标签:eve pillar log make vpd web lag restart term
环境: rhel6.5 server1master
server2 minion server3 minion
配置yum安装包:rhel6
[root@server1 ~]# yum install salt-master
[root@server1 ~]# /etc/init.d/salt-master start
[root@server2 ~]# yum install salt-minion
[root@server2 ~]# vim /etc/salt/minion
master: 172.25.135.1
[root@server2 ~]# /etc/init.d/salt-minion start
[root@server1 ~]# salt-key -A
The following keys are going to be accepted:
Unaccepted Keys:
server2
Proceed? [n/Y] y
Key for minion server2 accepted.
[root@server1 ~]# salt-key -L
Accepted Keys:
server2
Denied Keys:
Unaccepted Keys:
Rejected Keys:
[root@server1 ~]# salt server2 test.ping
server2:
True
[root@server1 ~]# salt server2 cmd.run hostname
server2:
server2
[root@server1 ~]# salt server2 cmd.run df
server2:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg_server0-lv_root 18102140 2078072 15104516 13% /
tmpfs 510200 16 510184 1% /dev/shm
/dev/vda1 495844 34532 435712 8% /boot
[root@server1 ~]# salt server2 cmd.run poweroff #测试关机
server2:
[root@server1 ~]# vim /etc/salt/master
[root@server1 ~]# cd /srv/salt/
[root@server1 salt]# ls
[root@server1 salt]# mkdir apache
[root@server1 salt]# cd apache/
[root@server1 apache]# vim install.sls
httpd:
pkg.installed #写个简单的http安装
[root@server1 apache]# salt server2 state.sls apache.install
[root@server1 apache]# mkdir files
[root@server2 ~]# scp /etc/httpd/conf/httpd.conf server1:/srv/salt/apache/files
[root@server1 apache]# cd files/
[root@server1 files]# ls
httpd.conf
[root@server1 files]# vim httpd.conf #简单修改一下80端口为8080
[root@server1 apache]# ls
files install.sls
[root@server1 apache]# vim install.sls
apache-install:
pkg.installed:
-
pkgs:
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://apache/files/httpd.conf
- mode: 644
- user: root
-
group: root
service.running:
- name: httpd
- enable: Ture
- watch:
- file: apache-install
[root@server1 apache]# salt server2 state.sls apache.install #server2上apache自动修改端口为8080
[root@server1 salt]# mkdir pkgs #自动推送源码nginx
[root@server1 salt]# cd pkgs
[root@server1 pkgs]# vim make.sls
gcc-make:
pkg.installed:
- pkgs:
- gcc
- pcre-devel
- openssl-devel
[root@server1 pkgs]# ls
make.sls
[root@server1 pkgs]# cd ..
[root@server1 salt]# ls
apache nginx pkgs
[root@server1 salt]# cd nginx/
[root@server1 nginx]# ls
files install.sls
[root@server1 nginx]# vim install.sls
include:
nginx-install:
file.managed:
/usr/local/nginx/conf/nginx.conf:
file.managed:
- source: salt://nginx/files/nginx.conf
/etc/init.d/nginx:
file.managed:
- source: salt://nginx/files/nginx
- mode: 755
nginx:
service.running:
- reload: True
- watch:
- file: /usr/local/nginx/conf/nginx.conf
[root@server1 files]# ls
nginx nginx-1.14.0.tar.gz nginx.conf #将启动脚步和配置文件放到nginx中的files文件夹内
[root@server1 salt]# vim top.sls
base:
"server2":
- apache.service
"server3":
- nginx.service
[root@server1 salt]# salt ‘*‘ state.highstate
负载均衡haproxy
[root@server1 salt]# yum install salt-minion
[root@server1 salt]# vim /etc/salt/minion #修改master端口
[root@server1 salt]# /etc/init.d/salt-minion start
[root@server1 salt]# salt-key -a server1
[root@server1 salt]# mkdir haproxy
[root@server1 salt]# cd haproxy/
[root@server1 haproxy]# mkdir files
[root@server1 haproxy]# cd files/
[root@server1 files]# ls #包和配置文件拷贝过来
haproxy-1.6.11.tar.gz haproxy.cfg haproxy.init
[root@server1 haproxy]# vim install.sls
include:
- pkgs.make
haproxy-install:
file.managed:
- name: /mnt/haproxy-1.6.11.tar.gz
- source: salt://haproxy/files/haproxy-1.6.11.tar.gz
cmd.run:
- name: cd /mnt && tar zxf haproxy-1.6.11.tar.gz && cd haproxy-1.6.11 && make TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 PREFIX=/usr/local/haproxy &> /dev/null && make TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 PREFIX=/usr/local/haproxy install
- creates: /usr/local/haproxy
/etc/haproxy:
file.directory:
/usr/sbin/haproxy:
file.symlink:
- target: /usr/local/haproxy/sbin/haproxy
[root@server1 haproxy]# vim service.sls
include:
- haproxy.install
- users.haproxy
/etc/haproxy/haproxy.cfg:
file.managed:
- source: salt://haproxy/files/haproxy.cfg
haproxy-service:
file.managed:
- name: /etc/init.d/haproxy
- source: salt://haproxy/files/haproxy.init
- mode: 755
service.running:
- name: haproxy
- relpad: True
- watch:
- file: /etc/haproxy/haproxy.cfg
[root@server1 salt]# mkdir users
[root@server1 users]# vim haproxy.sls
haproxy-group:
group.present:
haproxy-user:
user.present:
- name: haproxy
- uid: 200
- gid: 200
- shell: /sbin/nologin
- home: /usr/local/haproxy
- createhome: False
[root@server1 salt]# vim top.sls
base:
"server1":
- apache
[root@server2 ~]# /etc/init.d/salt-minion restart
[root@server3 ~]# cd /etc/salt/
[root@server3 salt]# vim grains
roles: nginx
[root@server1 salt]# salt server2 grains.item roles
server2:
roles:
- apache
[root@server1 salt]# salt server3 grains.item roles
server3:
roles:
nginx
[root@server1 salt]# vim top.sls
base:
"server1":
- haproxy.service
"roles:apache":
- match: grain
- apache.service
"roles:nginx":
- match: grain
- nginx.service
[root@server1 salt]# salt ‘*‘ state.highstate
[root@server1 salt]# mkdir _grains
[root@server1 salt]# cd _grains/
[root@server1 _grains]# vim my_grains.py
#! /usr/bin/env python
def my_grains():
grains = {};
grains[‘hello‘] = ‘world‘
grains[‘salt‘] = ‘stack‘
return grains
[root@server1 _grains]# salt server2 saltutil.sync_grains
[root@server1 _grains]# salt server2 grains.item hello
server2:
hello:
world
[root@server1 salt]# cd /etc/salt
[root@server1 salt]# mkdir /srv/pillar/
[root@server1 pillar]# /etc/init.d/salt-master restart
[root@server1 pillar]# mkdir web
[root@server1 pillar]# cd web/
[root@server1 web]# ls
[root@server1 web]# vim install.sls
{% if grains[‘fqdn‘] == ‘server2‘ %}
webserver: httpd
{% elif grains[‘fqdn‘] == ‘server3‘%}
webserver: nginx
{% endif %}
[root@server1 web]# cd ..
[root@server1 pillar]# ls
web
[root@server1 pillar]# vim top.sls
base:
‘*‘:
saltstack 安装和基本配置使用
标签:eve pillar log make vpd web lag restart term
原文地址:http://blog.51cto.com/13810716/2312695