SaltStack

配置yum源


[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2020-02-11 15:39:19--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 111.48.167.244, 111.48.167.240, 111.48.167.239, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|111.48.167.244|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

100%[=================================================================>] 2,523       --.-K/s 用时 0.001s  

2020-02-11 15:39:19 (1.92 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])

修改服务端的主机名

[root@localhost ~]# hostname 
localhost.localdomain
[root@localhost ~]# hostnamectl set-hostname node1
[root@localhost ~]# bash

[root@node1 ~]# sed -i 's#\$releasever#7#g' /etc/yum.repos.d/CentOS-Base.repo

[root@node1 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
--2020-02-11 15:43:00--  http://mirrors.aliyun.com/repo/epel-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 111.48.167.248, 111.48.167.243, 111.48.167.239, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|111.48.167.248|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:664 [application/octet-stream]
正在保存至: “/etc/yum.repos.d/epel.repo”

100%[=================================================================>] 664         --.-K/s 用时 0.03s   

2020-02-11 15:43:00 (24.7 KB/s) - 已保存 “/etc/yum.repos.d/epel.repo” [664/664])



[root@node1 ~]# yum -y install salt-master salt-minion
。。。。。
已安装:
  salt-master.noarch 0:2015.5.10-2.el7                 salt-minion.noarch 0:2015.5.10-2.el7           

作为依赖被安装:
  PyYAML.x86_64 0:3.10-11.el7                                    json-c.x86_64 0:0.11-4.el7_0         
  libsodium.x86_64 0:1.0.18-1.el7                                libtomcrypt.x86_64 0:1.17-26.el7     
  libtommath.x86_64 0:0.42.0-6.el7                               libyaml.x86_64 0:0.1.4-11.el7_0      
  lz4.x86_64 0:1.7.5-3.el7                                       openpgm.x86_64 0:5.2.122-2.el7       
  python-babel.noarch 0:0.9.6-8.el7                              python-backports.x86_64 0:1.0-8.el7  
  python-backports-ssl_match_hostname.noarch 0:3.5.0.1-1.el7     python-chardet.noarch 0:2.2.1-3.el7  
  python-ipaddress.noarch 0:1.0.16-2.el7                         python-jinja2.noarch 0:2.7.2-4.el7   
  python-kitchen.noarch 0:1.1.1-5.el7                            python-markupsafe.x86_64 0:0.11-10.el
  python-requests.noarch 0:2.6.0-8.el7_7                         python-six.noarch 0:1.9.0-2.el7      
  python-urllib3.noarch 0:1.10.2-7.el7                           python2-crypto.x86_64 0:2.6.1-16.el7 
  python2-msgpack.x86_64 0:0.5.6-5.el7                           python2-zmq.x86_64 0:14.7.0-8.el7    
  salt.noarch 0:2015.5.10-2.el7                                  systemd-python.x86_64 0:219-67.el7_7.
  yum-utils.noarch 0:1.1.31-52.el7                               zeromq.x86_64 0:4.1.4-6.el7          

作为依赖被升级:
  cryptsetup-libs.x86_64 0:2.0.3-5.el7                 libgudev1.x86_64 0:219-67.el7_7.3              
  systemd.x86_64 0:219-67.el7_7.3                      systemd-libs.x86_64 0:219-67.el7_7.3           
  systemd-sysv.x86_64 0:219-67.el7_7.3                

完毕!



服务启动、重启,关闭防火墙、selinux
[root@node1 ~]# systemctl start salt-master
[root@node1 ~]# systemctl start salt-minion
[root@node1 ~]# systemctl stop firewalld
[root@node1 ~]# setenforce 0
[root@node1 ~]# systemctl enable salt-master
Created symlink from /etc/systemd/system/multi-user.target.wants/salt-master.service to /usr/lib/systemd/system/salt-master.service.
[root@node1 ~]# systemctl enable salt-minion
Created symlink from /etc/systemd/system/multi-user.target.wants/salt-minion.service to /usr/lib/systemd/system/salt-minion.service.


[root@node1 ~]# ss -antl
State       Recv-Q Send-Q     Local Address:Port                    Peer Address:Port              
LISTEN      0      128                    *:22                                 *:*                  
LISTEN      0      100                    *:4505                               *:*                  
LISTEN      0      100            127.0.0.1:25                                 *:*                  
LISTEN      0      100                    *:4506                               *:*                  
LISTEN      0      128                   :::22                                :::*                  
LISTEN      0      100                  ::1:25                                :::* 


修改被控端的配置文件,将master设为主控端的IP
[root@node1 ~]# sed -i '/^#master:/a master: 192.168.161.131' /etc/salt/minion   
[root@node1 ~]# sed -n '/^master/p' /etc/salt/minion
master: 192.168.161.131

[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2020-02-11 15:49:04--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 111.48.167.244, 111.48.167.238, 111.48.167.241, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|111.48.167.244|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

100%[===========================================================>] 2,523       --.-K/s 用时 0.002s  

2020-02-11 15:49:04 (1.41 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])

