Simple deployment and practice of saltstack, and saltstack deployment
# Elasticity: master; Dylan: minion
# Use salt to install the minion installation package
[Root @ Eline states] # vim/etc/salt/master
1 default_include: master.d/*.conf 2 3 interface: 0.0.0.0 4 5 ''' 6 state_top: top.sls 7 ''' 8 file_roots: 9 base:10 - /etc/salt/states11 prod:12 - /etc/salt/states/prod13 '''
View Code
[Root @ Eline states] # vim/etc/salt/states/top. sls
1 base: 2 'dylan': 3-init. pkg # Use the pkg file 4 5 pkg In the init directory. init: # custom name 6 pkg. installed: # Run pkg. installed Module 7-names: # Name of the package to be installed 8-lrzsz 9-mtr10-nmap
View Code
[Root @ Eline init] # salt '*' state. sls init. pkg
dylan:---------- ID: pkg.init Function: pkg.installed Result: True Comment: All specified packages are already installed Started: 14:21:07.973412 Duration: 4582.543 ms Changes: Summary for dylan------------Succeeded: 1Failed: 0------------Total states run: 1Total run time: 4.583 s
# Use salt to synchronize minion configuration files
[Root @ Eline init] # vim/etc/salt/states/init/limit. sls
1/etc/security/limits. conf: # target file name to be synchronized 2 file. managed: 3-source: salt: // init/files/limits. conf 4-user: root 5-group: root 6-mode: 644 7 # Or 8 limit-config: # id name 9 file. managed: 10-name:/etc/security/limits. conf # target file name to be synchronized 11-source: salt: // init/files/limits. conf12-user: root13-group: root14-model: 644
View Code
[Root @ Eline init] # cp/etc/security/limits. conf/etc/salt/states/init/files/
[Root @ Eline states] # vim/etc/salt/states/top. sls
1 base:2 'dylan':3 - init.pkg4 - init.limit
View Code
# Return the output result to mysql
Install the MySQL-python package on the master end, and write the package directly to mysql on the master end. -- return mysql is not required.
# Use grains to define a target
[Root @ dylan ~] # Vim/etc/salt/grains
test: salt_test
[Root @ elaine ~] # Salt '*' saltutil. sync_grains # refresh
dylan:
[Root @ elaine/] # salt '*' grains. item test
dylan: ---------- test: salt_test
[Root @ elaine ~] # Salt-g'test: salt_test 'test. ping
dylan: True
# Grains in the top. sls Status File
[Root @ Eline/] # vim/etc/salt/states/top. sls
1 base:2 'dylan':3 - init.pkg4 'os:CentOS':5 - match: grain6 - init.limit
View Code
# Define a target using pillar
[Root @ elaine/] # mkdir-p/etc/salt/pillar/init
[Root @ Eline init] # vim/etc/salt/master
1 pillar_roots:2 base:3 - /etc/salt/pillar
[Root @ elaine/] # vim/etc/salt/pillar/top. sls
1 base: 2 '*': # define the target host to add pillar 3-init. rsyslog # define the method file/etc/salt/pillar/init to add pillar
[Root @ Eline/] # vim/etc/salt/pillar/init/rsyslog. sls
1 {% if grains['osfinger'] == 'CentOS Linux-7' %}2 syslog: rsyslog3 {% elif grains['osfinger'] == 'CentOS-5' %}4 syslog: syslog5 {% endif %}
[Root @ elaine init] # systemctl restart salt-master
[Root @ elaine init] # salt '*' saltutil. refresh_pillar
dylan: True
[Root @ eleine init] # salt '* 'pillar. item syslog
dylan: ---------- syslog: rsyslog
[Root @ elaine init] #
[Root @ Eline init] # salt-I 'syslog: rsyslog 'test. ping
dylan: True
# Install and configure zabbix-agent
[Root @ Eline init] # grep 'server = '/etc/salt/states/init/files/zabbix_agentd.conf
# Server = {Zabbix_Server} # Add the parameter to be modified in the configuration file to the variable Zabbix_Server. The configuration file is changed to the template file.
[Root @ Eline init] # vim/etc/salt/states/init/zabbix_agent.sls
1 zabbix_agent: 2 pkg. installed: # Install zabbix-agent 3-name: zabbix-agent.x86_64 4 5 file. managed: # configure zabbix-agent 6-name:/etc/zabbix/zabbix_agentd.conf 7-source: salt: // init/files/zabbix_agentd.conf 8-user: root 9-group: root10-mode: 64411-template: jinja # declare the template format 12-defaults: 13 Zabbix_Server: {pillar ['zabbix-agent'] ['zabbix _ Server']} # assign a new value to the variable Zabbix_Server (here, You can directly add a value using pillar, for example, Zabbix_Server: 192.168.35.129) 14 15 service. running: # Start zabbix-agent16-name: zabbix-agent17-enable: True18 #-reload: True # reload service 19-watch: # Restart service 20-file: zabbix_agent after file change
[Root @ Eline init] # vim/etc/salt/states/top. sls
1 base: 2 'dylan': 3-init. pkg4-init. zabbix_agent # In top. sls adds the method file zabbix_agent.sls5 'OS: CentOS': 6-match: grain7-init. limit
# Define pillar
[Root @ eleine init] # cat/etc/salt/pillar/init/zabbix_agent.sls
zabbix-agent: Zabbix_Server: 198.162.35.129
[Root @ elaine pillar] # cat/etc/salt/pillar/top. sls
base: '*': - init.rsyslog - init.zabbix_agent
# Salt. ssh
[Root @ Eline init] # vim/etc/salt/roster
1 squid:2 host: 172.16.139.883 user: root4 passwd: Ch@n93M3?
[Root @ Eline init] # salt-ssh-I '*' test. ping
squid: True
[Root @ Eline init] # salt-ssh-I '* 'cmd. run' service squid restart'
Squid: Stop squid:... [OK] Starting squid:. [OK]