salt-ssh install salt-minion

Saltstack?

Salt 一种全新的基础设施管理方式,部署轻松,在几分钟内可运行起来,扩展性好,很容易管理上万台服务器,速度够快,服务器之间秒级通信。node

salt底层采用动态的链接总线, 使其能够用于编配, 远程执行, 配置管理等等.git

批量部署salt-minion客户端

大规模部署salt的时候,为了减轻运维工做,须要批量来安装salt-minion客户端。github

salt-ssh是Saltstack的另外一种管理方式,无需安装minion端,能够运用Salt的一切功能,管理和使用方式和基本和Salt同样。可是执行效率会比有minion端慢不少,不适合大规模批量操做web

环境:

192.168.1.14  服务端:salt-ssh salt-master salt-minion
192.168.1.15  客户端:salt-minion
192.168.1.16  客户端:salt-minion
192.168.1.17  客户端:salt-minion

1、salt-ssh安装(master端)

一、克隆代码:

$ git clone https://github.com/BigbigY/salt-ssh-install-salt-minion.git

二、导入SaltStack存储密钥:

$ rpm --import SALTSTACK-GPG-KEY.pub

三、将saltstack.repo拷贝到/etc/yum.repos.d/

四、Run sudo yum clean expire-cache.

五、Run sudo yum update.

六、安装salt-ssh

提示:salt-ssh不须要启动服务,只须要启动下salt-master服务bash

$ yum -y install salt-ssh salt-master
$ systemctl start salt-master

2、配置salt-ssh客户端信息,通讯

一、ip文件:

把全部minion_ip放到文件中,格式以下:服务器

$ cat host_ip.txt 
192.168.1.14
192.168.1.15
192.168.1.16
192.168.1.17

二、批量添加脚本:

USERNAME是客户端用户名,PASSWORD是客户端密码,这里的话客户端帐号密码都相同,全部我写了个批量添加的脚本运维

$ cat ip.sh
#!/bin/bash
USERNAME="root"
PASSWORD="123"
for i in `cat /root/host_ip.txt`
do
        echo "$i:" >> /etc/salt/roster ##$i表示取文件的每行内容
        echo "  host: $i" >> /etc/salt/roster
        echo "  user: $USERNAME" >>/etc/salt/roster
        echo "  passwd: $PASSWORD" >>/etc/salt/roster
#        echo "  sudo: True" >>/etc/salt/roster
        echo "  timeout: 10" >>/etc/salt/roster
done

三、执行,查看

$ cat /etc/salt/roster
# Sample salt-ssh config file
#web1:
#  host: 192.168.42.1 # The IP addr or DNS hostname
#  user: fred         # Remote executions will be executed as user fred
#  sudo: True         # Whether to sudo to root, not enabled by default
#web2:
#  host: 192.168.42.2
192.168.1.14:
  host: 192.168.1.14
  user: root
  passwd: 123
  timeout: 10
192.168.1.15:
  host: 192.168.1.15
  user: root
  passwd: 123
  timeout: 10
192.168.1.16:
  host: 192.168.1.16
  user: root
  passwd: 123
  timeout: 10
192.168.1.17:
  host: 192.168.1.17
  user: root
  passwd: 123
  timeout: 10

四、测试

$ salt-ssh -i '*' test.ping
192.168.1.17:
    True
192.168.1.14:
    True
192.168.1.16:
    True
192.168.1.15:
    True

3、批量安装salt-minion

一、目录结构:

$ pwd
/srv/salt
$ tree minions/
minions/
├── 5
│   └── README.md
├── 6
│   └── README.md
└── 7
    ├── conf
    │   ├── minion
    │   ├── SALTSTACK-GPG-KEY.pub
    │   └── saltstack.repo
    └── install.sls

4 directories, 6 files

二、须要在控制端/etc/hosts文件增长Host解析(master)

$ cat /etc/hosts
192.168.1.14  salt.node1.com
192.168.1.15  salt.node2.com
192.168.1.16  salt.node3.com
192.168.1.17  salt.node4.com

三、执行:

minion配置文件根据本身master_ip修改,id根据自身状况获取ssh

$ pwd
/srv/salt
salt-ssh -i '*' state.sls minions.7.install

四、查看须要受权的主机:

$ salt-key
Accepted Keys:
Denied Keys:
Unaccepted Keys:
192.168.1.14
192.168.1.15
192.168.1.16
192.168.1.17
Rejected Keys:

五、受权要管理的主机:

$ salt-key -A
The following keys are going to be accepted:
Unaccepted Keys:
192.168.1.14
192.168.1.15
192.168.1.16
192.168.1.17
Proceed? [n/Y] y
Key for minion 192.168.1.14 accepted.
Key for minion 192.168.1.15 accepted.
Key for minion 192.168.1.16 accepted.
Key for minion 192.168.1.17 accepted.

查看

$ salt-key
Accepted Keys:
192.168.1.14
192.168.1.15
192.168.1.16
192.168.1.17
Denied Keys:
Unaccepted Keys:
Rejected Keys:

六、salt测试

$ salt '*' test.ping
192.168.1.14:
    True
192.168.1.15:
    True
192.168.1.16:
    True
192.168.1.17:
    True

七、取消salt-ssh:

在/etc/salt/roster清除添加的认证主机测试

八、测试

$ salt '*' test.ping
192.168.1.14:
    True
192.168.1.15:
    True
192.168.1.16:
    True
192.168.1.17:
    True

舒适提示: 此篇以ip为minion_id,若是须要根据主机名,能够写把主机名写命名好,而后改写install.sls grains获取改为host主机名就能够了。 或者能够本身编写个grains模块来获取。code

相关文章
相关标签/搜索