SaltStack初始化系统
目录规划如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# tree
.
├── pillar
│ ├── base
│ │ ├── top.sls
│ │ └── zabbix
│ │ └── agent.sls
│ └── prod
└── salt
├── base
│ ├── init
│ │ ├── audit.sls
│ │ ├── dns.sls
│ │ ├── env_init.sls
│ │ ├── epel.sls
│ │ ├── files
│ │ │ ├── resolv.conf
│ │ │ └── zabbix_agentd.conf
│ │ ├── history.sls
│ │ ├── sysctl.sls
│ │ └── zabbix_agent.sls
│ └── top.sls
└── prod
9 directories, 12 files
1、修改salt-master配置文件,重启master,创建相应的目录!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# egrep -A 4 ^file_roots /etc/salt/master
file_roots:
base:
- /srv/salt/base
prod:
- /srv/salt/prod
# grep -EA 4 ^pillar_roots /etc/salt/master
pillar_roots:
base:
- /srv/pillar/base
prod:
- /srv/pillar/prod
mkdir -p /srv/salt/base
mkdir -p /srv/salt/prod
mkdir -p /srv/pillar/base
mkdir -p /srv/pillar/prod
2、base环境的sls状态文件的配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# cd /srv/salt/base/
# tree
.
├── init#系统初始化模块
│ ├── audit.sls#记录命令操作到:/var/log/messages
│ ├── dns.sls#本地DNS解析文件:/etc/resolv.conf
│ ├── env_init.sls#将其它的sls包括在一个文件里
│ ├── epel.sls#配置epel源
│ ├── files#此目录存放相应的文件
│ │ ├── resolv.conf
│ │ └── zabbix_agentd.conf
│ ├── history.sls#命令历史记录格式的调整
│ ├── sysctl.sls#内核参数优化
│ └── zabbix_agent.sls#zabbix-agent
└── top.sls
2 directories, 10 files
##########################################################################################
1
2
3
4
5
# cat init/audit.sls
/etc/bashrc:
file.append:
- text:
- export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "":$(who am i):[`pwd`]"$msg"; }'
##########################################################################################
1
2
3
4
5
6
7
# cat init/dns.sls
/etc/resolv.conf:
file.managed:
- source: salt://init/files/resolv.conf
- user: root
- group: root
- mode: 644
##########################################################################################
1
2
3
4
5
6
# cat init/epel.sls
yum_repo_release:
pkg.installed:
- sources:
- epel-release: http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
- zabbix-release: http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
##########################################################################################
1
2
3
4
5
# cat init/history.sls
/etc/profile:
file.append:
- text:
- export HISTTIMEFORMAT="%F %T `whoami` "
##########################################################################################
1
2
3
4
5
6
7
8
9
10
11
12
13
# cat init/sysctl.sls
net.ipv4.ip_local_port_range:
sysctl.present:
- value: 10000 65000
fs.file-max:
sysctl.present:
- value: 2000000
net.ipv4.ip_forward:
sysctl.present:
- value: 1
vm.swappiness:
sysctl.present:
- value: 0
##########################################################################################
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# cat init/zabbix_agent.sls
zabbix-agent:
pkg.installed:
- name: zabbix-agent
file.managed:
- name: /etc/zabbix/zabbix_agentd.conf
- source: salt://init/files/zabbix_agentd.conf
- template: jinja
- defaults:
Server: {{ pillar['Zabbix_Server'] }}
- require:
- pkg: zabbix-agent
service.running:
- enable: True
- watch:
- pkg: zabbix-agent
- file: zabbix-agent
zabbix_agentd.conf.d:
file.directory:
- name: /etc/zabbix/zabbix_agentd.d
- watch_in:
- service: zabbix-agent
- require:
- pkg: zabbix-agent
- file: zabbix-agent
##########################################################################################
1
2
3
4
5
6
7
8
# cat init/env_init.sls
include:
- init.audit
- init.dns
- init.epel
- init.history
- init.sysctl
- init.zabbix_agent
##########################################################################################
1
2
3
4
5
# cat init/files/resolv.conf
# Generated by NetworkManager
search oldboyedu.com
nameserver 114.114.114.114
nameserver 8.8.8.8
##########################################################################################
1
2
# grep -E ^Server= init/files/zabbix_agentd.conf
Server={{ Server }}
##########################################################################################
1
2
3
4
# cat top.sls
base:
'*':
- init.env_init
##########################################################################################
3、pillar的配置
1
2
3
4
5
6
7
# cd /srv/pillar/base/
# tree
.
├── top.sls
└── zabbix
└── agent.sls
1 directory, 2 files
##########################################################################################
1
2
3
4
# cat top.sls
base:
'*':
- zabbix.agent
##########################################################################################
1
2
# cat zabbix/agent.sls
Zabbix_Server: 192.168.56.11
4、验证:执行高级状态
1
salt '*' state.highstate
页:
[1]