准备工作:
主从机上作操作----关闭selinux和iptables或者开放3306端口(iptables -A INPUT -p tcp --dport 3306 -j ACCEPT iptables -A OUTPUT -p tcp --sport 3306 -j ACCEPT),时间同步ntpdate time.windows.com
mysql_1信息:主
[root@mysql_1 ~ 10:30 &6]#cat /etc/redhat-release ;uname -r ;ifconfig eth0 |grep ‘inet addr‘ |awk -F ‘:‘ ‘{print $2}‘ |echo ip:`awk -F ‘ ‘ ‘{print $1}‘` CentOS release 6.5 (Final) 2.6.32-431.el6.i686 ip:172.31.12.4
mysql_2信息:从
[root@mysql_2 ~ 11:02 &18]#cat /etc/redhat-release ;uname -r ;ifconfig eth1 |grep ‘inet addr‘ |awk -F ‘:‘ ‘{print $2}‘ |echo ip:`awk -F ‘ ‘ ‘{print $1}‘` CentOS release 6.5 (Final) 2.6.32-431.el6.i686 ip:172.31.12.233
下载mysql并解压:这里只演示从机
cd /usr/local/src/
[root@mysql_2 ~ 11:19 &20]#wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz [root@mysql_2 src 11:24 &23]#tar -zxvf mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
移动解压目录到/usr/loca/下:创建mysql目录
[root@mysql_2 src 11:26 &26]#mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql
创建mysql用户:禁止mysql用户登录bash登录
[root@mysql_2 src 13:13 &27]#useradd -s /sbin/nologin mysql
创建mysql安装目录,并修改为mysql属主属组:
[root@mysql_2 src 13:14 &28]#mkdir -p /data/mysql [root@mysql_2 src 13:16 &29]#chown -R mysql:mysql /data/mysql/
进入到/usr/local/mysql目录下初始化mysql:
[root@mysql_2 src 13:16 &30]#cd /usr/local/mysql/ [root@mysql_2 mysql 13:19 &31]#./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
拷贝mysql主配置文件到/etc/目录下并重命名为my.cnf:
[root@mysql_2 mysql 13:21 &32]#cp support-files/my-large.cnf /etc/my.cnf
拷贝mysql的启动脚本到/etc/init.d/目录下并重命名为mysqld并讲权限修改为755:
[root@mysql_2 mysql 13:27 &33]#cp support-files/mysql.server /etc/init.d/mysqld [root@mysql_2 mysql 13:29 &35]#chmod 755 /etc/init.d/mysqld
编辑启动脚本:
[root@mysql_2 mysql 13:30 &36]#vim /etc/init.d/mysqld 指定mysql的安装目录:datadir=/data/mysql
把启动脚本加入到服务项中,并设置为开机启动:
[root@mysql_2 mysql 13:33 &37]#chkconfig --add mysqld [root@mysql_2 mysql 13:35 &38]#chkconfig mysqld on
修改从配置文件服务id号为2:
[root@mysql_2 mysql 13:38 &40]#vim /etc/my.cnf server-id = 1 改为 server-id = 2
设置mysql 命令路径:vim /etc/profile,在末尾加上并刷新服务:
[root@mysql_2 mysql 13:39 &41]#echo PATH=$PATH:/usr/local/mysql/bin >> /etc/profile [root@mysql_2 mysql 13:41 &43]#source /etc/profile
启动mysql服务:
[root@mysql_2 mysql 13:42 &45]#service mysqld start
以上步骤,分别在两台服务器上配置好!
分别给主从mysql设置密码:
[root@mysql_2 mysql 13:44 &46]#mysqladmin -uroot password ‘123456‘
登陆mysql主、从服务器,分别建立数据库 db1:
[root@mysql_2 mysql 13:47 &47]#mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.40-log MySQL Community Server (GPL) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> create database db1; 创建db1库 Query OK, 1 row affected (0.00 sec)
本文出自 “时不待我!” 博客,请务必保留此出处http://zengweidao.blog.51cto.com/8342699/1529639
二进制免编译MYSQL主从配置,布布扣,bubuko.com
原文地址:http://zengweidao.blog.51cto.com/8342699/1529639