[root@linux-node1 ~]# cd /srv/salt/base/
[root@linux-node1 base]# ls
apache.sls dns.sls files top.sls
[root@linux-node1 base]# mkdir init
[root@linux-node1 base]# mv apache.sls dns.sls files/ /tmp/
[root@linux-node1 base]# ll
总用量 8
drwxr-xr-x 2 root root 4096 11月 17 14:05 init
-rw-r--r-- 1 root root 23 11月 17 13:15 top.sls
[root@linux-node1 base]# cp /tmp/dns.sls init/
[root@linux-node1 base]# cd init/
[root@linux-node1 init]# mkdir files
[root@linux-node1 init]# cp /etc/resolv.conf files/
[root@linux-node1 init]# cat /srv/salt/base/init/files/resolv.conf
#hehe
nameserver 10.0.0.2
[root@linux-node1 init]# cat /srv/salt/base/init/dns.sls
/etc/resolv.conf:
file.managed:
- source: salt://init/files/resolv.conf
- user: root
- group: root
- mode: 644
场景1 记录历史命令:
[root@linux-node1 init]# export PROMPT_COMMAND=‘{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg";}‘
[root@linux-node1 ~]# tailf /var/log/messages
Nov 17 14:25:24 linux-node1 root: [euid=root]:root pts/0 2015-11-17 10:44 (10.0.0.1):[/srv/salt/base/init]free -m
场景2 系统初始化
[root@linux-node1 init]# cat dns.sls =========================>dns的sls文件
/etc/resolv.conf:
file.managed:
- source: salt://init/files/resolv.conf
- user: root
- group: root
- mode: 644
[root@linux-node1 init]# cat history.sls =========================>历史记录的sls文件
/etc/profile:
file.append:
- text:
- export HISTTIMEFORMAT="%F %T `whoami`"
[root@linux-node1 init]# cat audit.sls =========================>审计的sls文件
/etc/bashrc:
file.append:
- text:
- export PROMPT_COMMAND=‘{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg";}‘
修改内核参数:
[root@linux-node1 init]# cat sysctl.sls
vm.swappiness:
sysctl.present:
- value: 0
net.ipv4.ip_local_port_range: ====================================>端口范围
sysctl.present:
- value: 10000 65000
fs.file-max: ====================================>可以打开的最大文件数
sysctl.present:
- value: 100000
[root@linux-node1 init]# cat env_init.sls ====================================>将所有需要优化的参数include到env_init.sls文件里面
include:
- init.dns
- init.history
- init.audit
- init.sysctl
[root@linux-node1 base]# cat /srv/salt/base/top.sls ====================================> top file文件
base:
‘*‘:
- init.env_init
[root@linux-node1 base]# salt ‘*‘ state.highstate test=True =====================>test=True 此处用test=True参数,测试系统究竟修改了哪些参数,如果没有错误再执行
[root@linux-node1 base]# salt ‘*‘ state.highstate
老男孩网址:http://www.etiantian.org
qq:406564728
欢迎交流
本文出自 “linux” 博客,请务必保留此出处http://chenjisong.blog.51cto.com/7858025/1714330
原文地址:http://chenjisong.blog.51cto.com/7858025/1714330