溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Saltstack怎樣批量部署apache

發(fā)布時間:2021-09-26 15:57:26 來源:億速云 閱讀:129 作者:柒染 欄目:系統(tǒng)運(yùn)維

這篇文章給大家介紹Saltstack怎樣批量部署apache,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

什么是SaltStack

SaltStack管理工具允許管理員對多個操作系統(tǒng)創(chuàng)建一個一致的管理系統(tǒng)

實(shí)驗環(huán)境準(zhǔn)備

名稱角色地址
centos7-minmaster192.168.142.172
centos7-min2client192.168.142.110

實(shí)驗步驟

一、主服務(wù)器——控制節(jié)點(diǎn)

安裝epel源并安裝控制端

yum install -y epel-release  //安裝epel源

yum -y install salt-master   //安裝控制端

修改控制端主配置文件

vi /etc/salt/master
//修改如下:
15行 interface: 192.168.142.172   //監(jiān)聽地址
215行 auto_accept: True        //避免要運(yùn)行salt-key來確認(rèn)證書認(rèn)證
416行 file_roots:
          base:
          - /srv/salt           //saltstack文件根目錄位置,目錄需要手動進(jìn)行創(chuàng)建
710行組分類:(這里實(shí)驗環(huán)境只有一臺客戶端,僅設(shè)置一個即可)
nodegroups:
  group1: 'web01.saltstack.com'

552行 pillar_opts: True        //開啟pillar功能,同步文件功能
529行 
pillar_roots:
          base:
          - /srv/pillar         //pillar的主目錄,需要手動進(jìn)行創(chuàng)建

建立salt&pillar目錄

mkdir /srv/salt
mkdir /srv/pillar

啟動服務(wù)并關(guān)閉核心防護(hù)功能

systemctl start salt-master
systemctl enable salt-master
//關(guān)閉核心功能
setenforce 0

檢測服務(wù)啟動狀況

netstat -anpt | egrep '4505|4506'
//4505為salt的消息發(fā)布專用端口;
//4506為客戶端與服務(wù)端通信的端口
tcp        0      0 192.168.142.172:4505    0.0.0.0:*               LISTEN      13692/python
tcp        0      0 192.168.142.172:4506    0.0.0.0:*               LISTEN      13704/python
tcp        0      0 192.168.142.172:4506    192.168.142.110:36688   ESTABLISHED 13704/python
tcp        0      0 192.168.142.172:4505    192.168.142.110:57042   ESTABLISHED 13692/python

二、從服務(wù)器——被控制節(jié)點(diǎn)

安裝epel源并安裝被控制端

yum install -y epel-release  //安裝epel源

yum -y install salt-minion   //安裝被控制端

修改被控端配置文件

vi /etc/salt/minion
//修改配置如下:
16行 master: 192.168.172.142     //指定主控端IP
78行 id: web01.saltstack.com     //指定被控端主機(jī)名

啟動服務(wù)

//啟動被控端服務(wù)
systemctl start salt-minion

在主控端進(jìn)行檢查

//在主控端測試與被控端的通信狀態(tài)(*號代表所有被控主機(jī))
salt '*' test.ping
web01.saltstack.com:
    True

//檢查密鑰情況
salt-key -L
Accepted Keys:
web01.saltstack.com
Denied Keys:
Unaccepted Keys:
web01.saltstack.com
Rejected Keys:
注意:

檢查時出現(xiàn)以下情況:
Salt request timed out. The master is not responding. If this error persists after verifying the master is up, worker_threads may need to be increased.
請自行檢查配置文件格式或者重啟服務(wù)器。

三、批量部署Apache

以下所有操作均在master端進(jìn)行
cd /srv/salt/
vim top.sls
//按下圖進(jìn)行添加
base:
  '*':
    - apache
//在所有的客戶端執(zhí)行apache模塊

vim apache.sls
//按下圖進(jìn)行添加
apache-service:
  pkg.installed:
    - names:
      - httpd
      - httpd-devel
  service.running:
    - name: httpd
    - enable: True

//重啟服務(wù)
systemctl restart salt-master.service

//執(zhí)行批量部署命令
salt '*' state.highstate
//執(zhí)行完成后出現(xiàn)以下信息即為成功
web01.saltstack.com:
----------
          ID: apache-service
    Function: pkg.installed
        Name: httpd
      Result: True
     Comment: The following packages were installed/updated: httpd
     Started: 15:04:51.323952
    Duration: 40217.299 ms
     Changes:
              ----------
              apr:
                  ----------
                  new:
                      1.4.8-5.el7
                  old:
              apr-util:
                  ----------
                  new:
                      1.5.2-6.el7
                  old:
              httpd:
                  ----------
                  new:
                      2.4.6-90.el7.centos
                  old:
              httpd-tools:
                  ----------
                  new:
                      2.4.6-90.el7.centos
                  old:
              mailcap:
                  ----------
                  new:
                      2.1.41-2.el7
                  old:
----------
          ID: apache-service
    Function: pkg.installed
        Name: httpd-devel
      Result: True
     Comment: The following packages were installed/updated: httpd-devel
     Started: 15:05:31.545046
    Duration: 16876.92 ms
     Changes:
              ----------
              apr-devel:
                  ----------
                  new:
                      1.4.8-5.el7
                  old:
              apr-util-devel:
                  ----------
                  new:
                      1.5.2-6.el7
                  old:
              cyrus-sasl:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-devel:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
              cyrus-sasl-gssapi:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-lib:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-md5:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-plain:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-scram:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              expat-devel:
                  ----------
                  new:
                      2.1.0-10.el7_3
                  old:
              httpd-devel:
                  ----------
                  new:
                      2.4.6-90.el7.centos
                  old:
              libdb:
                  ----------
                  new:
                      5.3.21-25.el7
                  old:
                      5.3.21-20.el7
              libdb-devel:
                  ----------
                  new:
                      5.3.21-25.el7
                  old:
              libdb-utils:
                  ----------
                  new:
                      5.3.21-25.el7
                  old:
                      5.3.21-20.el7
              openldap:
                  ----------
                  new:
                      2.4.44-21.el7_6
                  old:
                      2.4.44-5.el7
              openldap-devel:
                  ----------
                  new:
                      2.4.44-21.el7_6
                  old:
----------
          ID: apache-service
    Function: service.running
        Name: httpd
      Result: True
     Comment: Service httpd has been enabled, and is running
     Started: 15:05:48.459684
    Duration: 1822.995 ms
     Changes:
              ----------
              httpd:
                  True

Summary
------------
Succeeded: 3 (changed=3)
Failed:    0

四、檢查試驗結(jié)果

web01:
[root@web01 ~]# rpm -q httpd
httpd-2.4.6-90.el7.centos.x86_64
[root@web01 ~]# netstat -ntap | grep 80
tcp6       0      0 :::80                   :::*                  LISTEN      6

關(guān)于Saltstack怎樣批量部署apache就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI