satlstack号称自动化运维的利器,那么saltstack能不能实现自身的批量部署呢?如果你也有这样的疑问,那么就更要看这篇文章了。答案当然是肯定的啦!saltstack可以利用salt-ssh来实现自身的批量部署。首先看待salt-ssh,很容易想到它是一个依赖 ssh 来进行远程命令执行的工具,这样做的好处是你不必在客户端安装minion程序,就可以实现远程命令的执行,而且salt-ssh支持salt的绝大部分功能。
10.10.10.4 salt-master os:redhat6.5 master
10.10.10.5 compute1 os:redhat6.5 minion
10.10.10.6 compute2 os:redhat6.5 minion
10.10.10.7 manager01 os:redhat6.5 minion
10.10.10.8 horsizon os:redhat6.5 minion
1、配置roster状态文件
[[email protected] ~]# cat /etc/salt/roster compute1: host: compute1 //主机名 user: root //用户名 passwd: salt_passwd //密码 port: 22 //端口 timeout: 3 //超时次数 compute2: host: compute2 user: root passwd: salt_passwd port: 22 timeout: 3 [[email protected] ~]# salt-ssh ‘*‘ test.ping compute1: True compute2: True manager01: True
## 需要注意的是,由于salt-ssh并没有继承salt的zeroMQ,所以执行起来要慢的多,-r选项可以执行系统命令
[[email protected] salt]# salt-ssh ‘*‘ -r ‘uptime‘ compute1: ---------- retcode: 0 stderr: stdout: 12:47:26 up 3:37, 0 users, load average: 0.00, 0.00, 0.00 compute2: ---------- retcode: 0 stderr: stdout: 12:47:26 up 3:35, 0 users, load average: 0.00, 0.00, 0.00
2、使用salt-ssh部署
OK,那现在我们可以通过salt-ssh开始部署minion的部署。
[[email protected] salt]# vim epel/ salt_install.sls test.sls [[email protected] salt]# vim epel/salt_install.sls clear_yum: cmd.run: - name: yum clean all //清除一下yum缓存 cache_yum: cmd.run: - name: yum makecache //重新生成最新的yum缓存
salt_install: pkg.installed: - name: salt-minion //指定安装的软件包
[[email protected] salt]# salt-ssh compute2 state.sls epel.salt_install compute2: ---------- cmd_|-cache_yum_|-yum makecache_|-run: ---------- __run_num__: 1 changes: ---------- pid: 10311 retcode: 0 stderr: This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. stdout: Loaded plugins: product-id, security, subscription-manager Metadata Cache Created comment: Command "yum makecache" run name: yum makecache result: True cmd_|-clear_yum_|-yum clean all_|-run: ---------- __run_num__: 0 changes: ---------- pid: 10310 retcode: 0 stderr: This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. stdout: Loaded plugins: product-id, security, subscription-manager Cleaning repos: base rhel-HighAvailability rhel-LoadBalancer : rhel-ResilientStorage rhel-ScalableFileSystem rhel-Server : saltstack Cleaning up Everything comment: Command "yum clean all" run name: yum clean all result: True pkg_|-salt_install_|-salt-minion_|-installed: ---------- __run_num__: 2 changes: ---------- openpgm: ---------- new: 5.1.118-3.el6 old: python-babel: ---------- new: 0.9.4-5.1.el6 old: python-jinja2: ---------- new: 2.2.1-1.el6.rf old: python-libcloud: ---------- new: 0.14.1-1.el6 old: python-yaml: ---------- new: 3.09-3.el6.rf old: python-zmq: ---------- new: 14.3.1-1.el6 old: salt: ---------- new: 2014.1.10-4.el6 old: salt-minion: ---------- new: 2014.1.10-4.el6 old: sshpass: ---------- new: 1.05-1.el6.rf old: zeromq3: ---------- new: 3.2.4-1.el6 old: comment: The following packages were installed/updated: salt-minion. name: salt-minion result: True # salt-ssh ‘*‘ -r ‘sed -i "s/#master: salt/master: 10.10.10.4/" /etc/salt/minion ‘ //修改修改minion的master的IP地址 # salt-ssh ‘*‘ -r ‘service salt-minion restart‘ [[email protected] salt]# salt-key -L Accepted Keys: Unaccepted Keys: compute1 compute2 manager01 Rejected Keys: [[email protected] salt]# salt-key –A //接受所有的key The following keys are going to be accepted: Unaccepted Keys: compute1 compute2 manager01 Proceed? [n/Y] y Key for minion compute1 accepted. Key for minion compute2 accepted. Key for minion manager01 accepted. [[email protected] salt]# salt-key -L Accepted Keys: compute1 compute2 manager01 Unaccepted Keys: Rejected Keys:
[[email protected] salt]# salt ‘*‘ test.ping compute1: True compute2: True manager01: True [[email protected] salt]# salt ‘*‘ cmd.run ‘date‘ compute1: Wed Feb 11 07:47:52 CST 2015 compute2: Wed Feb 11 07:47:52 CST 2015 manager01: Wed Feb 11 07:47:52 CST 2015
时间: 2024-10-10 21:51:36