一、Saltstack环境准备
第一台:linux-node1,既作为salt-master,又作为salt-minion
[root@linux-node1 ~]# cat /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain610.0.0.7 linux-node110.0.0.8 linux-node2[root@linux-node1 ~]# cat /etc/redhat-releaseCentOS release 6.7 (Final)[root@linux-node1 ~]# uname -mx86_64[root@linux-node1 ~]# uname -r2.6.32-573.el6.x86_64[root@linux-node1 ~]# uname -aLinux linux-node1 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
第二台:linux-node2,只作为salt-minion
[root@linux-node2 ~]# uname -r2.6.32-573.el6.x86_64[root@linux-node2 ~]# uname -mx86_64[root@linux-node2 ~]# uname -aLinux linux-node2 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux[root@linux-node2 ~]# cat /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain610.0.0.7 linux-node110.0.0.8 linux-node2
二、Saltstack介绍
2.1 Salt三用运行方式
- local本地运行
- Master/Minion
- Salt ssh
2.2 Salt的三大功能
- 远程执行
- 配置管理(状态管理)
- 云管理:阿里云,aws,openstack都提供了封装好的接口,可以使用salt-cloud进行云主机的管理
三、Salt安装配置启动
此处使用yum安装,生产也建议使用yum安装,minion在装操作系统的时候就装上,也可以使用salt ssh安装minion,后续会提到
- linux-node1
[root@linux-node1 ~]#rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm[root@linux-node1 ~]#yum install -y salt-master salt-minion[root@linux-node1 ~]# chkconfig salt-master on[root@linux-node1 ~]# chkconfig salt-minion on
- linux-node2
[root@linux-node2 ~]#rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm[root@linux-node2 ~]#yum install -y salt-minion[root@linux-node1 ~]# chkconfig salt-minion on
启动salt
[root@linux-node1 ~]# /etc/init.d/salt-master startStarting salt-master daemon: [确定]
修改两个salt-minion的配置文件,指出salt-master的主机,这里可以使用ip地址,如果有内部dns也可以使用主机名,使用主机名方便以后salt-master的迁移
[root@linux-node1 ~]#sed -i '16s#\#master: salt#master: 10.0.0.7#g' /etc/salt/minion[root@linux-node2 ~]#sed -i '16s#\#master: salt#master: 10.0.0.7#g' /etc/salt/minion
注意:下面配置文件中的id十分重要,在生产上可以用来配置主机名,后面会有主机面的配置策略,如果不进行配置此id,将默认使用fqdn
[root@linux-node1 ~]# sed -n '68,74p' /etc/salt/minion# Explicitly declare the id for this minion to use, if left commented the id# will be the hostname as returned by the python call: socket.getfqdn()# Since salt uses detached ids it is possible to run multiple minions on the# same machine but with different ids, this can be useful for salt compute# clusters.#id:
启动salt-master和salt-minion
[root@linux-node1 ~]# /etc/init.d/salt-master start[root@linux-node1 ~]# /etc/init.d/salt-minion start
四、Saltstack的认证
minion首次启动后会在minion端看到minion的私钥和公钥,salt会把公钥发送给master
[root@linux-node2 minion]# pwd/etc/salt/pki/minion[root@linux-node2 minion]# lsminion.pem minion.pub
master启动后也会生成key,此时master需要统一minion的请求
[root@linux-node1 master]# pwd/etc/salt/pki/master[root@linux-node1 master]# lsmaster.pem master.pub minions minions_autosign minions_denied minions_pre minions_rejected
使用salt-key查看各种状态的key
[root@linux-node1 pki]# salt-keyAccepted Keys:Denied Keys:Unaccepted Keys:linux-node1linux-node2Rejected Keys:
接受两个新的key,这里使用-A接受所有,也可使用-a指定某个minion,也可使用通配符匹配。具体salt-key的指令参数,请看salt-key –help查看
[root@linux-node1 pki]# salt-key -AThe following keys are going to be accepted:Unaccepted Keys:linux-node1linux-node2Proceed? [n/Y] yKey for minion linux-node1 accepted.Key for minion linux-node2 accepted.[root@linux-node1 pki]# salt-keyAccepted Keys:linux-node1linux-node2Denied Keys:Unaccepted Keys:Rejected Keys:
这时就可以在master端的已接受minionm看到minion端id文件了
[root@linux-node1 master]# pwd/etc/salt/pki/master[root@linux-node1 master]# tree.├── master.pem├── master.pub├── minions│ ├── linux-node1│ └── linux-node2├── minions_autosign├── minions_denied├── minions_pre└── minions_rejected5 directories, 4 files
实际上master的minions列表文件中存放的就是minion的公钥
[root@linux-node1 minions]# cat linux-node1-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7tnEScZ0vLwevAwFCQp5kADzCOcZ3pHc+zFVugnzGCxtrmymwgV0QFARSqGQU9eWL/vaY2hz8YIwmPIU5Ri2j+A0l8K15q2X2hgKepiU+qZG1Xc9EeAX/DPD+qynxXCd9EGMH32U1nQxlbnOwHUHdDUbfAXf6Mxm/8/5VqNEWnx8ymug6N2MAWvJbLn2+24jhMxjeJrJRxz4nVTqOa4ycOHiPqdwCaAUc9ul/sOp6VFlE+TsRQ3mcOHbYCDy9NgGmz3GNAtsdr6LcfEvYq4qq78DK6Y5i5eEKsVbDT8BBP5I9D8YwL8fymFB8LcTPiiRlwPaAvgL2KeL10C9Q1z6cwIDAQAB-----END PUBLIC KEY-----
master也会把自己的公钥发送到minion端
[root@linux-node1 minion]# pwd/etc/salt/pki/minion[root@linux-node1 minion]# cat minion_master.pub-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoPuOLwx+0cL+BKZZRmT4JYhdGfC4ww5ku2Na8ZP4fPy73iZ5KXDG8z/fwsueHXssnsAgsY3EbyyjIa6Cx8Lha0T+N9U00olpHshOWUjy1kRmMjMYnveuU8cw0MDTZ327Ze6TEUfR9DbFCcz1uzCnrCuCMUohtUA/ErwttAuERnaM5R7xZV4fG/eO8B0vXQv2nisJNIMRZbbCiaJTARirULqq8mpWIuqww3jZznef6R6WwhMCh+9vQTNVEXYropKQjm7cGgleQhUpRqPgtEw880qxybjMflOJZzOVTc1L72ah1s3unRReHU+olH+Zhxb2lb7/YpA2DoURf/b25M0h6wIDAQAB-----END PUBLIC KEY-----
五、Saltstack的远程执行
使用test.ping测试master和minion是否连通
salt:基本命令; *:代表所有minion主机;test:模块; ping:test模块的一个方法,这里的单引号也可以使用双引号
[root@linux-node1 minion]# salt '*' test.pinglinux-node2:Truelinux-node1:True
使用cmd.run远程执行命令,cmd是模块,run是cmd模块的一个方法
[root@linux-node1 minion]# salt '*' cmd.run 'w'linux-node2:21:19:48 up 16:54, 2 users, load average: 0.00, 0.00, 0.00USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATroot tty1 - 29Feb16 62days 0.10s 0.10s -bashroot pts/2 10.0.0.1 19:30 39:12 0.04s 0.04s -bashlinux-node1:21:19:48 up 17:05, 2 users, load average: 0.12, 0.03, 0.01USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATroot tty1 - 29Feb16 8days 0.15s 0.15s -bashroot pts/2 10.0.0.1 19:30 1.00s 0.89s 0.78s /usr/bin/python
六、配置管理
6.1启用配置管理
修改salt-master的配置文件,打开416至418行的注释
file_root代表文件目录所在,base指base环境,是必须存在的,这里支持多种(测试开发生产等)环境,后续会提到
[root@linux-node1 minion]# sed -n '416,418p' /etc/salt/masterfile_roots:base:- /srv/salt[root@linux-node1 minion]# mkdir /srv/salt[root@linux-node1 minion]# /etc/init.d/salt-master restart
6.2简单安装一个apache服务
编写apache.sls
[root@linux-node1 salt]# pwd/srv/salt[root@linux-node1 salt]# cat -A apache.slsapache-install:$ #服务IDpkg.installed:$ #apache:模块 install:方法- names:$ #names列表- httpd$ #会使用yum安装httpd- httpd-devel$ #会使用yum安装httpd-develapache-service:$ #服务IDservice.running:$ #service:模块 running:方法- name: httpd$ #name:指定http的服务用来service.running- enable: True$ #开机启动- reload: True$ #支持重载
执行上面的状态文件,salt:命令 *:代表所有minion,具体匹配方法后面会有详解 state:模块 sls:方法 apache:要执行的state文件
[root@linux-node1 salt]# salt '*' state.sls apachelinux-node2:ID: apache-installFunction: pkg.installedName: httpdResult: TrueComment: Package httpd is already installed.Started: 23:26:15.045492Duration: 2256.368 msChanges:ID: apache-installFunction: pkg.installedName: httpd-develResult: TrueComment: Package httpd-devel is already installed.Started: 23:26:17.302343Duration: 1.577 msChanges:ID: apache-serviceFunction: service.runningName: httpdResult: TrueComment: Service httpd is already enabled, and is in the desired stateStarted: 23:26:17.305384Duration: 137.522 msChanges:SummarySucceeded: 3Failed: 0Total states run: 3linux-node1:ID: apache-installFunction: pkg.installedName: httpdResult: TrueComment: Package httpd is already installed.Started: 23:26:15.152083Duration: 2307.265 msChanges:ID: apache-installFunction: pkg.installedName: httpd-develResult: TrueComment: Package httpd-devel is already installed.Started: 23:26:17.459645Duration: 1.052 msChanges:ID: apache-serviceFunction: service.runningName: httpdResult: TrueComment: Service httpd is already enabled, and is in the desired stateStarted: 23:26:17.462565Duration: 122.922 msChanges:SummarySucceeded: 3Failed: 0Total states run: 3
查看apahce服务状态
[root@linux-node1 salt]# lsof -i:80COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEhttpd 8054 root 4u IPv6 86585 0t0 TCP *:http (LISTEN)httpd 8058 apache 4u IPv6 86585 0t0 TCP *:http (LISTEN)httpd 8059 apache 4u IPv6 86585 0t0 TCP *:http (LISTEN)httpd 8060 apache 4u IPv6 86585 0t0 TCP *:http (LISTEN)httpd 8061 apache 4u IPv6 86585 0t0 TCP *:http (LISTEN)httpd 8062 apache 4u IPv6 86585 0t0 TCP *:http (LISTEN)httpd 8063 apache 4u IPv6 86585 0t0 TCP *:http (LISTEN)httpd 8064 apache 4u IPv6 86585 0t0 TCP *:http (LISTEN)httpd 8065 apache 4u IPv6 86585 0t0 TCP *:http (LISTEN)
6.3 编写top file,执行高级状态
top.sls是默认的入口文件,名称也是top.sls,必须放在base环境下
[root@linux-node1 salt]# cat top.slsbase: #base环境'linux-*': #指定base环境下的minion主机- apache #高级状态需要执行服务
执行高级状态,意思是从top.sls开始读入,进行匹配执行状态文件
[root@linux-node1 salt]# salt '*' state.highstate
七、saltstack的数据系统
7.1 学习grains
grains:搜集minion启动时的系统信息,只有在minion启动时才会搜集,grains更适合做一些静态的属性值的采集,例如设备的角色(role),磁盘个数(disk_num)等诸如此类非常固定的属性,另一个作用可以用来匹配minion
7.1.1 远程执行获取信息
列出所有的grains选项
[root@linux-node1 ~]# salt 'linux-node1*' grains.lslinux-node1:- SSDs- biosreleasedate- biosversion- cpu_flags- cpu_model- cpuarch- domain- fqdn- fqdn_ip4- fqdn_ip6- gpus- host- hwaddr_interfaces- id- init- ip4_interfaces- ip6_interfaces- ip_interfaces- ipv4- ipv6- kernel- kernelrelease- locale_info- localhost- lsb_distrib_codename- lsb_distrib_id- lsb_distrib_release- machine_id- manufacturer- master- mdadm- mem_total- nodename- num_cpus- num_gpus- os- os_family- osarch- oscodename- osfinger- osfullname- osmajorrelease- osrelease- osrelease_info- path- productname- ps- pythonexecutable- pythonpath- pythonversion- saltpath- saltversion- saltversioninfo- selinux- serialnumber- server_id- shell- virtual- zmqversion```列出所有grains和内容```bash[root@linux-node1 ~]# salt 'linux-node1*' grains.itemslinux-node1:SSDs:biosreleasedate:05/20/2014biosversion:6.00cpu_flags:- fpu- vme- de- pse- tsc- msr- pae- mce- cx8- apic- sep- mtrr- pge- mca- cmov- pat- pse36- clflush- dts- mmx- fxsr- sse- sse2- ss- syscall- nx- rdtscp- lm- constant_tsc- up- arch_perfmon- pebs- bts- xtopology- tsc_reliable- nonstop_tsc- aperfmperf- unfair_spinlock- pni- pclmulqdq- ssse3- cx16- sse4_1- sse4_2- popcnt- xsave- avx- hypervisor- lahf_lm- arat- epb- pln- pts- dtscpu_model:Intel(R) Core(TM) i3-2330M CPU @ 2.20GHzcpuarch:x86_64domain:fqdn:linux-node1fqdn_ip4:- 10.0.0.7fqdn_ip6:gpus:|_----------model:SVGA II Adaptervendor:unknownhost:linux-node1hwaddr_interfaces:----------eth0:00:0c:29:2c:10:a1eth1:00:0c:29:2c:10:ablo:00:00:00:00:00:00id:linux-node1init:upstartip4_interfaces:----------eth0:- 10.0.0.7eth1:- 172.16.1.7lo:- 127.0.0.1ip6_interfaces:----------eth0:- fe80::20c:29ff:fe2c:10a1eth1:- fe80::20c:29ff:fe2c:10ablo:- ::1ip_interfaces:----------eth0:- 10.0.0.7- fe80::20c:29ff:fe2c:10a1eth1:- 172.16.1.7- fe80::20c:29ff:fe2c:10ablo:- 127.0.0.1- ::1ipv4:- 10.0.0.7- 127.0.0.1- 172.16.1.7ipv6:- ::1- fe80::20c:29ff:fe2c:10a1- fe80::20c:29ff:fe2c:10abkernel:Linuxkernelrelease:2.6.32-573.el6.x86_64locale_info:----------defaultencoding:UTF8defaultlanguage:zh_CNdetectedencoding:UTF-8localhost:linux-node1lsb_distrib_codename:Finallsb_distrib_id:CentOSlsb_distrib_release:6.7machine_id:53d3f8757a7bdf1be87664bd00000012manufacturer:VMware, Inc.master:10.0.0.7mdadm:mem_total:992nodename:linux-node1num_cpus:1num_gpus:1os:CentOSos_family:RedHatosarch:x86_64oscodename:Finalosfinger:CentOS-6osfullname:CentOSosmajorrelease:6osrelease:6.7osrelease_info:- 6- 7path:/sbin:/usr/sbin:/bin:/usr/binproductname:VMware Virtual Platformps:ps -efHpythonexecutable:/usr/bin/python2.6pythonpath:- /usr/bin- /usr/lib64/python26.zip- /usr/lib64/python2.6- /usr/lib64/python2.6/plat-linux2- /usr/lib64/python2.6/lib-tk- /usr/lib64/python2.6/lib-old- /usr/lib64/python2.6/lib-dynload- /usr/lib64/python2.6/site-packages- /usr/lib64/python2.6/site-packages/gtk-2.0- /usr/lib/python2.6/site-packagespythonversion:- 2- 6- 6- final- 0saltpath:/usr/lib/python2.6/site-packages/saltsaltversion:2015.5.8saltversioninfo:- 2015- 5- 8- 0selinux:----------enabled:Falseenforced:Disabledserialnumber:VMware-56 4d 3d be 86 1f f0 55-7e 57 0a 5a a5 2c 10 a1server_id:1879729795shell:/bin/bashvirtual:VMwarezmqversion:3.2.5
显示单个grains内容,get方法直接显示值,item方法会把条目名也显示出来
[root@linux-node1 ~]# salt 'linux-node1*' grains.item fqdnlinux-node1:----------fqdn:linux-node1[root@linux-node1 ~]# salt 'linux-node1*' grains.get fqdn_ip4linux-node1:- 10.0.0.7
7.1.2 使用grains匹配minion主机
模拟使用grains匹配minion,-G代表指定grains匹配
[root@linux-node1 ~]# salt -G 'os:centos' grains.get fqdnlinux-node2:linux-node2linux-node1:linux-node1
修改minion配置文件,简单手动设置一个grains
[root@linux-node1 ~]# sed -n '84,87p' /etc/salt/miniongrains:roles:- webserver- memcache
重启grains,测试手动添加结果
[root@linux-node1 ~]# /etc/init.d/salt-minion restartStopping salt-minion daemon: [确定]Starting salt-minion daemon: [确定][root@linux-node1 ~]# salt -G 'roles:memcache' cmd.run 'uptime'linux-node1:20:43:25 up 1 day, 5:21, 2 users, load average: 0.15, 0.04, 0.01
添加grains,默认会到/etc/salt/grains中读取,手动添加到/etc/salt/grains即可
[root@linux-node2 ~]# cat /etc/salt/grainsapp:nginx[root@linux-node2 ~]# /etc/init.d/salt-minion restartStopping salt-minion daemon: [确定]Starting salt-minion daemon: [确定][root@linux-node1 ~]# salt '*' grains.item applinux-node2:----------app:nginxlinux-node1:---
7.1.3使用grains在state文件中使用grains
[root@linux-node1 salt]# cat top.slsbase:'app:nginx': #标记grains内容- match: grain #指定使用grains- apache
7.1.4 在jinja模板中使用grains
后续会有详细应用说明,此处不多赘述
keepalived-server:file.managed:- name: /etc/keepalived/keepalived.conf- source: salt://cluster/files/haproxy-outside-keepalived.conf- mode: 644- user: root- group: root- template: jinja{% if grains['fqdn'] == 'ip-172-31-43-148.eu-west-1.compute.internal' %}- ROUTID: haproxy_ha- ROLE: MASTER- PRIORITYID: 150{% elif grains['fqdn'] == 'ip-172-31-43-123.eu-west-1.compute.internal' %}- ROUTID: haproxy_ha- ROLE: BACKUP- PRIORITYID: 100{% endif %}```##7.2学习pillar###7.2.1 pillar介绍Pillar 是 Salt 非常重要的一个组件,它用于给特定的 minion 定义任何你需要的数据, 这些数据可以被 Salt 的其他组件使用。Salt 在 0.9.8 版本中引入了 Pillar。Pillar 在解析完成 后,是一个嵌套的 dict 结构;最上层的 key 是 minion ID,其 value 是该 minion 所拥有的 Pillar 数据;每一个 value 也都是 key/value。这里可以看出 Pillar 的一个特点,Pillar 数据是与特定 minion 关联的,也就是说每一个minion 都只能看到自己的数据, 所以 Pillar 可以用来传递敏感数据 (在 Salt 的设计中, Pillar 使用独立的加密 session,也是为了保证敏感数据的安全性) 。 Pillar 可以用在哪些地方?**敏感数据**例如 ssh key,加密证书等,由于 Pillar 使用独立的加密 session,可以确保这些敏感数据不被其他 minion 看到。**变量**可以在 Pillar 中处理平台差异性,比如针对不同的操作系统设置软件包的名字,然后在State 中引用。**其他任何数据**可以在 Pillar 中添加任何需要用到的数据。比如定义用户和 UID 的对应关系,mnion 的角色等。###7.2.2 pillar基础更改配置文件打开pillar,默认是关闭的```bash[root@linux-node1 ~]# sed -n '552p' /etc/salt/masterpillar_opts: True[root@linux-node1 ~]# /etc/init.d/salt-master restartStopping salt-master daemon: [确定]Starting salt-master daemon: [确定]
查看master自带的pillar条目,实际生产是不打开的,自带的pillar没什么卵用,所以一般都会设置成false,使用自己定义的pillar
[root@linux-node1 ~]# salt 'linux-node1*' pillar.itemslinux-node1:----------master:----------__role:masterauth_mode:1auto_accept:Falsecache_sreqs:Truecachedir:/var/cache/salt/mastercli_summary:Falseclient_acl:----------client_acl_blacklist:----------cluster_masters:cluster_mode:paranoidcon_cache:Falseconf_file:/etc/salt/masterconfig_dir:/etc/saltcython_enable:Falsedaemon:Truedefault_include:master.d/*.confenable_gpu_grains:Falseenforce_mine_cache:Falseenumerate_proxy_minions:Falseenvironment:Noneevent_return:event_return_blacklist:event_return_queue:0event_return_whitelist:ext_job_cache:ext_pillar:extension_modules:/var/cache/salt/extmodsexternal_auth:----------failhard:Falsefile_buffer_size:1048576file_client:localfile_ignore_glob:Nonefile_ignore_regex:Nonefile_recv:Falsefile_recv_max_size:100file_roots:----------base:- /srv/saltfileserver_backend:- rootsfileserver_followsymlinks:Truefileserver_ignoresymlinks:Falsefileserver_limit_traversal:Falsegather_job_timeout:10gitfs_base:mastergitfs_env_blacklist:gitfs_env_whitelist:gitfs_insecure_auth:Falsegitfs_mountpoint:gitfs_passphrase:gitfs_password:gitfs_privkey:gitfs_pubkey:gitfs_remotes:gitfs_root:gitfs_user:hash_type:md5hgfs_base:defaulthgfs_branch_method:brancheshgfs_env_blacklist:hgfs_env_whitelist:hgfs_mountpoint:hgfs_remotes:hgfs_root:id:linux-node1interface:0.0.0.0ioflo_console_logdir:ioflo_period:0.01ioflo_realtime:Trueioflo_verbose:0ipv6:Falsejinja_lstrip_blocks:Falsejinja_trim_blocks:Falsejob_cache:Truekeep_jobs:24key_logfile:/var/log/salt/keykeysize:2048log_datefmt:%H:%M:%Slog_datefmt_logfile:%Y-%m-%d %H:%M:%Slog_file:/var/log/salt/masterlog_fmt_console:[%(levelname)-8s] %(message)slog_fmt_logfile:%(asctime)s,%(msecs)03.0f [%(name)-17s][%(levelname)-8s][%(process)d] %(message)slog_granular_levels:----------log_level:warningloop_interval:60maintenance_floscript:/usr/lib/python2.6/site-packages/salt/daemons/flo/maint.flomaster_floscript:/usr/lib/python2.6/site-packages/salt/daemons/flo/master.flomaster_job_cache:local_cachemaster_pubkey_signature:master_pubkey_signaturemaster_roots:----------base:- /srv/salt-mastermaster_sign_key_name:master_signmaster_sign_pubkey:Falsemaster_tops:----------master_use_pubkey_signature:Falsemax_event_size:1048576max_minions:0max_open_files:100000minion_data_cache:Trueminionfs_blacklist:minionfs_env:baseminionfs_mountpoint:minionfs_whitelist:nodegroups:----------open_mode:Falseorder_masters:Falseoutputter_dirs:peer:----------permissive_pki_access:Falsepidfile:/var/run/salt-master.pidpillar_opts:Truepillar_roots:----------base:- /srv/pillarpillar_safe_render_error:Truepillar_source_merging_strategy:smartpillar_version:2pillarenv:Noneping_on_rotate:Falsepki_dir:/etc/salt/pki/masterpreserve_minion_cache:Falsepub_hwm:1000publish_port:4505publish_session:86400queue_dirs:raet_alt_port:4511raet_clear_remotes:Falseraet_main:Trueraet_mutable:Falseraet_port:4506range_server:range:80reactor:reactor_refresh_interval:60reactor_worker_hwm:10000reactor_worker_threads:10renderer:yaml_jinjaret_port:4506root_dir:/rotate_aes_key:Truerunner_dirs:saltversion:2015.5.8search:search_index_interval:3600serial:msgpackshow_jid:Falseshow_timeout:Truesign_pub_messages:Falsesock_dir:/var/run/salt/mastersqlite_queue_dir:/var/cache/salt/master/queuesssh_passwd:ssh_port:22ssh_scan_ports:22ssh_scan_timeout:0.01ssh_sudo:Falsessh_timeout:60ssh_user:rootstate_aggregate:Falsestate_auto_order:Truestate_events:Falsestate_output:fullstate_top:salt://top.slsstate_top_saltenv:Nonestate_verbose:Truesudo_acl:Falsesvnfs_branches:branchessvnfs_env_blacklist:svnfs_env_whitelist:svnfs_mountpoint:svnfs_remotes:svnfs_root:svnfs_tags:tagssvnfs_trunk:trunksyndic_dir:/var/cache/salt/master/syndicssyndic_event_forward_timeout:0.5syndic_jid_forward_cache_hwm:100syndic_master:syndic_max_event_process_time:0.5syndic_wait:5timeout:5token_dir:/var/cache/salt/master/tokenstoken_expire:43200transport:zeromquser:rootverify_env:Truewin_gitrepos:- https://github.com/saltstack/salt-winrepo.gitwin_repo:/srv/salt/win/repowin_repo_mastercachefile:/srv/salt/win/repo/winrepo.pworker_floscript:/usr/lib/python2.6/site-packages/salt/daemons/flo/worker.floworker_threads:5zmq_filtering:False```###7.2.3 设置pillar环境修改master的配置文件,设置pillr_root,可以看出pillar是支持环境的,同样也许存在base环境,而且也是支持topfile的,可以指定具体哪个minion配置哪个minion```bash[root@linux-node1 ~]# sed -n '529,531p' /etc/salt/masterpillar_roots:base:- /srv/pillar[root@linux-node1 ~]# /etc/init.d/salt-master restartStopping salt-master daemon: [确定]Starting salt-master daemon: [确定]
7.2.4手动定义一个pillar
[root@linux-node1 pillar]# pwd/srv/pillar[root@linux-node1 pillar]# cat apache.sls{% if grains['os'] == 'CentOS' %}apache: httpd{% elif grains['os'] == 'Debain' %}apache: apache2{% endif %}[root@linux-node1 pillar]# cat top.slsbase:'linux-node2*':- apache[root@linux-node1 pillar]# salt '*' pillar.itemslinux-node1:----------linux-node2:----------apache:httpd```如果对pillar具体内容进行修改,需要执行刷新pillar```bash[root@linux-node1 pillar]# salt '*' saltutil.refresh_pillarlinux-node2:Truelinux-node1:True
7.2.5 使用pillar匹配minion
salt -I 指定pillar匹配
[root@linux-node1 pillar]# salt -I 'apache:httpd' cmd.run 'cd /etc/salt &&pwd'linux-node2:/etc/salt
7.3 grains与pillar的区别
- grains存储的是静态、不常变化的内容;pillar则相反,存储的是动态数据
- grains是存储在minion本地,可以使用saltutil.sync_grains刷新;而pillar存储在master本地,可以使用saltutil.refresh_pillar来刷新
- minion有权限操作自己的grains值,如增加、删除,可以用来做资产管理等;pillar存储在master中指定数据,只有指定的minion才可以看到,可以用来存储敏感数据,minion无权修改
本文介绍 SaltStack 的安装配置过程,包括环境搭建、远程执行、配置管理及数据系统的使用。涵盖 minion 和 master 的配置,认证流程,以及 grains 和 pillar 的详细应用。

30万+

被折叠的 条评论
为什么被折叠?



