About a .saltstack
1.saltstack profile:
Saltstack is a Python-based development of a C / S architecture, with Puppet, Ansible-in-one configuration management tool, it is very powerful, and reusability of each module incorporates high; the use of message queues ZeroMQ known as the fastest in the world Saltstack that can be performed on a second level of tens of thousands of servers of various operations, and RAS Key used to confirm the identity embodiment, transmission using AES encryption, higher safety performance;
Saltstack just a configuration management tools, or to make a cloud and data center infrastructure orchestration tool. Currently Salt-cloud projects have been incorporated into the main project in Saltstack, Saltstack has supported Docker related modules, after the friendly support of major cloud platform, with Saltstack of Mine achievement of the cloud platform services automatically extended.
2. Communication port:
- master end: 4505
- minion end: 4506
salt of master listens on port 4505 and 4506,4505 salt is used to publish information; 4506 is used to monitor salt client-side port to communicate with the service return data. minion end not listen port, after the minion start automatically registers connected to the master through, stays connected after the adoption.
3. Main features:
- A configuration management system, capable of maintaining a predefined remote node status (for example, to ensure that the specified report to be installed, the specified service running)
- Remote execution of a distributed system for the remote node (which may be a single node, the rules may be any chosen node) query data and execute commands on
II. Experiments
1. Deploy experimental environment
server1:
yum install salt-master -y ##这里已经配好了yum源(包含所有依赖关系)
server2:
yum insall -y salt-minion
server3:
yum install -y salt-minion
2. Open the salt-master
[root@server1 salt]# systemctl start salt-master
[root@server1 salt]# netstat -antlp
3. Configure server2, server3 the salt-minion
[root@server2 ~]# cd /etc/salt/
[root@server2 salt]# ls
cloud cloud.maps.d master minion.d proxy.d
cloud.conf.d cloud.profiles.d master.d pki roster
cloud.deploy.d cloud.providers.d minion proxy
[root@server2 salt]# vim minion
16 master: 172.25.31.1
[root@server2 salt]# systemctl start salt-minion
The same operation server3
3. server2, server3 added
[root@server1 salt]# salt-key -L ##-L列出所有
[root@server1 salt]# salt-key -A ##加入
4. Check the port-specific information
[root@server1 salt]# yum install -y lsof
[root@server1 salt]# lsof -i :4505
[root@server1 salt]# vim master
[root@server1 salt]# systemctl restart salt-master
Two .saltstack applications
1. Installation server2 httpd
[root@server1 apache]# pwd
/srv/salt/apache
[root@server1 apache]# ls
apache.sls files install.sls
[root@server1 apache]# cat install.sls
install-apache:
pkg.installed:
- pkgs:
- httpd
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://apache/files/httpd.conf
service.running:
- name: httpd
- reload: True
- watch:
- file: install-apache
[root@server1 apache]# cd files/
[root@server1 files]# ls
httpd.conf
[root@server1 apache]# salt server2 state.sls apache.install
[root@server2 minion]# tree .
.
├── accumulator
├── extmods
├── files
│ └── base
│ ├── apache
│ │ ├── files
│ │ │ └── httpd.conf
│ │ └── install.sls
│ └── nginx
│ └── install.sls
├── highstate.cache.p
├── pkg_refresh
├── proc
└── sls.p
8 directories, 6 files
Install all
[root@server1 apache]# cat apache.sls
install-apache:
pkg.installed:
- pkgs:
- httpd
/etc/httpd/conf/httpd.conf
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://apache/files/httpd.conf
service.running:
- name: httpd
- watch:
- file: /etc/httpd/conf/httpd.conf
[root@server1 salt]# cat top.sls
base:
'*':
- apache.install
[root@server1 salt]# salt '*' state.highstate
server2:
----------
ID: install-apache
Function: pkg.installed
Result: True
Comment: All specified packages are already installed
Started: 11:47:42.671750
Duration: 679.907 ms
Changes:
----------
ID: install-apache
Function: file.managed
Name: /etc/httpd/conf/httpd.conf
Result: True
Comment: File /etc/httpd/conf/httpd.conf is in the correct state
Started: 11:47:43.354708
Duration: 27.683 ms
Changes:
----------
ID: install-apache
Function: service.running
Name: httpd
Result: True
Comment: Started Service httpd
Started: 11:47:43.383628
Duration: 122.231 ms
Changes:
----------
httpd:
True
Summary for server2
------------
Succeeded: 3 (changed=1)
Failed: 0
------------
Total states run: 3
Total run time: 829.821 ms
server3:
----------
ID: install-apache
Function: pkg.installed
Result: True
Comment: All specified packages are already installed
Started: 11:47:42.600298
Duration: 663.636 ms
Changes:
----------
ID: install-apache
Function: file.managed
Name: /etc/httpd/conf/httpd.conf
Result: True
Comment: File /etc/httpd/conf/httpd.conf is in the correct state
Started: 11:47:43.266732
Duration: 34.541 ms
Changes:
----------
ID: install-apache
Function: service.running
Name: httpd
Result: True
Comment: Started Service httpd
Started: 11:47:43.302496
Duration: 171.214 ms
Changes:
----------
httpd:
True
Summary for server3
------------
Succeeded: 3 (changed=1)
Failed: 0
------------
Total states run: 3
Total run time: 869.391 ms
2. server2 install nginx
[root@server1 salt]# ls
apache nginx pkgs top.sls
[root@server1 salt]# cd nginx/
[root@server1 nginx]# ls
files install.sls service.sls
[root@server1 salt]# cat pkgs/install.sls
nginx-make:
pkg.installed:
- pkgs:
- gcc
- make
- zlib-devel
- pcre-devel
[root@server1 nginx]# cat install.sls
include:
- pkgs.install
install-nginx:
file.managed:
- name: /mnt/nginx-1.15.8.tar.gz
- source: salt://nginx/files/nginx-1.15.8.tar.gz
cmd.run:
- name: cd /mnt && tar zxf nginx-1.15.8.tar.gz && cd nginx-1.15.8 && sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && ./configure --prefix=/usr/local/nginx && make && make install
- creates: /usr/local/nginx
[root@server1 nginx]# cd files/
[root@server1 files]# ls
nginx-1.15.8.tar.gz nginx.conf
[root@server1 files]# cd ..
[root@server1 nginx]# ls
files install.sls service.sls
[root@server1 nginx]# cat service.sls
include:
- nginx.install
/usr/local/nginx/sbin/nginx: ##命令方式启动
cmd.run:
- creates: /usr/local/nginx/logs/nginx.pid
/usr/local/nginx/conf/nginx.conf:
file.managed:
- source: salt://nginx/files/nginx.conf
/usr/local/nginx/sbin/nginx -s reload:
cmd.wait:
- watch:
- file: /usr/local/nginx/conf/nginx.conf
[root@server1 nginx]# salt server2 state.sls nginx.install
[root@server1 salt]# cd /var/cache/salt/
[root@server1 salt]# ls
master
[root@server1 salt]# cd master/
[root@server1 master]# ls
file_lists jobs minions proc queues roots syndics tokens
[root@server1 master]# cd jobs/
[root@server1 jobs]# ls ##这里包含缓存文件
0b 0f 16 1f 39 5b 5e 61 88 89 a1 a6 b6 c0 c2 c3 c4 d0 f0
Turn off nginx process server3 way to start the command
[root@server1 salt]# ls
apache nginx pkgs top.sls
[root@server1 salt]# cd nginx/
[root@server1 nginx]# ls
files install.sls service.sls
[root@server1 nginx]# cat install.sls
include:
- pkgs.install
install-nginx:
file.managed:
- name: /mnt/nginx-1.15.8.tar.gz
- source: salt://nginx/files/nginx-1.15.8.tar.gz
cmd.run:
- name: cd /mnt && tar zxf nginx-1.15.8.tar.gz && cd nginx-1.15.8 && sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && ./configure --prefix=/usr/local/nginx && make && make install
- creates: /usr/local/nginx
[root@server1 nginx]# cat service.sls
include:
- nginx.install
/usr/local/nginx/conf/nginx.conf:
file.managed:
- source: salt://nginx/files/nginx.conf
service-nginx
file.managed:
- name: /usr/lib/systemd/system/nginx.service ##以systemd方式启动
- source: salt://nginx/files/nginx.service
service.running:
- name: nginx
- reload: True
- watch:
- file: /usr/local/nginx/conf/nginx.conf
[root@server1 nginx]# cd files/
[root@server1 files]# ls
nginx-1.15.8.tar.gz nginx.conf nginx.service
[root@server1 files]# cat nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@server1 files]# cd ../..
[root@server1 salt]# ls
apache nginx pkgs top.sls
[root@server1 nginx]# salt '*' state.highstate