1 写出ansible部署rsync服务的playbook剧本内容
[root@m01 playbook]# cat /etc/ansible/hosts[rsync_server]172.16.1.41 [rsync_client]172.16.1.31 事先准备好rsyncd.conf、password等文件[root@m01 server]# tree /server/conf//server/conf/└── rsync_conf ├── rsync_client.password ├── rsyncd.conf └── rsync.password 剧本内容[root@m01 playbook]# vim /server/playbook/rsync.yml - hosts:rsync_server tasks: - name: s01:install rsync yum: name=rsync state=installed - name: s02:create rsync user user: name=rsync state=present createhome=no shell=/sbin/nologin - name: s03:create backup dir file: dest=/backup state=directory owner=rsync group=rsync - name: s04:create auth file copy: src=/server/conf/rsync_conf/rsync.password dest=/etc/ mode=600 - name: s05:edit rsync conf file copy: src=/server/conf/rsync_conf/rsyncd.conf dest=/etc/ - name: s06:start rsync server shell: rsync --daemon creates=/var/run/rsyncd.pid - hosts: rsync_client tasks: - name: s01:install rsync yum: name=rsync state=installed - name: s02:create auth file copy: src=/server/conf/rsync_conf/rsync_client.password dest=/etc/rsync.password mode=600
2 通过ansible剧本部署nfs客户端与服务端
要求
服务端分享/data目录客户端backup服务器把/data目录挂载到/nfsbackup目录中[root@m01 playbook]# cat nfs.yml - hosts: 172.16.1.31 tasks: - name: s01:install nfs-utils rpcbind yum: name=nfs-utils,rpcbind state=installed - name: s02:start rpcbind service: name=rpcbind state=started - name: s02:start nfs service: name=nfs state=started - name: s03:auto start nfs shell: chkconfig nfs on - name: s03:auto start rpcbind shell: chkconfig rpcbind on - name: s04:share to machine shell: echo "/data 172.16.1.0/24(rw,sync)" >> /etc/exports - name: s05:create data dir file: dest=/data state=directory owner=nfsnobody group=nfsnobody - name: s06:nfs reload shell: /etc/init.d/nfs reload - hosts: 172.16.1.41 tasks: - name: s01:install nfs-utils rpcbind yum: name=nfs-utils,rpcbind state=installed - name: s01:start rpcbind service: name=rpcbind state=started - name: s02:auto start shell: chkconfig rpcbind on - name: s02:auto start nfs shell: chkconfig nfs off - name: s03:create nfsbackup dir file: dest=/nfsbackup state=directory - name: s04:mount data to nfsbackup command: mount -t nfs 172.16.1.31:/data /nfsbackup
3 通过剧本部署配置sersync数据同步服务
nfs端ip 172.16.1.31 [root@m01 playbook]#cat /server/playbook/sersync.yml - hosts: 172.16.1.31 tasks: - name: s01:install inotify-tools yum: name=epel-release,inotify-tools state=installed - name: s02:install sersync script: /server/scripts/sersync.sh - name: s03:edit sersync conf copy: src=/server/conf/sersync_conf.xml dest=/usr/local/sersync/confxml.xml - name: s04: run sersync shell: sersync -d -r -o /usr/local/sersync/confxml.xml sersync.sh安装脚本内容 [root@m01 playbook]# cat /server/scripts/sersync.shmkdir -p /home/oldboy/tools &&cd /home/oldboy/tools &&wget https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz &&tar zxf sersync2.5.4_64bit_binary_stable_final.tar.gz &&mv GNU-Linux-x86/ /usr/local/sersync /server/conf/sersync_conf.xml 的内容不再列出 backup 备份服务器端rsync 服务前面已经配置过了 测试 [root@nfs01-clone data]# touch ansible_to_install_sersync.txt[root@nfs01-clone data]# lltotal 0-rw-r--r--. 1 root root 0 Aug 19 09:55 ansible_to_install_sersync.txt [root@backup-clone ~]# ll /nfsbackup/total 0-rw-r--r--. 1 root root 0 Aug 19 09:55 ansible_to_install_sersync.txt