|
master:
查看主机解析(如果内网有自己的DNS主从,那就更省事情了)
1
2
3
4
5
6
| [iyunv@master ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.10.140mastermaster.saltstack.com
10.10.10.141node01node01.saltstack.com
10.10.10.142node02node02.saltstack.com
|
安装外部epel源,然后安装salt-master
1
2
3
4
5
6
7
8
9
10
11
| [iyunv@master ~]# rpm -ivh http://dl.fedoraproject.org/pub/ ... ease-6-8.noarch.rpm
[iyunv@master ~]# yum -y install salt-master
[iyunv@master ~]# /etc/init.d/salt-master start
Starting salt-master daemon: [确定]
[iyunv@master ~]# chkconfig --add salt-master
[iyunv@master ~]# chkconfig salt-master on
[iyunv@master ~]# chkconfig --list | grep salt-master
salt-master 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
[iyunv@master ~]# netstat -tunlp | grep python
tcp 0 0 0.0.0.0:4505 0.0.0.0:* LISTEN 2907/python2.6
tcp 0 0 0.0.0.0:4506 0.0.0.0:* LISTEN 2927/python2.6
|
备注:saltstack是基于python进行开发,server端监听的是4505以及4506两个端口
1
2
3
4
5
6
| [iyunv@master ~]# lsof -i :4505
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
salt-mast 2907 root 12u IPv4 16492 0t0 TCP *:4505 (LISTEN)
[iyunv@master ~]# lsof -i :4506
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
salt-mast 2927 root 20u IPv4 16519 0t0 TCP *:4506 (LISTEN)
|
进入salt的目录,查看目录结构:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| [iyunv@master ~]# cd /etc/salt/
[iyunv@master salt]# tree
.
├── master
├── pki
│ └── master
│ ├── master.pem
│ ├── master.pub
│ ├── minions
│ ├── minions_autosign
│ ├── minions_denied
│ ├── minions_pre
│ ├── minions_rejected
│ └── ssh
│ ├── salt-ssh.rsa
│ └── salt-ssh.rsa.pub
├── roster
├── roster.bak
└── roster.org
8 directories, 8 files
|
备注:/etc/salt/master这个文件,为saltstack master的主配置文件
minion:
安装和配置minion端
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| [iyunv@node01 ~]# rpm -ivh http://dl.fedoraproject.org/pub/ ... ease-6-8.noarch.rpm
[iyunv@node01 ~]# yum -y install salt-minion
[iyunv@node01 ~]# /etc/init.d/salt-minion start
Starting salt-minion daemon: [确定]
[iyunv@node01 ~]# chkconfig --list | grep salt
salt-minion 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
[iyunv@node01 ~]# tree /etc/salt/
/etc/salt/
├── minion
├── minion.d
├── minion_id
└── pki
└── minion
├── minion.pem
└── minion.pub
3 directories, 4 files
You have new mail in /var/spool/mail/root
[iyunv@node01 ~]# cd /etc/salt/
|
修改前备份minion端配置文件(运维要养成好习惯)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| [iyunv@node01 salt]# cp minion minion.bak
设置master的名称:(这里也可以写为master: 10.10.10.140)
[iyunv@node01 salt]# sed -i "16s/#master: salt/master: master.saltstack.com/" /etc/salt/minion
设置minion端的ID
[iyunv@node01 salt]# sed -i "78s/#id:/id: minion.saltstack.com/" /etc/salt/minion
[iyunv@node01 salt]# diff /etc/salt/minion /etc/salt/minion.bak
16c16
< master: master.saltstack.com
---
> #master: salt
78c78
< id: node01.saltstack.com
---
> #id:
[iyunv@node01 salt]# egrep -v '#|^$' /etc/salt/minion |uniq
id: 10.10.10.140
[iyunv@node01 salt]# /etc/init.d/salt-minion restart
Stopping salt-minion daemon: [确定]
Starting salt-minion daemon: [确定]
|
在master端接受指定的key:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| [iyunv@master ~]# salt-key -L
Accepted Keys:
Denied Keys:
Unaccepted Keys:
node01.saltstack.com
Rejected Keys:
说明:使用salt-key -L表明查看key的信息
[iyunv@master ~]# salt-key -a node01.saltstack.com
The following keys are going to be accepted:
Unaccepted Keys:
node01.saltstack.com
Proceed? [n/Y] Y
Key for minion node01.saltstack.com accepted.
说明:如上所示,在服务端允许node01.saltstack.com成为被信任的key
[iyunv@master ~]# salt-key -L
Accepted Keys:
node01.saltstack.com
Denied Keys:
Unaccepted Keys:
Rejected Keys:
|
使用salt推送几个常用的命令进行测试:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| [iyunv@master ~]# salt '*' test.ping
node01.saltstack.com:
True
说明:返回值为True,表明执行的结果是正确的
[iyunv@master ~]# salt 'node01.saltstack.com' cmd.run 'df -h'
node01.saltstack.com:
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 14G 8.4G 4.5G 66% /
tmpfs 932M 84K 932M 1% /dev/shm
/dev/sda1 190M 42M 139M 23% /boot
/dev/sda3 2.0G 18M 1.8G 1% /tmp
[iyunv@master ~]# salt 'node01.saltstack.com' cmd.run 'ntpdate -u 10.203.10.20'
node01.saltstack.com:
15 Feb 13:37:12 ntpdate[9245]: step time server 10.203.10.20 offset -28800.128648 sec
|
到此,salt的master以及minion端的安装就已完成
|
|
|
|
|
|
|