1.基础环境部署
1)firewalld selinux
2)ssh秘钥生成,及公钥推送
3)epel
4)安装软件包rsync,nfs-utils
[root@linux-node1 ~]# ansible all -m yum -a "name=rsync,nfs-utils started"
5)创建用户,组
[root@linux-node1 ~]# ansible all -m group -a "name=www gid=666"
[root@linux-node1 ~]# ansible all -m user -a "name=www uid=666 group=666 shell=/sbin/nologin create_home=no"
6)创建目录,并修改所属和权限
[root@linux-node1 ~]# ansible all -m file -a "path=/data owner=666 group=666 recurse=yes state=directory"
[root@linux-node1 ~]# ansible all -m file -a "path=/backup owner=666 group=666 recurse=yes state=directory"
[root@linux-node1 ~]# ansible all -m file -a "path=/server/scripts state=directory"
7)创建rsync客户端密码文件
[root@linux-node1 ~]# ansible all -m copy -a "content='1' dest=/etc/rsync.pass mode=600"
8)推送脚本(脚本提前准备)
[root@linux-node1 scripts]# ansible all -m copy -a "src=/server/scripts/rsync_time.sh dest=/server/scripts"
9)计划任务
[root@linux-node1 scripts]# ansible all -m cron -a "name='Rsync Time' hour=1 minute=0 job='/bin/sh /server/scripts/rsync_time.sh >/dev/null 2>&1'"
2.rsync服务端
1)安装
在基础配置已实现
[root@linux-node1 ~]# ansible backup -m yum -a "name=mailx state=installed"
2)配置
[root@linux-node1 ~]# mkdir -p /server/conf
[root@linux-node1 ~]# ansible all -m copy -a "src=/server/conf/rsyncd dest=/etc/"
[root@linux-node1 ~]# ansible all -m copy -a "content='rsync_backup:1' dest=/etc/rsync_backup node=600"
3)启动
[root@linux-node1 ~]# ansible backup -m service -a "name=rsyncd state=started enabled=yes"
3.nfs服务端
1)安装
2)配置
[root@linux-node1 ~]#echo '/data 192.168.6.0/24(rw,sync,all_squash,anonuid=666,anongid=666)' > /server/conf/exports
[root@linux-node1 ~]# ansible nfs -m copy -a "src=/server/conf/exports dest=/etc/exports"
3)启动
[root@linux-node1 ~]# ansible nfs -m service -a "name=rpcbind state=started enabled=yes"
[root@linux-node1 ~]# ansible nfs -m service -a "name=nfs-utils state=started enabled=yes"
4.web服务器
1)安装
[root@linux-node1 ~]# ansible sunrise -m yum -a "name=httpd state=installed"
2)配置
3)启动
[root@linux-node1 ~]# ansible web -m service -a "name=httpd state=started enabled=yes"
4)挂载
[root@linux-node1 ~]# ansible web -m mount -a "src=192.168.6.242:/data path=/var/www/html fstype=nfs state=mounted"
文档更新时间: 2019-07-23 10:03 作者:李延召