ikyujyhtg 发表于 2017-2-16 09:52:41

saltstack的master以及minion的安装

master:
查看主机解析(如果内网有自己的DNS主从,那就更省事情了)

1
2
3
4
5
6
# 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
# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum -y install salt-master
# /etc/init.d/salt-master start
Starting salt-master daemon:                               [确定]
# chkconfig --add salt-master
# chkconfig salt-master on
# chkconfig --list | grep salt-master
salt-master    0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
# 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
# lsof -i :4505
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
salt-mast 2907 root   12uIPv416492      0t0TCP *:4505 (LISTEN)
# lsof -i :4506
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
salt-mast 2927 root   20uIPv416519      0t0TCP *:4506 (LISTEN)




进入salt的目录,查看目录结构:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# cd /etc/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
#rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
#yum -y install salt-minion
# /etc/init.d/salt-minion start
Starting salt-minion daemon:                               [确定]
# chkconfig --list | grep salt
salt-minion    0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
# 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
# cd /etc/salt/




修改前备份minion端配置文件(运维要养成好习惯)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# cp minion minion.bak
设置master的名称:(这里也可以写为master: 10.10.10.140)
# sed -i "16s/#master: salt/master: master.saltstack.com/" /etc/salt/minion
设置minion端的ID
# sed -i "78s/#id:/id: minion.saltstack.com/" /etc/salt/minion
# diff /etc/salt/minion /etc/salt/minion.bak
16c16
< master: master.saltstack.com
---
> #master: salt
78c78
< id: node01.saltstack.com
---
> #id:
# egrep -v '#|^$' /etc/salt/minion |uniq
id: 10.10.10.140
# /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
# salt-key -L
Accepted Keys:
Denied Keys:
Unaccepted Keys:
node01.saltstack.com
Rejected Keys:
说明:使用salt-key -L表明查看key的信息
# salt-key -a node01.saltstack.com
The following keys are going to be accepted:
Unaccepted Keys:
node01.saltstack.com
Proceed? Y
Key for minion node01.saltstack.com accepted.
说明:如上所示,在服务端允许node01.saltstack.com成为被信任的key
# 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
# salt '*' test.ping
node01.saltstack.com:
    True
说明:返回值为True,表明执行的结果是正确的
# salt 'node01.saltstack.com' cmd.run 'df -h'
node01.saltstack.com:
    Filesystem      SizeUsed Avail Use% Mounted on
    /dev/sda5      14G8.4G4.5G66% /
    tmpfs         932M   84K932M   1% /dev/shm
    /dev/sda1       190M   42M139M23% /boot
    /dev/sda3       2.0G   18M1.8G   1% /tmp
# salt 'node01.saltstack.com' cmd.run 'ntpdate -u 10.203.10.20'
node01.saltstack.com:
    15 Feb 13:37:12 ntpdate: step time server 10.203.10.20 offset -28800.128648 sec




到此,salt的master以及minion端的安装就已完成



页: [1]
查看完整版本: saltstack的master以及minion的安装