NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! ,。。。 All done! If you've completed all of the above steps, your MariaDB installation should now be secure.
Thanks for using MariaDB! ┌──[root@vms153.liruilongs.github.io]-[~] └─$
datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd
# # include all files from the config directory # !includedir /etc/my.cnf.d
1 2 3 4 5 6 7 8 9 10 11 12 13 14
┌──[root@vms153.liruilongs.github.io]-[~] └─$cat /etc/my.cnf.d/client.cnf # # These two groups are read by the client library # Use it for options that affect all clients, but not the server #
[client]
# This group is not read by mysql client library, # If you use the same .cnf file for MySQL and MariaDB, # use it for MariaDB-only client options [client-mariadb]
┌──[root@vms153.liruilongs.github.io]-[~] └─$cat /etc/my.cnf.d/mysql-clients.cnf # # These groups are read by MariaDB command-line tools # Use it for options that affect only one utility #
┌──[root@vms153.liruilongs.github.io]-[~] └─$mysql -uroot -pliruilong Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd
┌──[root@vms154.liruilongs.github.io]-[/var/lib/mysql] └─$mysql -uroot -pliruilong Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 9 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement. ####指定主服务器信息 #master_host= 指定主服务器的IP地址 #master_user= 指定主服务器授权用户 #master_password= 指定授权用户的密码 #master_log_file= 指定主服务器binlog日志文件(去153上查看) #master_log_pos= 指定主服务器binlog日志偏移量(去153上查看) MariaDB [(none)]> change master to -> master_host="192.168.26.153", -> master_user="repluser", -> master_password="repluser", -> master_log_file="master153.000004", -> master_log_pos=391; Query OK, 0 rows affected (0.00 sec)
┌──[root@vms154.liruilongs.github.io]-[/var/lib/mysql] └─$systemctl restart mariadb.service ┌──[root@vms154.liruilongs.github.io]-[/var/lib/mysql] └─$mysql -uroot -pliruilong Welcome to the MariaDB monitor. Commands endwith ; or \g. Your MariaDB connection id is4 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;'or'\h'for help. Type '\c'to clear the current input statement.
┌──[root@vms154.liruilongs.github.io]-[/var/lib/mysql] └─$mysql -uroot -pliruilong Welcome to the MariaDB monitor. Commands endwith ; or \g. Your MariaDB connection id is5 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;'or'\h'for help. Type '\c'to clear the current input statement.
IMPORTANT: Please check that the backup run completes successfully. At the end of a successful backup run innobackupex prints "completed OK!".
Can't locate Digest/MD5.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at - line 693. BEGIN failed--compilation aborted at - line 693. 220929 00:53:41 Connecting to MySQL server host: localhost, user: root, password: set, port: 0, socket: /var/lib/mysql/mysql.sock Using server version 5.5.68-MariaDB innobackupex version 2.3.6 based on MySQL server 5.6.24 Linux (x86_64) (revision id: ) xtrabackup: uses posix_fadvise(). xtrabackup: cd to /var/lib/mysql xtrabackup: open files limit requested 0, set to 1024 xtrabackup: using the following InnoDB configuration: xtrabackup: innodb_data_home_dir = ./ xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend xtrabackup: innodb_log_group_home_dir = ./ ....... 220929 00:53:43 Executing UNLOCK TABLES 220929 00:53:43 All tables unlocked 220929 00:53:43 Backup created in directory '/alldb' MySQL binlog position: filename 'master153.000004', position '854' 220929 00:53:43 [00] Writing backup-my.cnf 220929 00:53:43 [00] ...done 220929 00:53:43 [00] Writing xtrabackup_info 220929 00:53:43 [00] ...done xtrabackup: Transaction log of lsn (1600828) to (1600828) was copied. 220929 00:53:43 completed OK! ┌──[root@vms153.liruilongs.github.io]-[/var/lib/mysql] └─$
IMPORTANT: Please check that the apply-log run completes successfully. At the end of a successful apply-log run innobackupex prints "completed OK!".
innobackupex version 2.3.6 based on MySQL server 5.6.24 Linux (x86_64) (revision id: ) xtrabackup: cd to /opt/alldb/ xtrabackup: This target seems to be not prepared yet. xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(1600828) 。。。。。。。。 InnoDB: Starting shutdown... InnoDB: Shutdown completed; log sequence number 1601046 220929 10:45:53 completed OK!
datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd
┌──[root@vms153.liruilongs.github.io]-[/] └─$mysql -uroot -pliruilong Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 6 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
┌──[root@vms155.liruilongs.github.io]-[~] └─$mysql -uroot -pliruilong Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> change master to -> master_host="192.168.26.153", -> master_user="repluser", -> master_password="repluser", -> master_log_file="master153.000004", -> master_log_pos="854"; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"854"' at line 6 MariaDB [(none)]> change master to master_host="192.168.26.153", master_user="repluser", master_password="repluser", master_log_file="master153.000004", master_log_pos=854; Query OK, 0 rows affected (0.04 sec)
MariaDB [(none)]> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Master_Host: 192.168.26.153 Master_User: repluser Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master153.000004 Read_Master_Log_Pos: 854 Relay_Log_File: mariadb-relay-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: master153.000004 Slave_IO_Running: No Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 854 Relay_Log_Space: 245 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 1593 Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it). Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 153 1 row inset (0.00 sec)
ERROR: No query specified
我们可以看到有一个报错,说从库的Server_id设置的不对
Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the –replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it).
┌──[root@vms153.liruilongs.github.io]-[/] └─$mysql -uroot -pliruilong Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 6 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd
# # include all files from the config directory # !includedir /etc/my.cnf.d ┌──[root@vms154.liruilongs.github.io]-[/] └─$systemctl restart mariadb.service ┌──[root@vms154.liruilongs.github.io]-[/] └─$
┌──[root@vms154.liruilongs.github.io]-[/] └─$mysql -uroot -pliruilong Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant replication slave on *.* to tom@"%" identified by "liruilong"; Query OK, 0 rows affected (0.00 sec)
┌──[root@vms155.liruilongs.github.io]-[/var/lib/mysql] └─$systemctl restart mariadb.service ┌──[root@vms155.liruilongs.github.io]-[/var/lib/mysql] └─$mysql -uroot -pliruilong -e 'show slave status;' ┌──[root@vms155.liruilongs.github.io]-[/var/lib/mysql] └─$mysql -uroot -pliruilong Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd
datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd
# # include all files from the config directory # !includedir /etc/my.cnf.d ┌──[root@vms153.liruilongs.github.io]-[/] └─$systemctl restart mariadb.service
154查看配置是否启动
1 2 3 4 5 6 7 8 9 10 11 12 13 14
┌──[root@vms154.liruilongs.github.io]-[/] └─$mysql -uroot -pliruilong -e'show variables like "%semi%";' +------------------------------------+-------+ | Variable_name | Value | +------------------------------------+-------+ | rpl_semi_sync_master_enabled | ON | | rpl_semi_sync_master_timeout | 10000 | | rpl_semi_sync_master_trace_level | 32 | | rpl_semi_sync_master_wait_no_slave | ON | | rpl_semi_sync_slave_enabled | ON | | rpl_semi_sync_slave_trace_level | 32 | +------------------------------------+-------+ ┌──[root@vms154.liruilongs.github.io]-[/] └─$
datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd
# # include all files from the config directory # !includedir /etc/my.cnf.d ┌──[root@vms155.liruilongs.github.io]-[/] └─$systemctl restart mariadb.service
查看配置是否启动
1 2 3 4 5 6 7 8 9 10
┌──[root@vms155.liruilongs.github.io]-[/] └─$mysql -uroot -pliruilong -e'show variables like "%semi%";' +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | rpl_semi_sync_slave_enabled | ON | | rpl_semi_sync_slave_trace_level | 32 | +---------------------------------+-------+ ┌──[root@vms155.liruilongs.github.io]-[/] └─$