码迷,mamicode.com
首页 > 其他好文 > 详细

saltstack 自动化运维神器(四)salt-ssh

时间:2015-02-11 18:59:25      阅读:860      评论:0      收藏:0      [点我收藏+]

标签:程序   客户端   文章   而且   

        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状态文件

[root@salt-master ~]# 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
[root@salt-master ~]# salt-ssh ‘*‘ test.ping
compute1:
    True
compute2:
    True
manager01:
    True

## 需要注意的是,由于salt-ssh并没有继承salt的zeroMQ,所以执行起来要慢的多,-r选项可以执行系统命令

[root@salt-master 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的部署。

[root@salt-master salt]# vim epel/
salt_install.sls  test.sls          
[root@salt-master 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   //指定安装的软件包
[root@salt-master 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‘


[root@salt-master salt]# salt-key -L
Accepted Keys:
Unaccepted Keys:
compute1
compute2
manager01
Rejected Keys:
[root@salt-master 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.
[root@salt-master salt]# salt-key -L
Accepted Keys:
compute1
compute2
manager01
Unaccepted Keys:
Rejected Keys:

 
[root@salt-master salt]# salt ‘*‘ test.ping
compute1:
    True
compute2:
    True
manager01:
    True
[root@salt-master 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

 

 

 

本文出自 “conny” 博客,转载请与作者联系!

saltstack 自动化运维神器(四)salt-ssh

标签:程序   客户端   文章   而且   

原文地址:http://conny.blog.51cto.com/3367680/1613695

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!