saltstack1 安装及基础操作
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了saltstack1 安装及基础操作相关的知识,希望对你有一定的参考价值。
saltstack常用网址:
官方网站:http://www.saltstack.com
官方文档:http://docs.saltstack.com
GitHub:http://github.com/saltstack
中国SaltStack用户组:http://www.saltstack.cn
saltstack运行方式:
local
mater/minion
salt ssh
saltstack三个功能:
远程执行
配置管理
云管理
master端:10.20.23.144
minion端:10.20.23.144 10.20.23.145
####所有主机名一定可以被解析,这里只列出了master端,minion端也一样###
[[email protected] ~]# hostname
linux-node1
[[email protected] ~]# ping linux-node1
PING linux-node1 (10.20.23.144) 56(84) bytes of data.
64 bytes from linux-node1 (10.20.23.144): icmp_seq=1 ttl=64 time=0.058 ms
64 bytes from linux-node1 (10.20.23.144): icmp_seq=2 ttl=64 time=0.034 ms
[[email protected] ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.20.23.144 linux-node1
10.20.23.145 linux-node2
###服务端###
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install salt-master -y
chkconfig salt-master on
/etc/init.d/salt-master start
###客户端###
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install salt-minion -y
chkconfig salt-minion on
vim /etc/salt/minion
master: 10.20.23.144
##保存退出
/etc/init.d/salt-minion start
###服务端###
[[email protected]linux-node1 salt]# lsof -i:4505
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
salt-mast 1107 root 12u IPv4 12007 0t0 TCP *:4505 (LISTEN)
[[email protected]linux-node1 salt]# lsof -i:4506
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
salt-mast 1126 root 20u IPv4 12036 0t0 TCP *:4506 (LISTEN)
[[email protected]linux-node1 ~]# salt-key
Accepted Keys:
Denied Keys:
Unaccepted Keys:
linux-node1
linux-node2
Rejected Keys:
[[email protected]_master ~]# salt-key -A
The following keys are going to be accepted:
Unaccepted Keys:
linux-node1
linux-node2
Proceed? [n/Y] Y
Key for minion linux-node1 accepted.
[[email protected]_master ~]# salt-key
Accepted Keys:
linux-node1
linux-node2
Denied Keys:
Unaccepted Keys:
Rejected Keys:
下面我们看下saltstack minion端和master端的认证:
[[email protected]_minion ~]# cd /etc/salt/
[[email protected]_minion salt]# ll
总用量 36
-rw-r-----. 1 root root 26392 10月 23 00:37 minion
drwxr-xr-x. 2 root root 4096 10月 25 21:57 minion.d
drwxr-xr-x. 4 root root 4096 10月 22 23:19 pki
[[email protected]_minion salt]# cd pki/
[[email protected]_minion pki]# ls
master minion
[[email protected]_minion pki]# cd minion/
[[email protected]_minion minion]# ll
总用量 12
-rw-r--r--. 1 root root 451 10月 25 21:57 minion_master.pub
-r--------. 1 root root 1679 10月 22 23:19 minion.pem
-rw-r--r--. 1 root root 451 10月 22 23:19 minion.pub
[[email protected]_minion minion]# pwd
/etc/salt/pki/minion
###minion端在第一次启动时会在/etc/salt/pki/minion目录下生成两个key,一个私钥minion.pem,一个公钥minion.pub,会把公钥发给master
[[email protected]_master states]# cd /etc/salt/
[[email protected]_master salt]# ll
总用量 40
-rw-r-----. 1 root root 29435 10月 25 22:43 master
drwxr-xr-x. 3 root root 4096 10月 22 19:11 pki
drwxr-xr-x. 4 root root 4096 10月 25 23:19 states
[[email protected]_master minions]# cat minion.saltstack.com
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxYHuuZiEwXQg9QFnoUOo
q8rQYLV8EZt2YgljEY8SUggJlN4Hp4gJQeTwGZASdpbh/sAaP8KH/zoxXa1cX+uf
qOObV8k7BY0Ug8NNPa5CByHgGbiAYPthQq7ASm8DZvAt3JAgBOVzwq6U8tle4u/i
vsR+uZ9X0oCZDH/dnuZG1qnaIPvRF+KYHPL1qGmIS1kfH8RizB1uXm2l6Kr1jMzN
nN+fjG5J1ofM/Ku4RcSud2IKXBLp6hrVjXgP1gddsgDFBd7VoClY2Ti3vA1EwpBL
ZoyIz1DuhP27pD4ZrxG7etx1ZsXGsy15gmteWQ09H/NQ1hvzRHpwuHAyvjaGGjNb
gwIDAQAB
-----END PUBLIC KEY-----
[[email protected]_master minions]# pwd
/etc/salt/pki/master/minions
[[email protected]_minion minion]# ll
总用量 12
-rw-r--r--. 1 root root 451 10月 25 21:57 minion_master.pub
-r--------. 1 root root 1679 10月 22 23:19 minion.pem
-rw-r--r--. 1 root root 451 10月 22 23:19 minion.pub
[[email protected]_minion minion]# pwd
/etc/salt/pki/minion
[[email protected]_minion minion]# cat minion.pub
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxYHuuZiEwXQg9QFnoUOo
q8rQYLV8EZt2YgljEY8SUggJlN4Hp4gJQeTwGZASdpbh/sAaP8KH/zoxXa1cX+uf
qOObV8k7BY0Ug8NNPa5CByHgGbiAYPthQq7ASm8DZvAt3JAgBOVzwq6U8tle4u/i
vsR+uZ9X0oCZDH/dnuZG1qnaIPvRF+KYHPL1qGmIS1kfH8RizB1uXm2l6Kr1jMzN
nN+fjG5J1ofM/Ku4RcSud2IKXBLp6hrVjXgP1gddsgDFBd7VoClY2Ti3vA1EwpBL
ZoyIz1DuhP27pD4ZrxG7etx1ZsXGsy15gmteWQ09H/NQ1hvzRHpwuHAyvjaGGjNb
gwIDAQAB
-----END PUBLIC KEY-----
###minion端的公钥会传递给master端,即minion.saltstack.com即为minion端传递过去的minion.pub 。
###master端公钥同时也会传递给minion端,即:
[[email protected]_minion minion]# pwd
/etc/salt/pki/minion
[[email protected]_minion minion]# cat minion_master.pub
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxS2k2LCyWaN4crvTziIH
vqpR47an/TPkzMMLLzZSfMcIED+2eYAAZ1HSO2HuifPrCuWaLIsV3iwL/gwPAfvF
kuwNyncz/mkJfCvB4ZupqTHKxWGlS3YM+uKxAT1pWMn44xMTK7OC22jsYfWpRYEY
feXYCmoLR7BRQi+1OaBSEoUSBkIkpGZDoHbucsKd9H2nUb+TmoDZDuxyZcs9CQPw
CCfRW6rl7a9iRgXbxZu0uwonon6xM2RL3bTDv9EdvO/N+pSYQEdkMGvrawxf8ThW
2mzdJVS+pxE1nL4gwpnVxxmoeEY4S41+tHVFwdZ5nhtxHtP+wdlHn5K+YQfxCZyM
sQIDAQAB
-----END PUBLIC KEY-----
[[email protected]_master master]# ll
总用量 28
-r--------. 1 root root 1679 10月 22 19:11 master.pem
-rw-r--r--. 1 root root 451 10月 22 19:11 master.pub
drwxr-xr-x. 2 root root 4096 10月 25 21:57 minions
drwxr-xr-x. 2 root root 4096 10月 22 19:11 minions_autosign
drwxr-xr-x. 2 root root 4096 10月 22 19:11 minions_denied
drwxr-xr-x. 2 root root 4096 10月 25 21:57 minions_pre
drwxr-xr-x. 2 root root 4096 10月 22 19:11 minions_rejected
[[email protected]_master master]# pwd
/etc/salt/pki/master
[[email protected]_master master]# cat master.pub
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxS2k2LCyWaN4crvTziIH
vqpR47an/TPkzMMLLzZSfMcIED+2eYAAZ1HSO2HuifPrCuWaLIsV3iwL/gwPAfvF
kuwNyncz/mkJfCvB4ZupqTHKxWGlS3YM+uKxAT1pWMn44xMTK7OC22jsYfWpRYEY
feXYCmoLR7BRQi+1OaBSEoUSBkIkpGZDoHbucsKd9H2nUb+TmoDZDuxyZcs9CQPw
CCfRW6rl7a9iRgXbxZu0uwonon6xM2RL3bTDv9EdvO/N+pSYQEdkMGvrawxf8ThW
2mzdJVS+pxE1nL4gwpnVxxmoeEY4S41+tHVFwdZ5nhtxHtP+wdlHn5K+YQfxCZyM
sQIDAQAB
-----END PUBLIC KEY-----
###这样就实现了master端和minion端的认证###
[[email protected] ~]# salt ‘*‘ test.ping
linux-node1:
True
linux-node2:
True
[[email protected] ~]# salt ‘*‘ cmd.run ‘uptime‘
linux-node1:
21:48:22 up 2:49, 2 users, load average: 0.00, 0.00, 0.00
linux-node2:
21:48:22 up 2:47, 1 user, load average: 1.64, 1.56, 1.47
saltstack的配置管理:
salt-master端:
vim /etc/salt/master
416 file_roots:
417 base:
418 - /srv/salt
##保存退出
mkdir /srv/salt
/etc/init.d/salt-master restart
[[email protected] ~]# cd /srv/salt
[[email protected] salt]# vim apache.sls
apache-install:
pkg.installed:
- names:
- httpd
- httpd-devel
apache-service:
service.running:
- name: httpd
- enable: True
- reload: True
[[email protected] salt]# salt ‘*‘ state.sls apache
##上条语句中的apache就是一个状态,,若是有多个状态呢 ??我们就可以使用高级状态salt ‘*‘ state.highstate,,高级状态有一个入口文件top.sls(必须放在base环境下),这个入口文件里写着这个机器有这些状态,,,那些机器有那些状态,,这样执行语句时就不用指定状态了,,直接写在top入口文件里即可。。
本文出自 “10732668” 博客,请务必保留此出处http://10742668.blog.51cto.com/10732668/1926730
以上是关于saltstack1 安装及基础操作的主要内容,如果未能解决你的问题,请参考以下文章