ansible部署rsync,nfs,sersync

1.安装rsync服务

  • rsync服务端
yum install -y rsync

ansible backup -m yum -a 'name=rsync'

2.配置/etc/rsyncd.conf copy

ansible backup -m copy -a 'src=/etc/rsyncd.conf dest=/etc/rsyncd.conf backup=yes'

3.添加虚拟用户

useradd -s /sbin/nologin -M rsync

ansible backup -m user -a 'name=rsync uid=1001 shell=/sbin/nologin create_home=no state=present'

4.创建密码文件

密码文件格式:		用户:密码
echo 'rsync_backup:123' >/etc/rsync.password
chmod 600 /etc/rsync.password

ansible backup -m file  -a 'path=/etc/rsync.password mode=0600 state=touch'

4.1.向文件内写入用户和密码

ansible backup -m lineinfile -a 'path=/etc/rsync.password.test line="rsync_backup:123" '


5.创建共享目录与权限

mkdir /data/
chown rsync.rsync /data/

ansible backup -m file  -a 'path=/data.test/ owner=rsync group=rsync  state=directory'

6.启动服务

systenctl enable rsyncd
systemctl start  rsyncd

ansible backup -m systemd -a 'name=rsyncd enabled=yes state=started'

rsync客户端

1.免密传输数据到服务端

echo '123' >/etc/rsync.client
#修改权限
chmod 600 etc/rsync.client 


ansible web -m file  -a 'path=/etc/rsync.client.test  mode=0600 state=touch'

ansible web -m lineinfile -a 'path=/etc/rsync.client.test line="123" '

2.ansible部署nfs

nfs服务端

1.安装nfs

ansible nfs  -m yum  -a 'name="nfs-utils,rpcbind" state=present'

2.配置nfs /etc/exrpots

ansible nfs -m lineinfile  -a  'path=/etc/exports  line="/ans-data/     172.16.1.0/24(rw)" '

3 创建共享目录和修改所有者

ansible nfs -m file -a 'path=/ans-data owner=nfsnobody group=nfsnobody state=directory'

4.启动(重启)

#重启rpc
ansible nfs -m systemd -a 'name=rpcbind enabled=yes state=restarted'
#重启nfs
ansible nfs -m systemd -a 'name=nfs enabled=yes state=restarted'

nfs客户端:

1.安装

ansible web  -m yum  -a 'name="nfs-utils,rpcbind" state=present'

2.web 创建挂载点 /ans-upload/

ansible web -m  file -a 'path=/ans-upload/ state=directory'

3.web 挂载并永久挂载

ansible web -m mount -a 'src="172.16.1.31:/ans-data/" path="/ans-upload" fstype=nfs state=mounted'

ansible部署nfs playbook脚本

---
- hosts: nfs
  tasks:
    - name: 1.安装nfs
      yum:
        name: nfs-utils,rpcbind
        state: present
    - name: 2.配置nfs
      lineinfile: 
        path: /etc/exports  
        line: "/ans-data/     172.16.1.0/24(rw)"
       
    - name: 3.创建共享目录和修改所有者
      file: 
        path: /ans-data
        owner: nfsnobody
        group: nfsnobody
        state: directory

    - name: 4.启动(重启)
      systemd: 
        name: rpcbind
        enabled: yes
        state: restarted

    - name: 5.重启nfs
      systemd: 
        name: nfs
        enabled: yes
        state: restarted
      
        

- hosts: web
  tasks:
    - name: 1.安装
      yum: 
        name: nfs-utils,rpcbind
        state: present
    - name: web 创建挂载点  /ans-upload/
      file:
        path: /ans-upload/
        state: directory
    - name: web 挂载并永久挂载
      mount: 
        src: 172.16.1.31:/ans-data/
        path: /ans-upload
        fstype: nfs 
        state: mounted

3.ansible部署sersync

1.部署rsync服务

a)rsync服务端

#1.etc/rsyncd.conf  配置文件中添加[nfsbackup]模块
[nfsbackup]
comment = shishi backup nfs
path = /nfsbackup-test/
管理端写好直接copy过去
#2.创建模块对应目录
mkdir -p /nfsbackup/
#3.修改目录所属者
chown rsync.rsync /nfsbackup

ansible backup -m file  -a 'path=/nfsbackup/ owner=rsync group=rsync  state=directory'

b) rsync客户端

#测试传输即可
#1.创建密码文件
echo 123 > /etc/client.rsync

#2.修改密码文件权限
chmod 600 /etc/rsync.client

ansible backup -m file  -a 'path=/etc/rsync.password mode=0600 state=touch'


ansible backup -m lineinfile -a 'path=/etc/rsync.password.test line="rsync_backup:123" '
已存在略过此步骤

2 sersync部署nfs

a)nfs01上

目录规划:
/app/tools/sersync/
/app/tools/sersync/bin/
/app/tools/sersync/conf/

mkdir - p/app/tools/sersync/
mkdir - p/app/tools/sersync/bin/
mkdir - p/app/tools/sersync/bin/conf/


ansible nfs -m file -a 'path=/app/tools/sersync/bin state=directory'
ansible nfs -m file -a 'path=/app/tools/sersync/conf state=directory'

复制sersync服务包到nfs上
ansible nfs -m copy -a 'src=/root/sersync dest=/app/tools/sersync/bin/'

ansible nfs -m copy -a 'src=/root/confxml.xml dest=/app/tools/sersync/conf/'

b) 配置文件copy过去

c) 启动sersync

#1.创建软连接
ln -s /app/tools/sersync/bin/sersync  /bin/

ansible nfs -m file -a 'src=/app/tools/sersync/bin/sersync path=/bin/sersync state=link'
#2.启动服务端
ansible nfs -m shell -a 'sersync -rdo /app/tools/sersync/conf/confxml.xml'



3 web接入nfs服务

  • 服务端配置
cat /etc/exports
/data/ 172.16.1.0/24(rw)

ansible nfs -m lineinfile  -a  'path=/etc/exports  line="/data/     172.16.1.0/24(rw)" '
#创建对应目录
mkdir /data/
#更改目录所有者
 chown nfsnobody.nfsnobody /data/
 
 
 
ansible nfs -m file -a 'path=/data/ owner=nfsnobody group=nfsnobody state=directory'
  • 客户端挂载
#2.创建挂载目录
mkdir -p /upload

ansible nfs -m file  -a 'path=/upload-test/   state=directory'

#3.挂载
mount -t nfs 172.16.1.31:/data/  /upload/


ansible nfs -m mount -a 'src="172.16.1.31:/data" path="/upload-test" fstype=nfs state=mounted'


ansible web -m mount -a 'src="172.16.1.31:/data/" path="/upload-test" fstype=nfs state=mounted'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值