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

8)ansible==>实现一键化ssh远程连接vim /server/scripts/distribute_key.sh #!/bin/bash. /etc/init.d/functions# 创建秘钥对if [ ! -f /root/.ssh/id_dsa ]thenssh-keygen -t dsa -f /root/.ssh/id_dsa -P "" >/dev/nullaction "key pair create"/bin/trueelseaction "key pair already exists" /bin/falsefi# 分发公钥信息for ip in 7 31 41 5 6 51 8dosshpass -p123456 ssh-copy-id -i ~/.ssh/id_dsa.pub 172.16.1.$ip -o StrictHostKeyChecking=no &>/dev/nullif [ $? -eq 0 ]thenaction "host 172.16.1.$ip pub_key distribute"/bin/trueecho ""elseaction "host 172.16.1.$ip pub_key distribute"/bin/falseecho ""fidone9)rsync全网备份nfs端: mkdir -p /server/srcipts
vim backup.sh#!/bin/bashBackup_IP=$(hostname -I|awk '{print $NF}')mkdir -p /backup/$Backup_IP# 1.tar zchPf /backup/$Backup_IP/system_backup_$(date +%F_%w).tar.gz /var/spool/cron/root /etc/rc.local /server/scripts /etc/exports# 2.find /backup/ -type f -name "*.tar.gz"|xargs md5sum >/backup/$Backup_IP/finger.txt# 3.rsync -az /backup/rsync_backup@172.16.1.41::backup_backup --password-file=/etc/rsync.password# 4.find /backup/ -type f -name"*.tar.gz"-mtime +7 -deletecrontab -e0 2 * * * /usr/bin/sh /server/scripts/backup.shweb01端: mkdir /server/srcipts
vim backup.sh#!/bin/bashBackup_IP=$(hostname -I|awk '{print $NF}')Backuo_html="/usr/share/nginx/html"Backup_mysql="/var/lib/mysql"mkdir -p /backup/$Backup_IP# 1.tar zchPf /backup/$Backup_IP/web_info_backup_$(date +%F_%w).tar.gz $Backup_html/bbs $Backup_html/blogtar zchPf /backup/$Backup_IP/web_log_backup_$(date +%F_%w).tar.gz $Backup_mysql/ultrax $Backup_mysql/wordpresstar zchPf /backup/$Backup_IP/system_backup_$(date +%F_%w).tar.gz /etc/rc.local /server/srcipts /var/spool/cron/root /etc/nginx/conf.d/bbs.conf /etc/nginx/nginx.conf /etc/nginx/conf.d/blog.conf# 2.find /backup/ -type f -name "*.tar.gz"|xargs md5sum >/backup/$Backup_IP/finger.txt# 3.rsync -az /backup/ rsync_backup@172.16.1.41::backup_backup --password-file=/etc/rsync.password# 4.find /backup/ -type f -name"*.tar.gz"-mtime +7 -deleteecho 123456 > /etc/rsync.passwordcrontab -e0 2 * * * /usr/bin/sh /server/scripts/backup.shweb02端:同理 backup端:
mkdir -p /server/srciptsvim /server/scripts/backup.sh#!/bin/bash# 1.find /backup/backup/ -type f -name "finger.txt"|xargs md5sum -c >/tmp/check_data.txt# 2.find /backup/backup/ -type f -name "*.tar.gz" -mtime +180 ! -iname "*_2.tar.gz" -deletecrontab -e0 6 * * * /usr/bin/sh /server/scripts/backup.sh



推荐阅读