部署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
原文地址:http://blog.51cto.com/13620936/2150981
时间: 2024-10-08 04:00:13