基于Linux系统的高可用中小型网站集群架构说明( 三 )


mkdir -p /server/scriptsvim /server/scripts/check_keepalivde.sh #!/bin/baship a|grep 10.0.0.3 &>/dev/nullif [ $? -eq 0 ]thenecho "master and backup change"|mail -s "check keepalived server" xxx@163.comficrontab -e* * * * *sh /server/scripts/check_keepalived.shvim /server/scripts/check_web.sh#!/bin/bashport_info=$(netstat -lntup|grep -w 80|wc -l)if [ $port_info -eq 0 ]thensystemctl stop keepalivedfichmod +x /server/srcipts/check_web.shvim /etc/keepalived/keepalived.confvrrp_script check_web {script "/server/scripts/check_web.sh"interval 2weight 2 }track_script {check_web }4)mariadb==>实现数据库迁移web01服务器端(bbs、blog)
mysqldump -uroot -p123456-A> /tmp/mysql_bak.sqlrsync -avz /tmp/mysql_bak.sql 172.16.1.51:/tmpvim /usr/share/nginx/html/blog/wp-config.php define('DB_HOST', '172.16.1.51');vim /usr/share/nginx/html/bbs/config/config_global.php$_config['db']['1']['dbhost'] = '172.16.1.51';vim /usr/share/nginx/html/bbs/config/config_ucenter.phpdefine('UC_DBHOST', '172.16.1.51');web02服务器端(www)
mysqldump -uroot -p123456-A> /tmp/phpcms_bak.sqlrsync -avz /tmp/phpcms_bak.sql 172.16.1.51:/tmpvim /usr/share/nginx/html/www/install_package/caches/configs/database.php'hostname' => '172.16.1.51',数据库服务器端
mysql-uroot -p123456 </tmp/mysql_bak.sqlmysql -uroot -p123456 < /tmp/phpcms_bak.sqlmysql -uroot -p123456grant all on wordpress.* to 'wordpress'@'172.16.1.%' identified by '123456';grant all on ultrax.* to ''root@'172.16.1.%' identified by '123456';grant all on phpcmsv9.* to 'phpcmsv9'@'172.16.1.%' identified by '123456';exitsystemctl restart mariadb5)nfs==>实现网站上传数据实时存储web01服务器
mkdir {/tmp/wordpress_bak,/tmp/discuz_bak}mv/usr/share/nginx/html/blog/wp-content/uploads/*/tmp/wordpress_bakmv /usr/share/nginx/html/bbs/data/attachment/forum/* /tmp/discuz_bak/mount -t nfs 172.16.1.31:/data/bbs/usr/share/nginx/html/bbs/data/attachment/forummount -t nfs 172.16.1.31:/data/blog/usr/share/nginx/html/blog/wp-content/uploads mv/tmp/wordpress_bak/*/usr/share/nginx/html/blog/wp-content/uploadsmv /tmp/discuz_bak/* /usr/share/nginx/html/bbs/data/attachment/forumweb02服务器
mkdir/tmp/phpcms_bakmv /usr/share/nginx/html/www/install_package/uploadfile/poster/* /tmp/phpcms_bak/mount -t nfs 172.16.1.31:/data/www/usr/share/nginx/html/www/install_package/uploadfile/postermv /tmp/phpcms_bak/* /usr/share/nginx/html/www/install_package/uploadfile/posternfs服务器
mkdir -p /data/{bbs,blog,www}vim /etc/exports/data/blog 172.16.1.0/24(rw,sync,no_root_squash)/data/www 172.16.1.0/24(rw,sync,no_root_squash)/data/bbs 172.16.1.0/24(rw,sync,no_root_squash)useradd -M -s /sbin/nologin nginx-u 995(与相关服务的属主属组及uid保持一致)chown-R nginx./datasystemctl restart nfs配置自动挂载文件
6)rsync==>定时任务实现与nfs服务器数据备份与还原backup服务器端
yum install -y rsyncvim /etc/rsyncd.confuid = rsyncgid = rsyncport = 873fake super = yes use chroot = nomax connections = 200timeout = 300lock file = /var/run/rsync.locklog file = /var/log/rsyncd.logignore errorsread only = falselist = falsehosts allow = 172.16.1.0/24hosts deny = 0.0.0.0/32auth users = rsync_backupsecrets file = /etc/rsync.password [backup_db]comment = "backup dir by oldboy"path = /backup/db/[backup_nfs]comment = "backup dir by oldboy"path = /backup/nfs/useradd-M-s/sbin/nologinrsyncecho rsync_backup:123456>/etc/rsync.passwordchmod 600 /etc/rsync.passwordmkdir/dackupchownrsync.rsync/dackupsystemctl startrsyncdnfs服务器端
yum install -y rsyncecho123456>/etc/rsync.passwordchmod 600 /etc/rsync.passwordnfs服务器定时任务
crontab -e302***/usr/bin/rsync -avz/data/rsync_backup@172.16.1.41::backup_nfs--password-file=/etc/rsync.password7)sersync==>实时同步数据库服务与备份服务数据库服务
yum install -y lrzszmkdir -p /server/toolsrz -y ==>选择路径unzip sersync_installdir_64bit.zipcd /server/tools/sersync_installdir_64bitmv sersync/ /usr/local/vim /usr/local/sersync/conf/confxml.xml<filter start="false"><exclude expression="(.*).svn"></exclude><exclude expression="(.*).gz"></exclude><exclude expression="^info/*"></exclude><exclude expression="^static/*"></exclude></filter><inotify><delete start="true"/><createFolder start="true"/><createFile start="false"/><closeWrite start="true"/><moveFrom start="true"/><moveTo start="true"/><attrib start="false"/><modify start="false"/></inotify><sersync><localpath watch="/var/lib/mysql/"><remote ip="172.16.1.41" name="backup_db"/><!--<remote ip="192.168.8.39" name="tongbu"/>--><!--<remote ip="192.168.8.40" name="tongbu"/>--></localpath><rsync><commonParams params="-az"/><auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/><userDefinedPort start="false" port="874"/><!-- port=874 --><timeout start="false" time="100"/><!-- timeout=100 --><ssh start="false"/></rsync><failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--><crontab start="false" schedule="600"><!--600mins--><crontabfilter start="false"><exclude expression="*.php"></exclude><exclude expression="info/*"></exclude></crontabfilter></crontab><plugin start="false" name="command"/></sersync><plugin name="command"><param prefix="/bin/sh" suffix="" ignoreError="true"/><!--prefix /opt/tongbu/mmm.sh suffix--><filter start="false"><include expression="(.*).php"/><include expression="(.*).sh"/></filter></plugin><plugin name="socket"><localpath watch="/opt/tongbu"><deshost ip="192.168.138.20" port="8009"/></localpath></plugin><plugin name="refreshCDN"><localpath watch="/data0/htdocs/aaa.xxx.com/site/"><cdninfo domainname="aaa.xxx.com" port="80" username="xxxx" passwd="xxxx"/><sendurl base="http://pic.xoyo.com/cms"/><regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xxx.com/images"/></localpath></plugin></head>cd /usr/local/sersync/bin/chmod +x sersyncyum install -y rsyncecho123456>/etc/rsync.passwordchmod 600 /etc/rsync.password./sersync -dro /usr/local/sersync/conf/confxml.xml


推荐阅读