salt

master

yum install chrony systemctl restart chronyd systemctl enable chronyd wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -ivh epel-release-latest-7.noarch.rpm yum repolist yum -y install salt-master systemctl stop firewalld #防火墙不关,salt-key -L时无法发现minion sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config #查找到SELINUX行,并替换enforcing setenforce 0 sed -i 's/#interface: 0.0.0.0/interface: 192.168.59.128/g' /etc/salt/master #指定master_ip sed -e '/^$/d; /^#/d' /etc/salt/master #查看是否指定好master_ip systemctl restart salt-master mkdir -p /etc/salt/master.d cat >> /etc/salt/master.d/nodegroup.conf << EOF nodegroups: test1: 'L@192.168.59.129' test2: 'L@192.168.59.129 EOF #yaml以两个空格为缩进,L@ 和G@ 分别表示minion和grain信息 sed -i 's/#default_include:/default_include:/g' /etc/salt/master salt-key -L salt-key -a saltstack-minion-name salt -N test1 test.ping #检测配置是否成功 salt -N test1 cmd.run 'sh touch /opt/1.txt' #创建文件 salt -N 'test1' cmd.run 'echo `date` >> /opt/1.txt' #执行命令 salt -N 'test1' cmd.run 'sed -i 's/Wed/Wednesday/g' /opt/1.txt' #查找替换,-i修改原文件 salt -N 'test1' cmd.run 'sed -e '/wednesday/p' /opt/1.txt' #查找并打印 salt -N 'test1' cmd.run 'sed -i 's/wednesday/#&/g' /opt/1.txt' #查找并在对应字符串前添加#号,&代表查找到的内容 history |grep sed salt -N 'test1' cmd.run "sed -i '/Wednesday/aNew_Wednesday/' /opt/1.txt" #在匹配行后添加一行 salt -N 'test1' cmd.run "sed -i '/Wednesday/iNew_Wednesday/' /opt/1.txt" #在匹配行前添加一行

minion
yum install chrony systemctl restart chronyd systemctl enable chronyd wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -ivh epel-release-latest-7.noarch.rpm yum repolist yum -y install salt-minion systemctl stop firewalld sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config setenforce 0 sed -i 's/#master: salt/master: 192.168.59.128/g' /etc/salt/minion #指定master_ip sed -e '/^$/d; /^#/d' /etc/salt/minion #查看是否指定好master_ip systemctl restart salt-minion

修改minion id minion
#systemctl stop salt-minion #vi /etc/salt/minion id:xxxx #rm -rf /etc/salt/pki #rm -rf /etc/salt/minion_id #systemctl start salt-minion

master
#salt-key -d "id名称" -y #salt-key -a "id名称" -y

    推荐阅读