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-server
systemctl start mariadb
systemctl enable mariadb
#初始化mariadb数据库
mysql_secure_installation
Server1配置
vim /etc/my.cnf
#在mysqld下添加如下内容
server-id = 1
log-bin = mysql-bin
sync_binlog = 1
binlog_checksum = none
binlog_format = mixed
auto-increment-increment = 2
auto-increment-offset = 1
slave-skip-errors = all
systemctl restart mariadb
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;
Server2配置
vim /etc/my.cnf
#在mysqld下添加如下内容
server-id = 2
log-bin = mysql-bin
sync_binlog = 1
binlog_checksum = none
binlog_format = mixed
auto-increment-increment = 2
auto-increment-offset = 2
slave-skip-errors = all
systemctl 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 ens192
virtual_router_id 51
#优先级一般主节点比从节点的大
priority 120
advert_int 1
#密码 主从一致
authentication {
auth_type PASS
auth_pass 1111
}
#定义虚拟ip
virtual_ipaddress {
192.168.1.83
}
}
#定义后端真实成员
virtual_server 192.168.1.83 80 3306 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 0
protocol TCP
real_server 192.168.1.81 80 3306 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80 3306
}
}
real_server 192.168.1.82 80 3306 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_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 ens192
virtual_router_id 51
#优先级一般主节点比从节点的大
priority 119
advert_int 1
#密码 主从一致
authentication {
auth_type PASS
auth_pass 1111
}
#定义虚拟ip
virtual_ipaddress {
192.168.1.83
}
}
#定义后端真实成员
virtual_server 192.168.1.83 80 3306 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 0
protocol TCP
real_server 192.168.1.81 80 3306 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80 3306
}
}
real_server 192.168.1.82 80 3306 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80 3306
}
}
}
systemctl restart keepalived
安装LAMP
yum install httpd httpd-devel mariadb-libs mariadb-devel mariadb php-mysql
yum 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.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -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进行测试
<?php
echo phpinfo();
?>
systemctl start httpd
systemctl enable httpd
systemctl start keepalived
systemctl enable keepalived
安装rsync
Server1配置
yum install rsync -y
vim /etc/rsyncd.conf
log 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运行权限为root
gid = root
#设置rsync运行权限为root
port = 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 rsyncd
systemctl enable rsyncd
echo "web:123456" > /etc/rsyncd.password
echo "123456" > /etc/rsyncd.pw
chmod 600 /etc/rsyncd.conf
chmod 600 /etc/rsyncd.password
chmod 600 /etc/rsyncd.pw
Server2配置
yum install rsync -y
vim /etc/rsyncd.conf
log 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运行权限为root
gid = root
#设置rsync运行权限为root
port = 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 rsyncd
systemctl enable rsyncd
echo "web:123456" > /etc/rsyncd.password
echo "123456" > /etc/rsyncd.pw
chmod 600 /etc/rsyncd.conf
chmod 600 /etc/rsyncd.password
chmod 600 /etc/rsyncd.pw
rsync --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=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535
vim web.sh
#!/bin/sh
srcdir=/var/www/html/
dstdir=web
rsyncuser=web
rsyncpassdir=/etc/rsyncd.pw
dstip="192.168.1.82"
for ip in $dstip
do
rsync -avH --port=873 --progress --delete $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdir
done
/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 file
do
for ip in $dstip
do
rsync -avH --port=873 --progress --delete $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdir
echo " ${file} was rsynced" >> /tmp/rsync.log 2>&1
done
done
chmod a+x web.sh
vi /etc/rc.d/rc.local
chmod +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=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535
vim web.sh
#!/bin/sh
srcdir=/var/www/html/
dstdir=web
rsyncuser=web
rsyncpassdir=/etc/rsyncd.pw
dstip="192.168.1.81"
for ip in $dstip
do
rsync -avH --port=873 --progress --delete $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdir
done
/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 file
do
for ip in $dstip
do
rsync -avH --port=873 --progress --delete $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdir
echo " ${file} was rsynced" >> /tmp/rsync.log 2>&1
done
done
chmod a+x web.sh