ansible一键部署rsync服务

第一个历程: 检查环境
第二个历程: 配置ansible主机清单
    vim /etc/ansible/hosts
	[rsync:children]
    rsync_server
    rsync_client
    [rsync_server]
    172.16.1.41 ansible_user=root ansible_password=123456
    [rsync_client]
    172.16.1.31 
    172.16.1.7  ansible_user=root ansible_password=654321 ansible_port=52113
    [root@m01 172.16.1.41]# ansible rsync -m ping
    172.16.1.31 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": false, 
        "ping": "pong"
    }
    172.16.1.41 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": false, 
        "ping": "pong"
    }
    172.16.1.7 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": false, 
        "ping": "pong"
    }
	
第三个历程: 利用模块功能部署rsync服务
服务端配置:
01. 安装软件程序
	ansible rsync -m yum -a "name=rsync state=installed"
02. 编写配置文件
在管理端准备好服务配置文件
	 ansible rsync_server -m copy -a "src=/etc/ansible/conf_file/rsyncd.conf dest=/etc/"
03. 创建虚拟用户
	ansible rsync_server -m user -a "name=rsync create_home=no shell=/sbin/nologin"
04. 创建密码文件 (授权600)
	ansible rsync_server -m copy -a "content='rsync_backup:zhangxianwei123' dest=/etc/rsync.password mode=600"
05. 创建备份目录 (授权 属主 属组)
	ansible rsync_server -m file -a "path=/backup state=directory owner=rsync group=rsync"
06. 启动程序服务
ansible rsync_server -m service -a "name=rsyncd state=started enabled=yes"

客户端配置:
01. 创建密钥文件 (授权600)
	ansible rsync_client -m copy -a "content='zhangxianwei123' dest=/etc/rsync.password mode=600"
02. 批量测试传输文件
	ansible rsync_client -m shell -a "rsync -avz /etc/hosts [email protected]::backup --password-file=/etc/rsync.password"

PS: 使批量管理操作下载软件速度提升
部署yum本地仓库
	
发布了48 篇原创文章 · 获赞 1 · 访问量 1471

猜你喜欢

转载自blog.csdn.net/weixin_43876317/article/details/102979526