[root@localhost ~]# sed -i 's#\$releasever#7#g' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
--2020-02-11 15:49:23--  http://mirrors.aliyun.com/repo/epel-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 111.48.167.238, 111.48.167.239, 111.48.167.248, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|111.48.167.238|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:664 [application/octet-stream]
正在保存至: “/etc/yum.repos.d/epel.repo”

100%[===========================================================>] 664         --.-K/s 用时 0s      

2020-02-11 15:49:23 (74.7 MB/s) - 已保存 “/etc/yum.repos.d/epel.repo” [664/664])

[root@localhost ~]# yum -y install salt-minion
。。。。。

作为依赖被升级:
  cryptsetup-libs.x86_64 0:2.0.3-5.el7              libgudev1.x86_64 0:219-67.el7_7.3                
  systemd.x86_64 0:219-67.el7_7.3                   systemd-libs.x86_64 0:219-67.el7_7.3             
  systemd-sysv.x86_64 0:219-67.el7_7.3             

完毕!



修改被控端的配置文件,将master设为主控端的IP
[root@localhost ~]# sed -i '/^#master:/a master: 192.168.161.131' /etc/salt/minion
[root@localhost ~]# sed -n '/^master/p' /etc/salt/minion
master: 192.168.161.131




服务设置开机自启重启,更改主机名
[root@localhost ~]# systemctl start salt-minion
[root@localhost ~]# systemctl enable salt-minion
Created symlink from /etc/systemd/system/multi-user.target.wants/salt-minion.service to /usr/lib/systemd/system/salt-minion.service.
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# hostnamectl set-hostname node2
[root@localhost ~]# bash
[root@node2 ~]# 

salt-key常用选项
    -L      //列出所有公钥信息
    -a minion    //接受指定minion等待认证的key
    -A      //接受所有minion等待认证的key
    -r minion    //拒绝指定minion等待认证的key
    -R      //拒绝所有minion等待认证的key
    -f minion   //显示指定key的指纹信息
    -F      //显示所有key的指纹信息
    -d minion   //删除指定minion的key
    -D      //删除所有minion的key
    -y      //自动回答yes
[root@node1 ~]# salt-key -L
Accepted Keys:
Denied Keys:
Unaccepted Keys:
192.168.161.132
Rejected Keys:

[root@node1 ~]# salt-key -a 'node*'
The following keys are going to be accepted:
Unaccepted Keys:
node1
Proceed? [n/Y] y
Key for minion node1 accepted.

[root@node1 ~]# salt-key -A
The following keys are going to be accepted:
Unaccepted Keys:
192.168.161.132
Proceed? [n/Y] y
Key for minion 192.168.161.132 accepted.

 SaltStack远程执行

[root@node1 ~]# salt "192.168.161.132" test.ping
192.168.161.132:
    True
[root@node1 ~]# salt "192.168.161.132" cmd.run ls
192.168.161.132:
    anaconda-ks.cfg
[root@node1 ~]# salt '*' test.ping
192.168.161.132:
    True
node1:
    True

salt命令使用

//语法:salt [options] '<target>' <function> [arguments]

//常用的options
    --version       //查看saltstack的版本号
    --versions-report   //查看saltstack以及依赖包的版本号
    -h      //查看帮助信息
    -c CONFIG_DIR   //指定配置文件目录(默认为/etc/salt/)
    -t TIMEOUT      //指定超时时间(默认是5s)
    --async     //异步执行
    -v      //verbose模式,详细显示执行过程
    --username=USERNAME     //指定外部认证用户名
    --password=PASSWORD     //指定外部认证密码
    --log-file=LOG_FILE     //指定日志记录文件
    
//常用target参数
    -E      //正则匹配
    -L      //列表匹配 
    -S      //CIDR匹配网段
    -G      //grains匹配
    --grain-pcre    //grains加正则匹配
    -N      //组匹配
    -R      //范围匹配
    -C      //综合匹配(指定多个匹配)
    -I      //pillar值匹配


[root@node1 ~]# salt -E '192*' test.ping
192.168.161.132:
    True
[root@node1 ~]#  salt -L 192.168.161.132,192.168.161.131 test.ping
192.168.161.132:
    True
[root@node1 ~]# vim /etc/salt/minion
[root@node1 ~]#  salt -L 192.168.161.132,node1 test.ping
node1:
    True
192.168.161.132:
    True
[root@node1 ~]# salt -S '192.168.161.0/24' test.ping
192.168.161.132:
    True
node1:
    True
[root@node1 ~]# salt -G 'os:redhat' test.ping
node1:
    True

192.168.161.132:
    True


1.常用的自动化运维工具有:
puppet
ansible     优点常用于小公司,无客户端  
            缺点无法并行执行
saltstack   优点常用于中、大型公司,可以并行执行
 
 
2.salt-minion与salt-master的认证过程:
minion在第一次启动时,会在/etc/salt/pki/minion/下自动生成一对密钥,然后将公钥发给master
master收到minion的公钥后,通过salt-key命令接受该公钥。此时master的/etc/salt/pki/master/minions目录将会存放以minion id命名的公钥,然后master就能对minion发送控制指令了 


3.因为salt是并行执行的,且是由minion端主动找mastaer端进行连接,master只需要通过命令来同意即可。而ansible则是串行的,只有在一个连接建立好了之后,才会建立下一个连接。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值