Mysql 5.7安装:https://www.cnblogs.com/shipment/p/14325309.html
KeepAlived:https://blog.csdn.net/qq_43377292/article/details/87364778
Rsync+inotify-tools:https://jackyu.cn/tech/rsync-plus-inotify-tools/
安装php:https://www.cnblogs.com/chenliang725/p/12575926.html
一、安装Mysql
yum -y install mariadb-serversystemctl start mariadbsystemctl enable mariadb#初始化mariadb数据库mysql_secure_installation
Server1配置
vim /etc/my.cnf#在mysqld下添加如下内容server-id = 1log-bin = mysql-binsync_binlog = 1binlog_checksum = nonebinlog_format = mixedauto-increment-increment = 2auto-increment-offset = 1slave-skip-errors = allsystemctl restart mariadbGRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;flush privileges;
Server2配置
vim /etc/my.cnf#在mysqld下添加如下内容server-id = 2log-bin = mysql-binsync_binlog = 1binlog_checksum = nonebinlog_format = mixedauto-increment-increment = 2auto-increment-offset = 2slave-skip-errors = allsystemctl restart mariadb
Server1配置
flush tables with read lock;show master status;unlock tables;stop slave;change master to master_host='192.168.1.82',master_user='root',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=487;start slave;show slave status \G;
Server2配置
flush tables with read lock;show master status;unlock tables;stop slave;change master to master_host='192.168.1.81',master_user='root',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=487;start slave;show slave status \G;
二、配置Keepalived
安装keepalived
yum install keepalived ipvsadm -y
配置Server 1 keepalived
vim /etc/keepalived/keepalived.conf#主节点标识,从节点不一致router_id QF_HA_Node01}vrrp_instance VI_1 {#表示这是master主节点state MASTER#标识虚拟ip绑定的网卡interface ens192virtual_router_id 51#优先级一般主节点比从节点的大priority 120advert_int 1#密码 主从一致authentication {auth_type PASSauth_pass 1111}#定义虚拟ipvirtual_ipaddress {192.168.1.83}}#定义后端真实成员virtual_server 192.168.1.83 80 3306 {delay_loop 6lb_algo rrlb_kind DRpersistence_timeout 0protocol TCPreal_server 192.168.1.81 80 3306 {weight 100TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3connect_port 80 3306}}real_server 192.168.1.82 80 3306 {weight 100TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3connect_port 80 3306}}}systemctl restart keepalived
Server2配置keepalived
vim /etc/keepalived/keepalived.conf#主节点标识,从节点不一致router_id QF_HA_Node02}vrrp_instance VI_1 {#表示这是master主节点state MASTER#标识虚拟ip绑定的网卡interface ens192virtual_router_id 51#优先级一般主节点比从节点的大priority 119advert_int 1#密码 主从一致authentication {auth_type PASSauth_pass 1111}#定义虚拟ipvirtual_ipaddress {192.168.1.83}}#定义后端真实成员virtual_server 192.168.1.83 80 3306 {delay_loop 6lb_algo rrlb_kind DRpersistence_timeout 0protocol TCPreal_server 192.168.1.81 80 3306 {weight 100TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3connect_port 80 3306}}real_server 192.168.1.82 80 3306 {weight 100TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3connect_port 80 3306}}}systemctl restart keepalived
安装LAMP
yum install httpd httpd-devel mariadb-libs mariadb-devel mariadb php-mysqlyum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpmrpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmyum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-mysql
yum install -y php72w php72w-opcache php72w-xml php72w-mcrypt php72w-gd php72w-devel php72w-mysql php72w-intl php72w-mbstring
在网站根目录下创建test.php进行测试
<?phpecho phpinfo();?>
systemctl start httpd
systemctl enable httpd
systemctl start keepalived
systemctl enable keepalived
安装rsync
Server1配置
yum install rsync -yvim /etc/rsyncd.conflog file = /var/log/rsyncd.log#日志文件位置,启动rsync后自动产生这个文件,无需提前创建pidfile = /var/run/rsyncd.pid#pid文件的存放位置lock file = /var/run/rsync.lock#支持max connections参数的锁文件secrets file = /etc/rsyncd.password#用户认证配置文件,里面保存用户名称和密码,后面会创建这个文件motd file = /etc/rsyncd.Motd#rsync启动时欢迎信息页面文件位置(文件内容自定义)[web] #自定义名称path = /var/www/html/#rsync服务端数据目录路径comment = web#模块名称与自定义名称相同uid = root#设置rsync运行权限为rootgid = root#设置rsync运行权限为rootport = 873#默认端口use chroot = no#默认为true,修改为no,增加对目录文件软连接的备份read only = no#设置rsync服务端文件为读写权限list = yes#显示rsync服务端资源列表max connections = 200#最大连接数timeout = 300#设置超时时间auth users = web#虚拟用户名hosts allow = 192.168.1.82#允许进行数据同步的服务器,可以设置多个,用英文逗号隔开systemctl start rsyncdsystemctl enable rsyncdecho "web:123456" > /etc/rsyncd.passwordecho "123456" > /etc/rsyncd.pwchmod 600 /etc/rsyncd.confchmod 600 /etc/rsyncd.passwordchmod 600 /etc/rsyncd.pw
Server2配置
yum install rsync -yvim /etc/rsyncd.conflog file = /var/log/rsyncd.log#日志文件位置,启动rsync后自动产生这个文件,无需提前创建pidfile = /var/run/rsyncd.pid#pid文件的存放位置lock file = /var/run/rsync.lock#支持max connections参数的锁文件secrets file = /etc/rsyncd.password#用户认证配置文件,里面保存用户名称和密码,后面会创建这个文件motd file = /etc/rsyncd.Motd#rsync启动时欢迎信息页面文件位置(文件内容自定义)[web]#自定义名称path = /var/www/html/#rsync服务端数据目录路径comment = web#模块名称与自定义名称相同uid = root#设置rsync运行权限为rootgid = root#设置rsync运行权限为rootport = 873#默认端口use chroot = no#默认为true,修改为no,增加对目录文件软连接的备份read only = no#设置rsync服务端文件为读写权限list = yes#显示rsync服务端资源列表max connections = 200#最大连接数timeout = 300#设置超时时间auth users = web#虚拟用户名hosts allow = 192.168.1.81#允许进行数据同步的服务器,可以设置多个,用英文逗号隔开systemctl start rsyncdsystemctl enable rsyncdecho "web:123456" > /etc/rsyncd.passwordecho "123456" > /etc/rsyncd.pwchmod 600 /etc/rsyncd.confchmod 600 /etc/rsyncd.passwordchmod 600 /etc/rsyncd.pwrsync --daemon
安装notify-tools
Server1配置
sysctl -w fs.inotify.max_queued_events="99999999"sysctl -w fs.inotify.max_user_watches="99999999"sysctl -w fs.inotify.max_user_instances="65535"vi /etc/sysctl.conf #添加以下代码fs.inotify.max_queued_events=99999999fs.inotify.max_user_watches=99999999fs.inotify.max_user_instances=65535vim web.sh#!/bin/shsrcdir=/var/www/html/dstdir=webrsyncuser=webrsyncpassdir=/etc/rsyncd.pwdstip="192.168.1.82"for ip in $dstipdorsync -avH --port=873 --progress --delete $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdirdone/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib,move $srcdir | while read filedofor ip in $dstipdorsync -avH --port=873 --progress --delete $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdirecho " ${file} was rsynced" >> /tmp/rsync.log 2>&1donedonechmod a+x web.shvi /etc/rc.d/rc.localchmod +x /etc/rc.d/rc.local
Server2配置
sysctl -w fs.inotify.max_queued_events="99999999"sysctl -w fs.inotify.max_user_watches="99999999"sysctl -w fs.inotify.max_user_instances="65535"vi /etc/sysctl.conf #添加以下代码fs.inotify.max_queued_events=99999999fs.inotify.max_user_watches=99999999fs.inotify.max_user_instances=65535vim web.sh#!/bin/shsrcdir=/var/www/html/dstdir=webrsyncuser=webrsyncpassdir=/etc/rsyncd.pwdstip="192.168.1.81"for ip in $dstipdorsync -avH --port=873 --progress --delete $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdirdone/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib,move $srcdir | while read filedofor ip in $dstipdorsync -avH --port=873 --progress --delete $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdirecho " ${file} was rsynced" >> /tmp/rsync.log 2>&1donedonechmod a+x web.sh
