CentOS 7环境部署MySQL主从服务器,根据PHP程序员的要求创建数据库与表。
实验要求
主:192.168.43.229
从:192.168.43.198
主Master
•开启时间同步
# systemctl stop firewalld.service //关闭防火墙
# setenforce 0
# vim /etc/ntp.conf
末尾添加:server 127.127.43.0 //本地是时钟源//
fudge 127.127.43.0 stratum 8 //设置时间层级为8(限制在15内
# systemctl start ntpd.service //开启时间同步
从Slave
•开启时间同步
# systemctl stop firewalld.service //关闭防火墙
# setenforce 0
# systemctl start ntpd.service //开启时间同步
# /usr/sbin/ntpdate 192.168.43.229
安装MySQL(主从都要)
# tar zxvf mysql-5.5.24.tar.gz -C /opt/
# yum install gcc gcc-c++ make cmake
ncurses-devel bison libaio-devel
# useradd -s /sbin/nologin mysql //添加mysql用户并加入到mysql组
# mkdir /usr/local/mysql
# cd /opt/mysql-5.5.24.tar.gz
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EXTRA_CHARSETS=all
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DENABLED_LOCAL_INFILE=1
-DMYSQL_DATADIR=/home/mysql
-DMYSQL_USER=mysql
-DMYSQL_TCP_PORT=3306
# make && make install
# chown -R mysql.mysql /usr/local/mysql
# export PATH=$PATH:/usr/local/mysql/bin/ \*开机时刷新*\
或者可选择vi /etc/profile 在最后一行加入后 运行source /etc/profile
# cp support-files/my-medium.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld
# chkconfig --add /etc/init.d/mysqld
# chkconfig mysqld --level 35 on
初始化数据库
# /usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql
# ln -s /var/lib/mysql/mysql.sock /home/mysql/mysql.sock /*直接建立软连接*/
# vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/home/mysql
# service mysqld start
# mysqladmin -u root password '123123' //为root用户创建密码
主Mater
# vim /etc/my.cnf
server-id = 11
log-bin=master-bin //主服务器日志文件//
log-slave-updates=true //从服务器更新二进制日志//
# systemctl restart mysqld.service
# mysql -u root -p
GRANT REPLICATION SLAVE ON *.* TO 'myslave'@'192.168.43.%' IDENTIFIED BY '123456';
# FLUSH PRIVILEGES;
# show master status;
从Slave
# vim /etc/my.cnf
server-id = 22
relay-log=relay-log-bin //从主服务器上同步日志文件记录到本地//
relay-log-index=slave-relay-bin.index //定义relay-log的位置和名称//
# systemctl restart mysqld.service
# mysql -u root -p
change master to master_host='192.168.43.229',master_user='myslave',master_password='123456',master_log_file='master-bin.000001',master_log_pos=338;
# start slave;
# show slave status\G; //查看状态//
主Master
进入MySQL
Linux环境下MySQL数据库主从同步配置 https://www.linuxidc.com/Linux/2017-04/143017.htm
CentOS 7.4下MySQL+Amoeba实现主从同步读写分离 https://www.linuxidc.com/Linux/2018-03/151648.htm
CentOS下MySQL安装与主从同步配置详解 https://www.linuxidc.com/Linux/2017-11/148524.htm
MySQL主从同步及错误1146解决办法 https://www.linuxidc.com/Linux/2017-02/140454.htm
MySQL5.7 搭建主从同步 https://www.linuxidc.com/Linux/2018-07/153211.htm
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx