Master server: 172.16.15.20
Slave server: 172.16.15.30
1. Install mysql
- # pvcreate /dev/sda5
- # vgcreate myvg /dev/sda5
- # lvcreate -L 10G -n mydata myvg
- # mkdir -p /data/mydata
- # mke2fs -j /dev/myvg/mydata
- # mount /dev/myvg/mydata /data/mydata/
-
- # tar xf mysql-5.5.24-linux2.6-i686.tar.gz -C /usr/local/
- # cd /usr/local/
- # ln -s mysql-5.5.24-linux2.6-i686/ mysql
- # cd mysql
- # useradd -r mysql
- # chown -R mysql.mysql .
- # scripts/mysql_install_db --datadir=/data/mydata/ --user=mysql
- # chown -R root .
- # cp support-files/my-large.cnf /etc/my.cnf
- # vim /etc/my.cnf
- thread_concurrency = 2
- datadir = /data/mydata
-
- # cp support-files/mysql.server /etc/rc.d/init.d/mysqld
- # chmod +x /etc/rc.d/init.d/mysqld
- # service mysqld start
2. Configure the master server and add users
- Mysql>Grant replication slave, replication client on *. * TO repluser @ '192. 172.% 'identified by 'redhat ';
-
- Mysql>Flush privileges;
-
- (Note: You must check the log and log location used later)
- Mysql>Show master status;
- + ------------------ + ---------- + -------------- + ------------------ +
- | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
- + ------------------ + ---------- + -------------- + ------------------ +
- |Mysql-bin.000001|335|
- + ------------------ + ---------- + -------------- + ------------------ +
- 1 row in set (0.00 sec
3. Configure the slave server
- # Vim/etc/my. cnf
- Relay-log=Mysql-Relay // Add relay logs
- Server-id=2// Modify the ID and the master.
-
- # Service mysqld restart takes effect
-
- Add the following command
- Mysql>CHANGE MASTERMASTER_HOST='2017. 16.15.20', // Specify the master server
- -> MASTER_USER='Repluser', // Specify the user
- -> MASTER_PASSWORD='Redhat', // Password
- -> MASTER_LOG_FILE='Mysql-bin.000001', // Specify the log
- -> MASTER_LOG_POS=355; // Specify the log location
-
- You can run the following command to view the configuration information:
- Mysql>Show slave status \ G
-
- Start the slave service thread
- Mysql>Start slave;
-
- Prohibit write from the server, and restart the service will become invalid.Read_only= On is written into the configuration file:
- SET GLOBALRead_only= On;
-
- Add the following in the configuration file [mysqld] so that the mysql service of the slave server does not start the slave service thread automatically during startup and starts it manually.
- Skip-slave-start=1
4. Test
- Create data on the master server
- Mysql>Create database tb1;
- Mysql>Use tb1;
- Mysql>Create table test (name varchar (10 ));
- Mysql>Insert into test values ('jack'), ('Tom ');
View:
650) this. width = 650; "border = 0>
Then we can see the copied information on the server:
650) this. width = 650; "border = 0>