1.Salt Masterless快速入门
- Stand up a master server via States (Salting a Salt Master) 用来配置一个master 如yum install xxx
- Use salt-call commands on a system without connectivity to a master 本地使用salt管理 不用master也能跑
- Masterless States, run states entirely from files local to the minion 完全从本地运行一个状态
2.没有mster配置
[root@linux-node2 ~]# vim /etc/salt/minion
#master: 118.190.201.11
file_client: local
file_roots:
base:
- /srv/salt/
pillar_roots:
base:
- /srv/pillar
3.不需要salt-minion服务
[root@linux-node2 ~]# systemctl stop salt-minion.service
4.执行状态
[root@linux-node2 ~]# salt-call --local cmd.run 'uptime'
[INFO ] Executing command 'uptime' in directory '/root'
local:
02:01:19 up 5 days, 13:49, 1 user, load average: 0.09, 0.03, 0.05
[root@linux-node2 ~]# mkdir /srv/salt/
[root@linux-node2 ~]# cd /srv/salt/
[root@linux-node2 ~]# vim /srv/salt/demo.sls
pkg-install:
pkg.installed:
- pkgs:
- wget
- screen
- nmap
5.执行结果
[root@linux-node2 ~]# salt-call --local state.sls demo
[INFO ] Loading fresh modules for state activity
[INFO ] Fetching file from saltenv 'base', ** done ** 'demo.sls'
[INFO ] Running state [pkg-install] at time 02:09:36.864720
[INFO ] Executing state pkg.installed for pkg-install
[INFO ] Executing command ['rpm', '-qa', '--queryformat', '%{NAME}_|-%{EPOCH}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-(none)\n'] in directory '/root'
[INFO ] All specified packages are already installed.
[INFO ] Completed state [pkg-install] at time 02:09:39.642429
local:
----------
ID: pkg-install
Function: pkg.installed
Result: True
Comment: All specified packages are already installed.
Started: 02:09:36.864720
Duration: 2777.709 ms
Changes:
Summary
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
6.top_file文件
[root@linux-node2 ~]# vim /srv/salt/top.sls
base:
'*':
- demo
[root@linux-node2 ~]# salt-call --local state.highstate
[INFO ] Loading fresh modules for state activity
[INFO ] Fetching file from saltenv 'base', ** done ** 'top.sls'
[INFO ] Creating module dir '/var/cache/salt/minion/extmods/beacons'
[INFO ] Syncing beacons for environment 'base'
[INFO ] Loading cache from salt://_beacons, for base)
[INFO ] Caching directory '_beacons/' for environment 'base'
[INFO ] Creating module dir '/var/cache/salt/minion/extmods/modules'
[INFO ] Syncing modules for environment 'base'
[INFO ] Loading cache from salt://_modules, for base)
[INFO ] Caching directory '_modules/' for environment 'base'
[INFO ] Creating module dir '/var/cache/salt/minion/extmods/states'
[INFO ] Syncing states for environment 'base'
[INFO ] Loading cache from salt://_states, for base)
[INFO ] Caching directory '_states/' for environment 'base'
[INFO ] Creating module dir '/var/cache/salt/minion/extmods/sdb'
[INFO ] Syncing sdb for environment 'base'
[INFO ] Loading cache from salt://_sdb, for base)
[INFO ] Caching directory '_sdb/' for environment 'base'
[INFO ] Creating module dir '/var/cache/salt/minion/extmods/grains'
[INFO ] Syncing grains for environment 'base'
[INFO ] Loading cache from salt://_grains, for base)
[INFO ] Caching directory '_grains/' for environment 'base'
[INFO ] Creating module dir '/var/cache/salt/minion/extmods/renderers'
[INFO ] Syncing renderers for environment 'base'
[INFO ] Loading cache from salt://_renderers, for base)
[INFO ] Caching directory '_renderers/' for environment 'base'
[INFO ] Creating module dir '/var/cache/salt/minion/extmods/returners'
[INFO ] Syncing returners for environment 'base'
[INFO ] Loading cache from salt://_returners, for base)
[INFO ] Caching directory '_returners/' for environment 'base'
[INFO ] Creating module dir '/var/cache/salt/minion/extmods/output'
[INFO ] Syncing output for environment 'base'
[INFO ] Loading cache from salt://_output, for base)
[INFO ] Caching directory '_output/' for environment 'base'
[INFO ] Creating module dir '/var/cache/salt/minion/extmods/utils'
[INFO ] Syncing utils for environment 'base'
[INFO ] Loading cache from salt://_utils, for base)
[INFO ] Caching directory '_utils/' for environment 'base'
[INFO ] Loading fresh modules for state activity
[INFO ] Fetching file from saltenv 'base', ** skipped ** latest already in cache 'salt://demo.sls'
[INFO ] Running state [pkg-install] at time 02:15:37.831641
[INFO ] Executing state pkg.installed for pkg-install
[INFO ] Executing command ['rpm', '-qa', '--queryformat', '%{NAME}_|-%{EPOCH}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-(none)\n'] in directory '/root'
[INFO ] All specified packages are already installed.
[INFO ] Completed state [pkg-install] at time 02:15:40.548441
local:
----------
ID: pkg-install
Function: pkg.installed
Result: True
Comment: All specified packages are already installed.
Started: 02:15:37.831641
Duration: 2716.8 ms
Changes:
Summary
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
7.Master高可用架构
官方文档:https://docs.saltstack.com/en/latest/topics/tutorials/multimaster.html
[root@linux-node2 ~]# yum install -y salt-master .......省略部分....... Running transaction Installing : salt-master-2015.5.10-2.el7.noarch 1/1 Verifying : salt-master-2015.5.10-2.el7.noarch 1/1 Installed: salt-master.noarch 0:2015.5.10-2.el7 Complete! ####node2节点minion配置 [root@linux-node2 ~]# hostname -I 118.190.201.12 [root@linux-node2 ~]# vim /etc/salt/minion master: - 118.190.201.11 - 118.190.201.12 ###master配置需要统一 [root@linux-node1 ~]# scp -P 22 /etc/salt/master 118.190.201.12:/etc/salt/ ###master,minion的key必须是一样的 [root@linux-node1 ~]# cd /etc/salt/pki/ ###file_roots与file_pillar需要一致 [root@linux-node1 /etc/salt/pki]# cd /srv/pillar/ ###使用nfs进行挂载 [root@linux-node1 ~]# yum install -y nfs-utils rpcbind [root@linux-node1 ~]# rpm -qa nfs-utils rpcbind rpcbind-0.2.0-44.el7.x86_64 nfs-utils-1.3.0-0.54.el7.x86_64 ####启动rpcbind服务 [root@linux-node1 ~]# systemctl start rpcbind.service [root@linux-node1 ~]# systemctl start nfs.service [root@linux-node1 ~]# systemctl enable rpcbind.service [root@linux-node1 ~]# systemctl enable nfs.service ####挂载 [root@linux-node1 ~]# vim /etc/exports /etc/salt/pki 118.190.201.0/24(rw,sync) /srv/pillar 118.190.201.0/24(rw,sync) ####平滑重启 [root@linux-node1 ~]# systemctl reload nfs [root@linux-node1 ~]# showmount -e localhost Export list for localhost: /srv/pillar 118.190.201.0/24 /etc/salt/pki 118.190.201.0/24 ###本地测试 [root@linux-node1 ~]# mount -t nfs 118.190.201.11:/srv/pillar /mnt [root@linux-node1 ~]# cd /mnt/ [root@linux-node1 /mnt]# ll total 0 drwxr-xr-x 2 root root 54 Oct 23 2017 base drwxr-xr-x 2 root root 6 Oct 19 01:47 prod ###node2节点操作 mkdir /srv/pillar yum install -y rpcbind systemctl start rpcbind yum install -y nfs-utils systemctl start nfs mount -t nfs 118.190.201.11:/srv/pillar /srv/pillar mount -t nfs 118.190.201.11:/etc/salt/pki /etc/salt/pki
如无特殊说明,文章均为本站原创,转载请注明出处
- 转载请注明来源:Saltstack之Masterless及Master高可用架构
- 本文永久链接地址:https://www.xionghaier.cn/archives/920.html
该文章由 John 发布
这货来去如风,什么鬼都没留下!!!

