一,saltstack簡介: python
SaltStack是一種新的基礎設施管理方法開發軟件,簡單易部署,可伸縮的足以管理成千上萬的服務器,和足夠快的速度控制,與他們交流,以毫秒爲單位。
vim
SaltStack提供了一個動態基礎設施通訊總線用於編排,遠程執行、配置管理等等。SaltStack基於python開發,項目於2011年啓動,年增加速度較快,五年期
centos
固定基礎設施編制和配置管理的開源項目。SaltStack社區致力於保持鹽項目集中、友好、健康、開放。
服務器
(網上摘抄的,說白了saltStack就是一個自動化工具,能夠實現對服務器的批量操做)
app
2、安裝環境dom
saltstack支持大部分UNIX/Linux及Windows環境。本次安裝的環境採用centos6socket
host A:192.168.163.229:master工具
host B:192.168.163.152:slaveroop
三,安裝測試
host A:
[root@master ~]# yum install salt-master
[root@master ~]# yum install salt-minion
host B:
[root@slave ~]# yum install salt-minion
若是發現yum 源沒有這個包,則須要配置yum 源。
[saltstack-repo] name=SaltStack repo for RHEL/CentOS $releasever baseurl=https://repo.saltstack.com/yum/redhat/$releasever/$basearch/2016.11 enabled=1 gpgcheck=1 gpgkey=https://repo.saltstack.com/yum/redhat/$releasever/$basearch/2016.11/SALTSTACK-GPG-KEY.pub
至此,master和slaver安裝完成(由於是測試,因此只安裝了2臺slaver,正式環境,天天機器都須要安裝slaver)
4、master和slaver配置
master配置文件路徑:/etc/salt/master
vim /etc/salt/master #修改第16行 interface: 192.168.163.229
注意interface:後面有一個空格,後面再跟本機(master)的ip地址便可。保存文件,啓動master。
[root@master ~]# /etc/init.d/salt-master start Starting salt-master daemon: [肯定] [root@master ~]#
用ps命令查看進程,能夠看到master啓動成功
[root@master ~]# ps -ef| grep salt root 91637 1 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91638 91637 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91639 91637 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91640 91637 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91641 91637 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91646 91641 1 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91647 91641 1 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91653 91641 1 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91655 91641 1 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91660 91641 1 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91661 91641 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 92056 2971 0 18:02 pts/0 00:00:00 grep salt
修改slaver配置:
[root@master ~]# vim /etc/salt/minion 12 #default_include: minion.d/*.conf 13 14 # Set the location of the salt master server. If the master server cannot be 15 # resolved, then the minion will fail to start. 16 #master: salt 17 master: 192.168.163.229 18 19 # If multiple masters are specified in the 'master' setting, the default behavior 20 # is to always try to connect to them in the order they are listed. If random_master is 21 # set to True, the order will be randomized instead. This can be helpful in distributing 22 # the load of many minions executing salt-call requests, for example, from a cron job. 23 # If only one master is listed, this setting is ignored and a warning will be logged. 24 # NOTE: If master_type is set to failover, use master_shuffle instead. 25 #random_master: False 26 27 # Use if master_type is set to failover. 28 #master_shuffle: False 29 30 # Minions can connect to multiple masters simultaneously (all masters 31 # are "hot"), or can be configured to failover if a master becomes 32 # unavailable. Multiple hot masters are configured by setting this 33 # value to "str". Failover masters can be requested by setting 34 # to "failover". MAKE SURE TO SET master_alive_interval if you are 35 # using failover. 36 # master_type: str 37 38 # Poll interval in seconds for checking if the master is still there. Only 39 # respected if master_type above is "failover". To disable the interval entirely, 40 # set the value to -1. (This may be necessary on machines which have high number
修改這個文件的第16行爲 master: 192.168.163.229 。一樣的master:後面有一個空格,後面的ip地址即爲master的ip地址,這個很好理解。
修改id爲 id: 192.168.163.229 。(在文件的第78行左右)
77 # same machine but with different ids, this can be useful for salt compute 78 # clusters. 79 id: 192.168.163.229 80 81 # Append a domain to a hostname in the event that it does not exist. This is 82 # useful for systems where socket.getfqdn() does not actually result in a 83 # FQDN (for instance, Solaris). 84 #append_domain:
id便是slaver的"身份證" ,能夠自定義,也能夠使用ip地址,但須要全局惟一。
保存文件後,啓動slaver進程。
[root@master ~]# /etc/init.d/salt-minion start Starting salt-minion daemon: [肯定] [root@master ~]# [root@master ~]# [root@master ~]# ps -ef |grep salt root 91637 1 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91638 91637 0 18:01 ? 00:00:01 /usr/bin/python2.6 /usr/bin/salt-master -d root 91639 91637 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91640 91637 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91641 91637 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91646 91641 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91647 91641 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91653 91641 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91655 91641 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91660 91641 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 91661 91641 0 18:01 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d root 92243 1 2 18:09 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-minion -d root 92264 2971 0 18:09 pts/0 00:00:00 grep salt
另外一臺host 只安裝了slaver,所以只須要配置和啓動slaver便可,方法和前面同樣。
五,認證
master和slaver啓動後,用命令salt-key查看
[root@master ~]# salt-key Accepted Keys: Denied Keys: Unaccepted Keys: 192.168.163.152 192.168.163.229 Rejected Keys: [root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]#
能夠發現 Accepted Keys裏面沒有內容,Unaccpted Keys 裏面有兩條記錄。恰好就是咱們兩臺slaver,由於如今尚未認證過,因此須要先認證,纔會變成Accepted狀態。
[root@master minion]# salt-key -a 192.168.163.152 The following keys are going to be accepted: Unaccepted Keys: 192.168.163.152 Proceed? [n/Y] Y Key for minion 192.168.163.152 accepted. [root@master minion]#
[root@master minion]# salt-key -a 192.168.163.229
The following keys are going to be accepted:
Unaccepted Keys:
192.168.163.229
Proceed? [n/Y] Y
Key for minion 192.168.163.229 accepted.
[root@master minion]#
[root@master minion]#
[root@master minion]#
[root@master minion]# salt-key
Accepted Keys:
192.168.163.152
192.168.163.229
Denied Keys:
Unaccepted Keys:
Rejected Keys:
[root@master minion]#
到此完成了認證。
六,簡單的salt命令
查看遠程主機ip地址
root@master minion]# salt '192.168.163.152' cmd.run 'ifconfig' 192.168.163.152: eth1 Link encap:Ethernet HWaddr 00:0C:29:70:1E:A6 inet addr:192.168.163.152 Bcast:192.168.163.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe70:1ea6/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:498824 errors:0 dropped:0 overruns:0 frame:0 TX packets:10915 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:47223551 (45.0 MiB) TX bytes:844785 (824.9 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:50 errors:0 dropped:0 overruns:0 frame:0 TX packets:50 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:11658 (11.3 KiB) TX bytes:11658 (11.3 KiB) virbr0 Link encap:Ethernet HWaddr 52:54:00:CA:B4:D1 inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) [root@master minion]#
查看遠程主機連通性
[root@master minion]# salt '192.168.163.152' test.ping 192.168.163.152: True [root@master minion]#
好了,本次安裝部署介紹完畢,其餘salt命令之後再詳細介紹。