Preparatory work:
Master-Slave operation----Close SELinux and iptables or open 3306 ports (iptables-a input-p TCP--dport 3306-j ACCEPT iptables-a output-p TCP--spo RT 3306-j ACCEPT), time synchronization ntpdate time.windows.com
Mysql_1 Information: Main
[Email protected]_1 ~ &6] #cat/etc/redhat-release uname-r ifconfig eth0 |grep ' inet addr ' |awk-f ': ' {prin T $ $ ' |echo IP: ' awk-f ' {print $} ' CentOS release 6.5 (Final) 2.6.32-431.el6.i686ip:172.31.12.4
Mysql_2 Information: From
[[Email protected]_2 ~ 11:02 &18] #cat/etc/redhat-release; uname-r; ifconfig eth1 |grep ' inet addr ' |awk-f ': ' {pri NT $ ' |echo IP: ' awk-f ' {print $} ' CentOS release 6.5 (Final) 2.6.32-431.el6.i686ip:172.31.12.233
Download MySQL and unzip: only the slave is shown here
cd/usr/local/src/
[Email protected]_2 ~ 11:19 &20] #wget http://syslab.comsenz.com/downloads/linux/ Mysql-5.1.40-linux-i686-icc-glibc23.tar.gz[[email protected]_2 src 11:24 &23] #tar-ZXVF Mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
move the extracted directory to/usr /loca/: Create Mysql directory
[Email protected]_2 src 11:26 &26] #mv mysql-5.1.40-linux-i686-icc-glibc23/usr/local/mysql
Create MySQL User: Disable MySQL user login bash Login
[Email protected]_2 src 13:13 &27] #useradd-S/sbin/nologin MySQL
Create the MySQL installation directory and modify it to the MySQL genus Master Group:
[Email protected]_2 src 13:14 &28] #mkdir-P/data/mysql[[email protected]_2 src 13:16 &29] #chown-R mysql:mysql/ data/mysql/
Go to the/usr/local/mysql directory to initialize MySQL:
[Email protected]_2 src 13:16 &30] #cd/usr/local/mysql/[[email protected]_2 MySQL 13:19 &31]#./scripts/mysql_ install_db--user=mysql--datadir=/data/mysql
Copy the MySQL master profile to the/etc/directory and rename it to MY.CNF:
[email protected]_2 mysql 13:21 &32] #cp support-files/my-large.cnf/etc/my.cnf
Copy the MySQL startup script to the/etc/init.d/directory and rename it to mysqld with the permission modified to 755:
[[email protected]_2 mysql 13:27 &33] #cp support-files/mysql.server/etc/init.d/mysqld[[email protected]_2 MySQL 13:29 &35] #chmod 755/etc/init.d/mysqld
To edit a startup script:
[[email protected]_2 mysql 13:30 &36] #vim/etc/init.d/mysqld Specify the installation directory for MySQL: datadir=/data/mysql
Add the startup script to the service item and set it to boot:
[[email protected]_2 mysql 13:33 &37] #chkconfig--add mysqld[[email protected]_2 mysql 13:35 &38] #chkconfig MySQL D on
Modify the service ID number from profile to 2:
[[email protected]_2 mysql 13:38 &40] #vim/etc/my.cnf Server-id = 1 changed to Server-id = 2
Set the MySQL command path: vim/etc/profile, add and refresh the service at the end:
[[email protected]_2 mysql 13:39 &41] #echo path= $PATH:/usr/local/mysql/bin >>/etc/profile[[email protected] _2 MySQL 13:41 &43] #source/etc/profile
To start the MySQL service:
[[email protected]_2 mysql 13:42 &45] #service mysqld start
The above steps, respectively, on the two servers configured well!
Set the password for master-slave MySQL separately:
[[email protected]_2 mysql 13:44 &46] #mysqladmin-uroot password ' 123456 '
login MySQL Master, from server, separate database db1:
[email protected]_2 mysql 13:47 &47] #mysql-uroot-penter password:welcome to the MySQL monitor. Commands End With; or \g.your MySQL connection ID is 2Server version:5.1.40-log mysql Community Server (GPL) Copyright (c) +, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql> create database db1; Create DB1 Library query OK, 1 row Affected (0.00 sec)
This article is from "be doing!" "Blog, be sure to keep this provenance http://zengweidao.blog.51cto.com/8342699/1529639