Saltstack Quest-Install VIM, Nginx Service and configuration, custom scripts

Source: Internet
Author: User
Tags saltstack

Saltstack Quest-Install VIM, Nginx Service and configuration, custom scripts

1.  configuration Minion First, remove the original test minion[[email protected] bin]# salt-key -d test230the  following keys are going to be deleted:accepted keys:test230proceed? [ n/y] ykey for minion test230 deleted. New minion: "Svr205-2" [[email protected]  ~]# yum install salt-minion -y[[email protected] ~]# vim /etc/salt/ Minionmaster: 10.0.200.21id: svr205-2[[email protected] ~]# service salt-minion  startStarting salt-minion daemon:                                 [  ok  ] "svr205-2, 3, 4, 5 similar" ibid. 2.  Configuring key[[email protected] bin]# salt-key -laccepted keys:unaccepted  for Master and Minion keys:svr205-2svr205-3svr205-4svr205-5rejected keys:[[email protected] bin]# salt-key -a svr205*the following  keys are going to be accepted:unaccepted keys: svr205-2svr205-3svr205-4svr205-5proceed? [n/y] ykey for minion svr205-2 accepted . Key for minion svr205-3 accepted. [[Email protected] bin]# salt-key -laccepted keys: Svr205-2svr205-3svr205-4svr205-5unaccepted keys:rejected keys: Test: [[email protected] salt]#  salt  ' svr205-* '  test.pingsvr205-3:    Truesvr205-2:     Truesvr205-5:    Truesvr205-4:    True3.  Configuration Management-Synchronize Vim configuration [[ email protected] salt]# pwd/srv/salt[[email protected] salt]# cat edit/ vim.sls vim-enhanced:    pkg.installed: []/root/.vimrc:     File.managed:        - source: salt://edit/conf/vimrc         - mode: 644        - uesr: root         - group: root[[email protected] salt]# ls  edit/conf/vimrc[[email protected] salt]# salt  ' svr205-* '  state.sls edit.vim##### #################################################################### #略 ######################################### ################################ #4 .  Remote execution-Execute script lvs-realsvr on 4 hosts and join the boot boot. startup script: [[EMAIL&NBSP;PROTECTED]&NBSP;SALT]#&NBSP;CAT&NBSP;LVS/REAL/START.SLS&NBSP;/ETC/RC.D/INIT.D/LVS-REALSVR:   file.managed:    - source: salt://lvs/bin/lvs-realsvr.sh     - mode: 755lvs-realsvr:  cmd.run:    - require:       - file: /etc/rc.d/init.d/lvs-realsvr    - name: service lvs-realsvr start  && chkconfig lvs-realsvr on Close script: [[Email protected] salt]# cat  lvs/real/stop.sls /etc/rc.d/init.d/lvs-realsvr:  file.managed:    - &NBSP;SOURCE:&NBSP;SALT://LVS/BIN/LVS-REALSVR.SH&NBSP;&NBSP;&NBSP;&NBSP;-&NBSP;MODE:&NBSP;755LVS-REALSVR:   cmd.run:    - require:      - file:  /etc/rc.d/init.d/lvs-realsvr    - name: service lvs-realsvr stop  && chkconfig lvs-realsvr off control script: [[Email protected] salt]# cat  lvs/bin/lvs-realsvr.sh #!/bin/bash# # 2015/2/28# lvs real server##  Chkconfig:   - 85 15# description:  control vip on lvs  realserver # source&nBsp;function library.  /etc/rc.d/init.d/functions# source networking configuration.  /etc/sysconfig/network# check that networking is up. [  "$NETWORKING"  =  "no"  ] && exit 0lockfile= "/var/lock/subsys/ Lvs-real "  s_vip= ' 10.0.205.100 ' Start ()  {  ifconfig lo:1 ${s_vip}  NETMASK&NBSP;255.255.255.255&NBSP;BROADCAST&NBSP;${S_VIP}&NBSP;&NBSP;ROUTE&NBSP;ADD&NBSP;-HOST&NBSP;${S_VIP}  dev lo:1  echo 1 >/proc/sys/net/ipv4/conf/lo/arp_ignore  echo  2 >/proc/sys/net/ipv4/conf/lo/arp_announce  echo 1 >/proc/sys/net/ipv4/ Conf/all/arp_ignore  echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce  retval =$?  echo  [  $retval  -eq 0 ] && touch  $lockfile   return  $retval}stop ()  {  echo 0 >/proc/sys/net/ipv4/conf/lo/arp_ignore  echo 0 >/proc/sys/net/ipv4/ Conf/lo/arp_announce  echo 0 >/proc/sys/net/ipv4/conf/all/arp_ignore  echo  0 >/proc/sys/net/ipv4/conf/all/arp_announce  ifconfig lo:1 down   route del -host ${s_vip}  retval=$?  echo  [  $retval  - eq 0 ] && rm -f  $lockfile   return  $retval}status ()  {   ip a |grep inet |grep -v inet6  }case $1 in     start)     start    status     ;;   stop)     stop    status    ;;   status)     status    ;;   *)       echo $ "Usage: $0 {start|stop|status}"     exit 2 esac          execute:[[email protected] salt]# salt  ' svr205-* '  state.sls  lvs.real.start######################################################################### #略 ############### ########################################################## #查看minion的状态: "Svr205-2" [[email protected]  ~]# ll /etc/init.d/lvs-realsvr -rwxr-xr-x 1 root root 1252 feb 28  05:31 /etc/init.d/lvs-realsvr[[email protected] ~]# ip a |grep inet  |grep -v inet6    inet 127.0.0.1/8 scope host lo     inet 10.0.205.100/32 brd 10.0.205.100 scope global lo:1     inet 10.0.205.2/8 brd 10.255.255.255 scope global eth0     [[email protected] salt]# salt  ' svr205-* '  state.sls lvs.real.stop################## ####################################################### #略 ###################################################### ################### #查看minion的状态: "Svr205-2" [[Email protected] ~]# ip a |grep inet  |grep -v inet6    inet 127.0.0.1/8 scope host lo     inet 10.0.205.2/8 brd 10.255.255.255 scope global eth0    5.  Configuration Management-install Nginx service and join the boot. [[email protected] salt]# cat nginx/init.sls nginx:  pkg.installed: []   service.running:    - require:      -  pkg: nginx  cmd.run:    - require:       - pkg: nginx    - name: chkconfig nginx on[[email protected] salt]# salt  ' svr205-* '  state.sls ############## ########################################################### #略 ################################################## ####################### #深入一步, use template to deploy customized index.html, update Nginx homepage, display hostname and IP information of current web host. [[email protected] salt]# cat nginx/init.sls nginx:  pkg.installed: []   service.running:    - watch:      -  file: /usr/share/nginx/html/index.html    - require:       - pkg: nginx  cmd.run:    - require:       - pkg: nginx    - name: chkconfig nginx  on/usr/share/nginx/html/index.html:  file.managed:    - source:  Salt://nginx/conf/index.html    - template: jinja[[email protected] salt]# cat nginx/conf/index.html  <p>  host:   {{ grains[' HOST '] }} <br />   <br /><br />{% for k,v in grains.get (' ip4_interfaces '). Items ()   %}  {{ k }}: {{ v.pop ()  }} <br />{% endfor %}< /p>[[email protected] salt]# salt  ' svr205-* '  state.sls nginx################# ######################################################## #略 ##################################################### #################### #查看文件是否有改变: "Svr205-2" [[email protected] ~]# cat /usr/share/nginx/html/ Index.html <p>  host:   svr205-2 <br />  <br  /><br />  lo: 10.0.205.100 <br />  eth0:  10.0.205.2 <br /></p> as above, get the hostname and IP information of the host, and meet the expectations. 


Saltstack Quest-Install VIM, Nginx Service and configuration, custom scripts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.