安裝腳本install_salt.sh:python
#!/bin/bash
####安裝第三方yum源
rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/i386/epel-release-6-8.noarch.rpm
###更新系統證書模塊和python到最新版本
yum upgrade ca-certificates --disablerepo=epel -y
yum update python -y
##服務端安裝
##yum install salt-master -y
##客戶端安裝
yum install salt-minion -y
##替換默認的master服務器IP
#sed -i 's/#master: salt/master: 10.100.60.52/g' /etc/salt/minion
#修改id號
#sed -i 's/#id:/id: LCB-P-wbs02-60.4/g' /etc/salt/minion
#/etc/init.d/salt-minion startlinux
使用的一些經常使用命令舉例:web
下發文件到制定機器(註釋,download_bag.sh放在salt的根目錄下,默認/srv/salt,,也可自行更改)
salt '*' cp.get_file salt://download_bag.sh /home/deployer/scripts/download_bag.sh
修改文件權限
salt '*' cmd.run 'cd /home/deployer/scripts; chown deployer:deployer *;chmod 755 *'shell
遠程執行本地腳本,返回日誌(配置詳情,salt-master服務器/srv/salt目錄)
示例:salt 'LCB-U-touch02-123' state.sls touch-webapp/download_bag
top.sls配置:
base:
'*':
- touch-webapp/download_bag.initbash
download_bag.init配置:vi /srv/salt/touch-webapp/download_bag/init.sls
shell_download:
cmd.script:
- source: salt://touch-webapp/download_bag/download_bag.sh
- mode: 755
- user: deployer
~服務器