1.编写Salt执行模块
###salt执行模块路径 [root@linux-node1 ~]# cd /usr/lib/python2.7/site-packages/salt/modules 名称是固定的如需要写一个disk的模块就是disk.py自己编写的模块名称不能跟系统冲突 ###编写的路径file_roots,master文件 [root@linux-node1 ~]# cd /srv/salt/base/ ###创建目录名称固定的 [root@linux-node1 /srv/salt/base]# mkdir _modules ###把自定义的模块写到modules下 [root@linux-node1 /srv/salt/base/_modules]# vim my_disk.py def list(): cmd='df -h' ret=__salt__['cmd.run'](cmd) return ret ###同步到所有minion下面 [root@linux-node1 /srv/salt/base/_modules]# salt '*' saltutil.sync_modules linux-node2.example.com: - modules.my_disk linux-node1.example.com: - modules.my_disk ###同步过去存放的路径 [root@linux-node1 /srv/salt/base/_modules]# cd /var/cache/salt/minion/extmods/modules/ [root@linux-node1 /var/cache/salt/minion/extmods/modules]# ls my_disk.py ####执行模块 [root@linux-node1 ~]# salt '*' my_disk.list linux-node2.example.com: Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 48G 1.7G 46G 4% / devtmpfs 903M 0 903M 0% /dev tmpfs 913M 12K 913M 1% /dev/shm tmpfs 913M 8.7M 904M 1% /run tmpfs 913M 0 913M 0% /sys/fs/cgroup /dev/sda1 497M 125M 373M 25% /boot linux-node1.example.com: Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 48G 1.7G 46G 4% / devtmpfs 903M 0 903M 0% /dev tmpfs 913M 16K 913M 1% /dev/shm tmpfs 913M 17M 896M 2% /run tmpfs 913M 0 913M 0% /sys/fs/cgroup /dev/sda1 497M 125M 373M 25% /boot tmpfs 183M 0 183M 0% /run/user/0
2.syndic分布式架构
###node2做master,node1安装syndic [root@linux-node1 ~]# yum install -y salt-syndic [root@linux-node2 ~]# yum install -y salt-master ###node1上配置syndic告诉master是node2 [root@linux-node1 ~]# vim /etc/salt/master syndic_master: 118.190.201.12 ###重启服务 [root@linux-node1 ~]# systemctl restart salt-master.service [root@linux-node1 ~]# systemctl start salt-syndic.service ###node2作为高级master也需要配置 [root@linux-node2 ~]# vim /etc/salt/master order_masters: True ##它下面可以有master ###重启服务 [root@linux-node2 ~]# systemctl start salt-master.service ###node2上执行salt-key [root@linux-node2 ~]# salt-key Accepted Keys: Denied Keys: Unaccepted Keys: linux-node1.example.com node2的minion Rejected Keys: ###确认key值 [root@linux-node2 ~]# salt-key -A The following keys are going to be accepted: Unaccepted Keys: linux-node1.example.com Proceed? [n/Y] y Key for minion linux-node1.example.com accepted. #同意之后 [root@linux-node2 ~]# salt-key Accepted Keys: linux-node1.example.com Denied Keys: Unaccepted Keys: Rejected Keys: ###执行命令 [root@linux-node2 ~]# salt '*' test.ping ##显示的是node1上的master结果 linux-node1.example.com: True linux-node2.example.com: True
如无特殊说明,文章均为本站原创,转载请注明出处
- 转载请注明来源:Saltstack执行模块二次开发及syndic分布式架构
- 本文永久链接地址:https://www.xionghaier.cn/archives/921.html