Ansible 项目案例
1、环境规划
角色 ip 部署软件
m01 192.168.1.66 ansible
backup 192.168.1.67 rsync
nfs 192.168.1.70 nfs、sersync
web01 192.168.1.69 httpd
实施步骤:
m01配置要求:
1.保证ssh密钥认证生效
2.安装ansible
3.准备所有的配置文件
本地hosts
selinux配置文件
rsyncd.conf
exports
mail.rc
sersync
rsync备份脚本
rsync检测脚本
mkdir -p /etc/ansible/ansible_playbook/{conf,file,scripts,tools}
保证ssh密钥认证生效
安装ansible
1、基础环境部署 (host: all)
1)网络环境(selinux firewalld)
- hosts: all tasks: - name: Disable SELinux copy: src=./conf/selinux.config dest=/etc/selinux/config - name : Stop SElinux shell: setenforce 0
- name: Disable Firewalld
service: name=firewalld state=stopped enabled=no
2)epel仓库
- name: Create Epel Repo get_url: url=http://mirrors.aliyun.com/repo/epel-7.repo dest=/etc/yum.repos.d/epel.repo
3)安装rsync,nfs-utils软件包
- name: Install Rsync Nfs
yum : name=rsync,nfs-utils state=installed
4)创建组
- name: Create Group group: name=www gid=666
5)创建用户
- name: Create User user: name=www uid=666 group=666 create_home=no shell=/sbin/nologin
6)创建目录,并修改所属和权限
- name: Create Directory /data file: path=/data owner=666 group=666 recurse=yes state=directory
7)推送脚本
- name: Create Scripts Directory file: path=/server/scripts state=directory - name: Push Rsync Backup Scripts copy: src=./scripts/rsync_backup.sh dest=/server/scripts/rsync_backup.sh
8)推送rsync客户端密码文件,并修改权限
- name: Create Rsync Client Pass File copy: content='1' dest=/etc/rsync.pass mode=600
9)计划任务
- name: Create Rsync Client Pass File copy: content='1' dest=/etc/rsync.pass mode=600
2、Rsync部署
1)安装rsync
2) 配置
3)启动
4)脚本
5)计划任务
- hosts: backup tasks: - name: Install Rsync Mailx yum: name=rsync,mailx state=installed - name: Push Rsync Config File copy: src=./conf/rsyncd.conf dest=/etc/rsyncd.conf notify: Restart Rsyncd - name: Create Rsync Auth File copy: content="rsync_backup:1' dest=/etc/rsync.password mode=600 - name: Start Rsync Service servcie: name=rsyncd state= started enabled=yes - name: Push Mailx Config File copy: src=./conf/mail.rc dest=/etc/mail.rc - name: Push Rsync Check Script copy: src=./scripts/rsync_check.sh dest=/server/scripts/rsync_check.sh - name: Create Rsync Check Crontab cron: name='Rsync Check' hour=5 minute=0 job='/bin/sh /server/scripts/rsync_check.sh &>/dev/null' handlers: - name: Restart Rsyncd service: name=rsyncd state=restarted
3、nfs部署
1)安装nfs-utils
2) 配置
3)启动
- hosts: nfs tasks: - name: Install nfs yum: name=nfs-utils state=installed - name: Push NFS Config File copy: src=./conf/exports dest=/etc/exports notify: Restart NFS - name: Start Rpcbind Service service: name=rpcbind state=started - name: Star nfs service service: name=nfs state=started enabled=yes handlers: - name: Restart NFS service: name=nfs state=restarted
4、sersync部署
草根-920