ansible playbook重构Rsync nfs

playbook汇总

手动部署rsync服务:
1.安装rsync
2.配置rsync(配置文件提前收集)
3.创建必要数据
创建用户
创建密码文件 权限
创建目录 修改权限
4.启动

[root@ansible ansible]# cat rsync.yml
- hosts: backup
tasks:
- name: Install Rsync Server
yum:
name: rsync
state: present

- name: Configure Rsync Server
copy:
src: rsyncd.conf
dest: /etc/rsyncd.conf

- name: Create Group www
group:
name: www
gid: 666

- name: Create www User
user:
name: www
uid: 666
group: www
shell: /sbin/nologin
create_home: false

- name: Create Password file
copy:
content: rsync_backup:123456
dest: /etc/rsync.passwd
mode: 0600

- name: Create /backup dir
file:
path: /backup
state: directory
owner: www
group: www

- name: Start Rsync Server
systemd:
name: rsyncd
state: started
enabled: yes

我们切换到 backup 上测试一下 rsync:

rsync -avz root@nfs:/root/1.txt  .  在41主机上下载31家目录下的1.txt到当前目录

二.Playbook重构nfs

手动配置nfs
1.安装nfs
yum -y install nfs-utils
2.配置nfs
exports(提前准备)
3.创建必要数据信息
创建www用户
创建共享目录/data/blog 修改属主属组
4.启动nfs

[root@ansible ansible]# cat nfs.yml
- hosts: nfs
tasks:
- name: Install nfs-utils Server
yum:
name: nfs-utils
state: present

- name: Configure NFS Server
copy:
src: exports
dest: /etc/exports

- name: Create Group www
group:
name: www
gid: 666

- name: Create www User
user:
name: www
uid: 666
group: www
shell: /sbin/nologin
create_home: false

- name: Create /code/blog dir
file:
path: /code/blog
state: directory
owner: www
group: www

- name: Start NFS Server
systemd:
name: nfs
state: started
enabled: yes

 

客户端挂载NFS(wordpress业务)

 

三.Playbook重构mysql

[root@ansible ansible]# cat mysql.yml
- hosts: db01
tasks:
- name: Install Mariadb-Server
yum:
name:
- mariadb-server
- MySQL-python
state: present

- name: Start Mariadb Server
systemd:
name: mariadb
state: started
enabled: yes

- name: Copy all.sql to Remote Host DB01
copy:
src: all.sql
dest: /root/all.sql

- name: import all.sql
mysql_db:
login_host: localhost
login_port: 3306
login_user: root
name: all
state: import
target: /root/all.sql

- name: Restart MariaDB Server
systemd:
name: mariadb
state: restarted

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章