三种模式
Local
Master/minion
Salt ssh
三大功能
远程执行
配置管理
云管理
配置系统环境
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
cat /etc/redhat-release CentOS release 6.6 (Final)
setenforce 0
/etc/init.d/iptables stop [root@node1 ~]# cat /etc/hosts 127.0 . 0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168 . 10 .129node1
192.168 . 10.128 node2
[root@node2 ~]# cat /etc/hosts 127.0 . 0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168 . 10.129 node1
192.168 . 10.128 node2
|
下载并配置slat-master 和salt-minion(Master/minion模式)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@node1 ~]# wget -P /etc/yum.repos.d/ http: //mirrors.aliyun.com/repo/epel-6.repo
[root@node1 ~]# yum install -y salt-master salt-minion -y [root@node1 ~]# chkconfig salt-master on [root@node1 ~]# /etc/init.d/salt-master start [root@node1 ~]# vim /etc/salt/minion master: 192.168 . 10.129
[root@node1 ~]# /etc/init.d/salt-minion start [root@node1 ~]# chkconfig salt-minion on [root@node2 ~]# wget -P /etc/yum.repos.d/ http: //mirrors.aliyun.com/repo/epel-6.repo
[root@node2 ~]# yum install -y salt-minion [root@node2 ~]# vim /etc/salt/minion master: 192.168 . 10.129
[root@node2 ~]# /etc/init.d/salt-minion start |
Master与Minion的连接
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@node1 master]# salt-key -a node* [root@node1 master]# salt-key -L Accepted Keys: node1 node2 Denied Keys: Unaccepted Keys: Rejected Keys: [root@node1 master]# salt '*' test.ping
node2: True
node1: True |
远程执行命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[root@node1 master]# salt '*' cmd.run 'df -h'
node1: Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
8 .3G 2 .1G 5 .8G 26 % /
tmpfs 242M 16K 242M 1 % /dev/shm
/dev/sda1 477M 28M 424M 7 % /boot
node2: Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
8 .3G 2 .1G 5 .9G 26 % /
tmpfs 242M 12K 242M 1 % /dev/shm
/dev/sda1 477M 28M 424M 7 % /boot
[root@node1 master]# salt '*' cmd.run 'uptime'
node2: 13 : 33 : 55 up 13 : 51 , 2 users, load average: 0.07 , 0.02 , 0.00
node1: 05 : 35 : 41 up 13 : 51 , 2 users, load average: 0.00 , 0.04 , 0.10
|
配置管理(下载httpd并启动)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@node1 master]# vim /etc/salt/master #注意空格,必须要启动一个base才能配置管理 file_roots: base:
- /srv/salt
[root@node1 master]# mkdir /srv/salt [root@node1 master]# /etc/init.d/salt-master restart [root@node1 master]# cd /srv/salt/ [root@node1 salt]# cat apache.sls #注意空格 apache-install: pkg.installed:
- names:
- httpd
- httpd-devel
apache-service: service.running:
- name: httpd
- enable: True
- reload: True |
使用命令直接执行状态
1
2
3
4
5
|
[root@node1 salt]# salt '*' state.sls apache #*代表所有salt-minion都执行
[root@node2 ~]# netstat -tunlp|grep httpd tcp 0 0 ::: 80 :::* LISTEN 9361 /httpd
[root@node1 salt]# netstat -tunlp|grep 80
tcp 0 0 ::: 80 :::* LISTEN 23119 /httpd
|
使用top.sls指定minlion执行状态
1
2
3
4
5
6
7
8
|
[root@node1 salt]# pwd /srv/salt [root@node1 salt]# cat top.sls #base环境下指定node2要执行apache这个状态,top指定谁可以执行什么状态,一般所有机器要执行的状态放在base环境中) base: 'node2' : #仅仅node2执行了apache这个状态
- apache
[root@node1 salt]# salt 'node2' state.highstate
|
本文转自 fxl风 51CTO博客,原文链接:http://blog.51cto.com/fengxiaoli/1957977