综合案例:利用ansible常用七种模块实现备份系统的部署及告警(十一)
【摘要】
1.综合案例-rsync,nfs,httpd,sersync
1.1.基础环境部署
1)关闭firewalld、selinux
每台服务器都要操作,也可以使用ansible的shell模块批量操作
...
1.综合案例-rsync,nfs,httpd,sersync
1.1.基础环境部署
1)关闭firewalld、selinux
每台服务器都要操作,也可以使用ansible的shell模块批量操作
[root@ansible ~]# systemctl stop firewalld
[root@ansible ~]# systemctl disable firewalld
[root@ansible ~]# sed -ri '/SELINUX=/c SELINUX=disabled' /etc/sysconfig/selinux
[root@ansible ~]# sed -ri '/SELINUX=/c SELINUX=disabled' /etc/selinux/config
- 1
- 2
- 3
- 4
- 5
- 6
- 7
2)ssh密钥生成,及公钥推送
1.生成公钥文件
[root@ansible ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
2.将公钥推送至远程服务器
[root@ansible ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.81.220
[root@ansible ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.81.230
[root@ansible ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.81.230
- 1
- 2
- 3
- 4
- 5
- 6
- 7
3)镜像配置
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo ;curl -o /etc/yum.repos.d/CentOS-Base.repo
- 1
4)安装软件包rsync、nfs-utils
[root@ansible ~]# ansible all -m yum -a "name=nfs-utils,rpcbind,rsync state=installed"
- 1
5)创建用户、组
组
[root@ansible ~]# ansible all -m group -a "name=linuxowner gid=9999"
用户
[root@ansible ~]# ansible all -m user -a "name=linuxowner uid=9999 group=9999 create_home=no shell=/sbin/nologin"
- 1
- 2
- 3
- 4
- 5
6)创建目录、并修改所属和权限
rsync备份
[root@ansible ~]# ansible all -m file -a "path=/backup owner=6666 group=6666 state=directory"
"
数据目录
[root@ansible ~]# ansible all -m file -a "path=/data owner=6666 group=6666 state=directory"
脚本目录
[root@ansible ~]# [root@ansible ~]# ansible all -m file -a "path=/script owner=6666 group=6666 state=directory"
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
7)创建rsync客户端密码文件
[root@ansible ~]# ansible all -m copy -a "content=123456 dest=/etc/rsync_pass mode=600"
- 1
8)推送脚本
[root@ansible ~]# mkdir /server/script/ -p
准备rsync安装脚本
准备rsync备份脚本
root@ansible ~]# tree /server/script
/server/script
├── rsyncd_backup.sh
├── rsyncd_shjc_install.sh
└── rsyncd_sjjy2.sh
推送至客户端
1.备份脚本推送至每个客户端
[root@ansible ~]# ansible all -m copy -a "src=/server/script/rsyncd_backup.sh dest=/script"
2.对rsync执行安装脚本
[root@ansible ~]# ansible backup -m script -a "/server/script/rsyncd_shjc_install.sh"
4.推送数据校验脚本至rsync
[root@ansible ~]# ansible backup -m copy -a "src=/server/script/rsyncd_sjjy2.sh dest=/script"
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
9)计划任务
web服务器
[root@ansible ~]# ansible web -m cron -a "name=rsync_backup hour=1 minute=0 job='/bin/sh /script/rsyncd_backup.sh'"
nfs服务器
[root@ansible ~]# ansible nfs -m cron -a "name=rsync_backup hour=1 minute=0 job='/bin/sh /script/rsyncd_backup.sh'"
backup服务器
[root@ansible ~]# ansible backup -m cron -a "name=rsync_check hour=5 minute=0 job='/bin/sh /script/rsyncd_sjjy2.sh'"
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3ANTYqeS-1593935468984)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20200610234617538.png)]
1.2.安装rsynnc
1)安装rsync
[root@ansible ~]# ansible backup -m yum -a "name=rsync state=installed"
- 1
2)配置rsync服务端
[root@ansible ~]# mkdir -p /server/conf
[root@ansible conf]# ansible backup -m copy -a "src=/server/conf/rsyncd.conf dest=/etc/"
[root@ansible conf]# ansible backup -m copy -a "content=rsync_backup:123456 dest=/etc/rsyncd.conf"
[root@ansible conf]# ansible backup -m file -a "path=/etc/rsync_passwd mode=666"
- 1
- 2
- 3
- 4
3)启动rsync
[root@ansible conf]# ansible backup -m service -a "name=rsyncd state=restarted"
- 1
13.3.安装NFS
1)安装配置nfs
[root@ansible conf]# ansible nfs -m yum -a "name=nfs-utils,rpcbind state=installed"
[root@ansible conf]# echo '/data2 192.168.81.0/24(rw,sync,all_squash,anonuid=6666,anongid=6666)' > /server/conf/exports
[root@ansible conf]# ansible nfs -m copy -a "src=/server/conf/exports dest=/etc/"
- 1
- 2
- 3
2)启动nfs
[root@ansible conf]# ansible nfs -m service -a "name=nfs state=started"
- 1
3)挂载
[root@ansible conf]# ansible all -m mount -a "src=192.168.81.230/data2 path=/data2 fstype=nfs state=mounted"
- 1
文章来源: jiangxl.blog.csdn.net,作者:Jiangxl~,版权归原作者所有,如需转载,请联系作者。
原文链接:jiangxl.blog.csdn.net/article/details/110489999
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)