saltstack初探

來源:互聯網
上載者:User

標籤:saltstack

系統內容:CentOS release 6.7 (Final)  

核心版本:2.6.32-573.el6.x86_64

硬體環境:20G硬碟    2G記憶體    雙核CPU  

IP地址部署:

master: 10.0.0.7     hostname:linux-node1.example.com

minion: 10.0.0.8     hostname:linux-node2.example.com


[[email protected] ~]# yum install salt-master salt-minion -y

[[email protected] ~]# cat /etc/salt/master | grep -v "^#"     

client_acl:

  oldboy:

    - test.ping

    - network.*

  user01:

    - linux-node1.example.com:

    - test.ping


file_roots:

  base:

    - /srv/salt/base

  prod:

    - /srv/salt/prod

  test:

    - /srv/salt/test


pillar_roots:

  base:

    - /srv/pillar/base


master_job_cache: mysql

mysql.host: ‘10.0.0.7‘

mysql.user: ‘salt‘

mysql.pass: ‘salt‘

mysql.db: ‘salt‘

mysql.port: 3306

etcd_pillar_config:

  etcd.host: 10.0.0.7

  etcd.port: 4001


ext_pillar:

  - etcd: etcd_pillar_config root=/salt/haproxy/



[[email protected] ~]# cat /etc/salt/minion | grep -v "^#"     

master: 10.0.0.7

id: linux-node1.example.com


grains:

  roles:

    - webserver

    - memcache


mysql.host: ‘10.0.0.7‘

mysql.user: ‘salt‘

mysql.pass: ‘salt‘

mysql.db: ‘salt‘

mysql.port: 3306


[[email protected] ~]# /etc/init.d/salt-master restart

Stopping salt-master daemon:                               [確定]

Starting salt-master daemon:                               [確定]


[[email protected] ~]# /etc/init.d/salt-minion restart

Stopping salt-minion daemon:                               [確定]

Starting salt-minion daemon:                               [確定]


[[email protected] ~]# salt-key  -L                      -L    顯示所有的機器列表

Accepted Keys:

Denied Keys:

Unaccepted Keys:

linux-node1.example.com

linux-node2.example.com

Rejected Keys:


[[email protected] ~]# salt-key -a linux-node1.example.com         -a    指定接受某台機器     

The following keys are going to be accepted:

Unaccepted Keys:

linux-node1.example.com

Proceed? [n/Y] y  

Key for minion linux-node1.example.com accepted.


[[email protected] ~]# salt-key 

Accepted Keys:

linux-node1.example.com

Denied Keys:

Unaccepted Keys:

linux-node2.example.com

Rejected Keys:


[[email protected] ~]# salt-key -A                                 -A    接受所有的機器

The following keys are going to be accepted:

Unaccepted Keys:

linux-node2.example.com

Proceed? [n/Y] Y

Key for minion linux-node2.example.com accepted.


[[email protected] ~]# salt-key                                  不帶參數預設為-L

Accepted Keys:

linux-node1.example.com

linux-node2.example.com

Denied Keys:

Unaccepted Keys:

Rejected Keys:



[[email protected] ~]# salt ‘*‘ test.ping                       ======salt-master是否與salt-minion建立聯絡,如果建立則返回True

linux-node2.example.com:

    True

linux-node1.example.com:

    True


top file檔案的作用:

告訴minion端在哪台機器上執行什麼操作:

例子:

[[email protected] ~]# cat /srv/salt/top.sls 

base:                                                         =============>指明什麼環境

  ‘*.example.com‘:                                            =============>指明哪台機器

    - apache                                                  =============>指明需要執行什麼狀態


apache.sls檔案:

apache-install:                                               ==============>id,可隨意取

  pkg.installed:                                              ==============>模組和方法

    - names:                                                  ==============>指定下面需要安裝什麼模組 

      - httpd                                                 ==============>需要哪個軟體包

      - httpd-devel                                           ==============>需要哪個軟體包


apache-service:                                               ==============>id,可隨意取

  service.running:                                            ==============>模組和方法

    - name: httpd                                             ==============>程式名

    - enable: True                                            ==============>是否開機自啟動

    - reload: True                                            ==============>是否允許重載


[[email protected] salt]# salt ‘*‘ state.sls apache

salt                    命令

 *                      指明哪一台機器

state                   模組

sls                     方法

apache                  指明是哪個狀態檔案需要執行


###########################################################################################################################################################################

###########################################################################################################################################################################

###########################################################################################################################################################################


[[email protected] ~]# yum install salt-minion -y

[[email protected] ~]# cat /etc/salt/minion | grep -v "^#"

master: 10.0.0.7

id: linux-node2.example.com

mysql.host: ‘10.0.0.7‘

mysql.user: ‘salt‘

mysql.pass: ‘salt‘

mysql.db: ‘salt‘

mysql.port: 3306


[[email protected] ~]# /etc/init.d/salt-minion restart

Stopping salt-minion daemon:                               [確定]

Starting salt-minion daemon:                               [確定]


老男孩網址:http://www.etiantian.org/

聯絡qq:406564728               

歡迎提出寶貴建議

本文出自 “linux” 部落格,請務必保留此出處http://chenjisong.blog.51cto.com/7858025/1714016

saltstack初探

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.