saltstack學習一:安裝與升級

weixin_33858249發表於2017-11-12

由於我的伺服器是centos5,安裝後還要把zeromq升級,有點蛋疼


一:服務端的安裝:

1
2
3
4
rpm -Uvh http://mirror.pnl.gov/epel/5/i386/epel-release-5-4.noarch.rpm
yum install salt-master
chkconfig salt-master on
service salt-master start


二、客戶端的安裝:

1
2
3
4
5
6
7
rpm -Uvh http://mirror.pnl.gov/epel/5/i386/epel-release-5-4.noarch.rpm
yum install salt-minion
chkconfig salt-minion on
#修改/etc/salt/minion配置:
master: 192.168.1.100   #服務端IP
id: 192.168.1.101       #標識,我用本機IP做標識
service salt-minion start


起始以為就這樣快樂的安裝完了,但測試過程中發現minion端會產生一個殭屍程式,問了群上的大神綠肥才知道這是一個BUG,要把minion端升級到2014.1.1版本:

1
2
yum --enablerepo=epel-testing install salt-minion
service salt-minion restart

這樣殭屍程式的BUG總算解決了,後來網上一看原來centos5安裝salt還有一個BUG,就是zeromq的版本太低,還需要升級一下,於是又找到這個辦法來升級:

1
2
3
4
wget -O /etc/yum.repos.d/ownsource.repo http://www.comingchina.com:8080/testing/ownsource/ownsource.repo
yum clean all
yum update zeromq libzmq3 python26-zmq
service salt-minion restart

檢查一下版本:

1
2
3
4
5
6
7
8
9
10
11
[root@localhost Server]# salt-minion  --versions-report
           Salt: 2014.1.1
         Python: 2.6.8 (unknown, Nov  7 2012, 14:47:45)
         Jinja2: unknown
       M2Crypto: 0.21.1
 msgpack-python: 0.1.12
   msgpack-pure: Not Installed
       pycrypto: 2.3
         PyYAML: 3.08
          PyZMQ: 13.1.0
            ZMQ: 3.2.2

確實是升級成功了,於是後面就想用salt的state功能來完成剩下機器的升級,可是不會弄呀,果斷網上抄一份配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
getownsourcerepo:
    cmd.run:
        - name: wget -O /etc/yum.repos.d/ownsource.repo http://www.comingchina.com:8080/testing/ownsource/ownsource.repo
        - unless: test -f /etc/yum.repos.d/ownsource.repo
                                                                                                           
zeromqs:
    pkg.installed:
        - pkgs:
            - zeromq
            - libzmq3
            - python26-zmq
        - require:
            - cmd: getownsourcerepo
                                                                                                           
salt-minion:
    service.running:
        enable: True
        watch:
            - pkg: zeromqs

放在/etc/salt/updatezeromq.sls,然後先找一臺機器測試一下:

1
salt '192.168.1.102' state.sls updatezeromq

哇,好神奇,這樣就可以更新了,等命令跑完,看一下版本,還是沒變,擦,這是什麼情況,認真看了一下日誌,是zeromq python26-zmq這兩個包已經存在,沒有升級,於是找了一下文件,看看pkg.installed 怎麼升級軟體,突然發現原來還可以指定版本的,果斷把sls檔案改成:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
getownsourcerepo:
    cmd.run:
        - name: wget -O /etc/yum.repos.d/ownsource.repo http://www.comingchina.com:8080/testing/ownsource/ownsource.repo
        - unless: test -f /etc/yum.repos.d/ownsource.repo
zeromqs:
    pkg.installed:
        - pkgs:
            - zeromq: 3.2.2-13.1
            - libzmq3
            - python26-zmq: 13.1.0-1
        - require:
            - cmd: getownsourcerepo
salt-minion:
    service.running:
        enable: True
        watch:
            - pkg: zeromqs

再來一次:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
[root@localhost salt]# salt  '192.168.1.102' state.sls updatezeromq
192.168.1.102:
----------
          ID: getownsourcerepo
    Function: cmd.run
        Name: wget -O /etc/yum.repos.d/ownsource.repo http://www.comingchina.com:8080/testing/ownsource/ownsource.repo
      Result: True
     Comment: Command "wget -O /etc/yum.repos.d/ownsource.repo http://www.comingchina.com:8080/testing/ownsource/ownsource.repo" run
     Changes: 
              ----------
              pid:
                  29228
              retcode:
                  0
              stderr:
                  --2014-04-09 17:35:22--  http://www.comingchina.com:8080/testing/ownsource/ownsource.repo
                  Resolving www.comingchina.com... 202.103.191.13
                  Connecting to www.comingchina.com|202.103.191.13|:8080... connected.
                  HTTP request sent, awaiting response... 200 OK
                  Length: 150 [text/plain]
                  Saving to: `/etc/yum.repos.d/ownsource.repo'
                                            
                       0K                                                       10014.3M=0s
                                            
                  2014-04-09 17:35:23 (14.3 MB/s) - `/etc/yum.repos.d/ownsource.repo' saved [150/150]
              stdout:
                                            
----------
          ID: zeromqs
    Function: pkg.installed
      Result: True
     Comment: 3 targeted packages were installed/updated.
     Changes: 
              ----------
              libzmq3:
                  ----------
                  new:
                      3.2.2-13.1
                  old:
                                                
              python26-zmq:
                  ----------
                  new:
                      13.1.0-1
                  old:
                      2.1.9-3.el5
              zeromq:
                  ----------
                  new:
                      3.2.2-13.1
                  old:
                      2.2.0-4.el5
----------
          ID: salt-minion
    Function: service.running
      Result: True
     Comment: Service restarted
     Changes: 
              ----------
              salt-minion:
                  True
Summary
------------
Succeeded: 3
Failed:    0
------------
Total:     3

終於順利升級成功!感覺玩這東西還真不容易。。。

本文轉自運維筆記部落格51CTO部落格,原文連結http://blog.51cto.com/lihuipeng/1393013如需轉載請自行聯絡原作者


lihuipeng

相關文章