创建rsync客户端搭建配置文件
[root@saltstack rsync]# vi rsync_client.sls // 添加下面内容 rsync.passwd: file.managed: - name: /etc/rsync.password - source: salt://rsync/rsync.password - user: root - group: root - mode: 600 backup: file.directory: - name: /backup - user: root - group: root - mode: 755 - makedirs: True创建rsync服务配置文件(这里是rsync服务的配置文件,上面的是salt安装rsync服务应用的搭建配置文件)
[root@saltstack rsync]# vi rsyncd.conf // rsync配置文件 uid =rsync gid =rsync use chroot=no max chonnections =200 timeout = 300 pid file =/var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log ignore errors read only = false list = false hosts allow = 172.16.0.0/24 hosts deny = 0.0.0.0/32 auth users = rsync_backup secrets file = /etc/rsync.password [backup] path = /backup [root@saltstack rsync]# vi rsyncd.password // 服务端密码文件 rsync_backup:123456 [root@saltstack rsync]# vi rsync.password // 客户端密码文件 123456 [root@saltstack rsync]# ll 总用量 20 -rw-r--r-- 1 root root 274 4月 26 15:17 rsync_client.sls -rw-r--r-- 1 root root 376 4月 26 15:11 rsyncd.conf -rw-r--r-- 1 root root 20 4月 26 15:15 rsyncd.password -rw-r--r-- 1 root root 7 4月 26 15:15 rsync.password -rw-r--r-- 1 root root 723 4月 26 15:16 rsync_server.sls验证rsync服务是否安装成功
rsync服务端查看服务是否启动
好极了,我们在rsync客户端推送一个文件到服务端是否成功
[root@client2 ~]# cd /backup/ [root@client2 backup]# echo 'this msg from new install rsync client used by test' > test.txt [root@client2 backup]# ls test.txt test.txt [root@client2 backup]# rsync -avz /backup/ rsync_backup@172.16.0.20::backup --password-file=/etc/rsync.password sending incremental file list ./ test.txt sent 132 bytes received 30 bytes 324.00 bytes/sec total size is 52 speedup is 0.32貌似推送成功了,快去rsync服务端看下吧
[root@client1 ~]# cd /backup/ [root@client1 backup]# ll 总用量 4 -rw-r--r-- 1 rsync rsync 52 4月 26 15:46 test.txt [root@client1 backup]# cat test.txt this msg from new install rsync client used by test好的,顺利装完,出去抽支烟和活动下颈椎吧。
Saltstack 常用命令1、拷贝文件到客户端
[root@saltstack ~]# salt 'client2' cp.get_file salt://apache.sls /tmp/cp.txt client2: /tmp/cp.txt客户端查看
[root@client2 ~]# ll /tmp 总用量 4 -rw-r--r-- 1 root root 151 4月 26 14:04 cp.txt2、拷贝目录到客户端
[root@saltstack ~]# salt 'client2' cp.get_dir salt://test /tmp client2: - /tmp/test/1.sh - /tmp/test/123/1.txt客户端查看
root@client2 ~]# ll /tmp/ 总用量 4 -rw-r--r-- 1 root root 151 4月 26 14:04 cp.txt drwxr-xr-x 3 root root 29 4月 26 14:14 test3、显示存活的客户端
[root@saltstack ~]# salt-run manage.up - client1 - client2 - saltstack4、命令下执行服务端的脚本
[root@saltstack ~]# vim /srv/salt/test/shell.sh #! /bin/sh echo "salt server do run shell script on client" > /tmp/shell.txt [root@saltstack ~]# salt 'client2' cmd.script salt://test/shell.sh
客户端查看
[root@client2 ~]# ll /tmp/ -rw-r--r-- 1 root root 42 4月 26 14:20 shell.txt [root@client2 ~]# cat /tmp/shell.txt salt server do run shell script on client