1. 程式人生 > >saltstack 快速入門

saltstack 快速入門

saltstack

三種模式

Local

Master/minion

Salt ssh


三大功能

遠程執行

配置管理

雲管理


配置系統環境

cat /etc/redhat-release

CentOS release 6.6 (Final)

setenforce 0

/etc/init.d/iptables stop

[[email protected] ~]# 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

[[email protected] ~]# 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模式

[[email protected] ~]# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo

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

[[email protected] ~]# chkconfig salt-master on

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

[[email protected]

/* */ ~]# vim /etc/salt/minion

master: 192.168.10.129

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

[[email protected] ~]# chkconfig salt-minion on

[[email protected] ~]# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo

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

[[email protected] ~]# vim /etc/salt/minion

master: 192.168.10.129

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

Master與Minion的連接

[[email protected] master]# salt-key -a node*

[[email protected] master]# salt-key -L

Accepted Keys:

node1

node2

Denied Keys:

Unaccepted Keys:

Rejected Keys:

[[email protected] master]# salt ‘*‘ test.ping

node2:

True

node1:

True


遠程執行命令

[[email protected] 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

[[email protected] 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並啟動)

[[email protected] master]# vim /etc/salt/master (註意空格,必須要啟動一個base才能配置管理)

file_roots:

base:

- /srv/salt

[[email protected] master]# mkdir /srv/salt

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

[[email protected] master]# cd /srv/salt/

[[email protected] salt]# cat apache.sls(註意空格)

apache-install:

pkg.installed:

- names:

- httpd

- httpd-devel

apache-service:

service.running:

- name: httpd

- enable: True

- reload: True


使用命令直接執行狀態

[[email protected] salt]# salt ‘*‘ state.sls apache*代表所有salt-minion都執行)

[[email protected] ~]# netstat -tunlp|grep httpd

tcp 0 0 :::80 :::* LISTEN 9361/httpd

[[email protected] salt]# netstat -tunlp|grep 80

tcp 0 0 :::80 :::* LISTEN 23119/httpd

使用top.sls指定minlion執行狀態

[[email protected] salt]# pwd

/srv/salt

[[email protected] salt]# cat top.sls(base環境下指定node2要執行apache這個狀態,top指定誰可以執行什麽狀態,一般所有機器要執行的狀態放在base環境中)

base:

‘node2‘ :僅僅node2執行了apache這個狀態

- apache

[[email protected] salt]# salt ‘node2‘ state.highstate


本文出自 “feng” 博客,請務必保留此出處http://fengxiaoli.blog.51cto.com/12104465/1957977

saltstack 快速入門