1、整体结构如下

[root@zabbix init]# pwd
/srv/salt/base/init
[root@zabbix init]# ll
total
-rw-r--r-- root root Jun : audit.sls
-rw-r--r-- root root Mar dns.sls
-rw-r--r-- root root Jun : env_init.sls
drwxr-xr-x root root Jun : files
-rw-r--r-- root root Jun : history.sls
-rw-r--r-- root root Jun : sysctl.sls

2、状态文件内容如下

[root@zabbix init]# cat audit.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@zabbix init]# cat dns.sls
/etc/resolv.conf:
file.managed:
- source: salt://init/files/resolv.conf
- user: root
- gourp: root
- mode: [root@zabbix init]# cat history.sls
/etc/profile:
file.append:
- text:
- export HISTTIMEFORMAT="%F %T `whoami`"
[root@zabbix init]# cat sysctl.sls
net.ipv4.ip_local_port_range:
sysctl.present:
- value:
fs.file-max:
sysctl.present:
- value:
net.ipv4.ip_forward:
sysctl.present:
- value:
vm.swappiness:
sysctl.present:
- value:
[root@zabbix init]# cat env_init.sls
include:
- init.dns
- init.history
- init.audit
- init.sysctl
[root@zabbix init]# cat /srv/salt/base/top.sls
base:
'*':
- init.env_init

3、执行结果

[root@zabbix init]# salt '*' state.highstate test=True #可以先测试一下

[root@zabbix init]# salt '*' state.highstate test=True
zabbix:
----------
ID: /etc/resolv.conf
Function: file.managed
Result: True
Comment: The file /etc/resolv.conf is in the correct state
Started: 21:30:07.452387
Duration: 38.22 ms
Changes:
----------
ID: /etc/profile
Function: file.append
Result: None
Comment: File /etc/profile is set to be updated
Started: 21:30:07.490775
Duration: 3.489 ms
Changes:
----------
diff:
---

+++

@@ -74,3 +74,4 @@

unset i
unset -f pathmunge
+export HISTTIMEFORMAT="%F %T `whoami`"
----------
ID: /etc/bashrc
Function: file.append
Result: None
Comment: File /etc/bashrc is set to be updated
Started: 21:30:07.494616
Duration: 3.249 ms
Changes:
----------
diff:
---

+++

@@ -90,3 +90,4 @@

unset -f pathmunge
fi
# vim:ts=4:sw=4
+export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg"; }'
----------
ID: net.ipv4.ip_local_port_range
Function: sysctl.present
Result: None
Comment: Sysctl option net.ipv4.ip_local_port_range might be changed, we failed to check config file at /etc/sysctl.d/99-salt.conf. The file is either unreadable, or missing.
Started: 21:30:07.499427
Duration: 42.356 ms
Changes:
----------
ID: fs.file-max
Function: sysctl.present
Result: None
Comment: Sysctl option fs.file-max might be changed, we failed to check config file at /etc/sysctl.d/99-salt.conf. The file is either unreadable, or missing.
Started: 21:30:07.542193
Duration: 68.585 ms
Changes:
----------
ID: net.ipv4.ip_forward
Function: sysctl.present
Result: None
Comment: Sysctl option net.ipv4.ip_forward might be changed, we failed to check config file at /etc/sysctl.d/99-salt.conf. The file is either unreadable, or missing.
Started: 21:30:07.610971
Duration: 40.195 ms
Changes:
----------
ID: vm.swappiness
Function: sysctl.present
Result: None
Comment: Sysctl option vm.swappiness might be changed, we failed to check config file at /etc/sysctl.d/99-salt.conf. The file is either unreadable, or missing.
Started: 21:30:07.651402
Duration: 30.574 ms
Changes:

Summary for zabbix
------------
Succeeded: 7 (unchanged=6, changed=2)
Failed: 0
------------
Total states run: 7
Total run time: 226.668 ms
k8s-node1:
----------
ID: /etc/resolv.conf
Function: file.managed
Result: None
Comment: The file /etc/resolv.conf is set to be changed
Started: 21:30:07.717759
Duration: 68.049 ms
Changes:
----------
diff:
---
+++
@@ -0,0 +1 @@
+nameserver 114.114.114.114
----------
ID: /etc/profile
Function: file.append
Result: None
Comment: File /etc/profile is set to be updated
Started: 21:30:07.785995
Duration: 2.284 ms
Changes:
----------
diff:
---

+++

@@ -76,3 +76,4 @@

unset -f pathmunge
JAVA_HOME=/usr/local/jdk
export PATH=$PATH:/usr/local/jdk/bin
+export HISTTIMEFORMAT="%F %T `whoami`"
----------
ID: /etc/bashrc
Function: file.append
Result: None
Comment: File /etc/bashrc is set to be updated
Started: 21:30:07.788420
Duration: 3.71 ms
Changes:
----------
diff:
---

+++

@@ -90,3 +90,4 @@

unset -f pathmunge
fi
# vim:ts=4:sw=4
+export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg"; }'
----------
ID: net.ipv4.ip_local_port_range
Function: sysctl.present
Result: None
Comment: Sysctl option net.ipv4.ip_local_port_range might be changed, we failed to check config file at /etc/sysctl.d/99-salt.conf. The file is either unreadable, or missing.
Started: 21:30:07.793759
Duration: 206.597 ms
Changes:
----------
ID: fs.file-max
Function: sysctl.present
Result: None
Comment: Sysctl option fs.file-max might be changed, we failed to check config file at /etc/sysctl.d/99-salt.conf. The file is either unreadable, or missing.
Started: 21:30:08.000637
Duration: 39.194 ms
Changes:
----------
ID: net.ipv4.ip_forward
Function: sysctl.present
Result: None
Comment: Sysctl option net.ipv4.ip_forward might be changed, we failed to check config file at /etc/sysctl.d/99-salt.conf. The file is either unreadable, or missing.
Started: 21:30:08.040010
Duration: 22.761 ms
Changes:
----------
ID: vm.swappiness
Function: sysctl.present
Result: None
Comment: Sysctl option vm.swappiness might be changed, we failed to check config file at /etc/sysctl.d/99-salt.conf. The file is either unreadable, or missing.
Started: 21:30:08.062950
Duration: 21.728 ms
Changes:

Summary for k8s-node1
------------
Succeeded: 7 (unchanged=7, changed=3)
Failed: 0
------------
Total states run: 7
Total run time: 364.323 ms
[root@zabbix init]#
[root@zabbix init]#
[root@zabbix init]#
[root@zabbix init]#
[root@zabbix init]#
[root@zabbix init]#
[root@zabbix init]#
[root@zabbix init]#
[root@zabbix init]#
[root@zabbix init]#
[root@zabbix init]#
[root@zabbix init]# salt '*' state.highstate
zabbix:
----------
ID: /etc/resolv.conf
Function: file.managed
Result: True
Comment: File /etc/resolv.conf is in the correct state
Started: 21:30:33.795289
Duration: 143.126 ms
Changes:
----------
ID: /etc/profile
Function: file.append
Result: True
Comment: Appended 1 lines
Started: 21:30:33.938875
Duration: 4.35 ms
Changes:
----------
diff:
---

+++

@@ -74,3 +74,4 @@

unset i
unset -f pathmunge
+export HISTTIMEFORMAT="%F %T `whoami`"
----------
ID: /etc/bashrc
Function: file.append
Result: True
Comment: Appended 1 lines
Started: 21:30:33.943370
Duration: 3.352 ms
Changes:
----------
diff:
---

+++

@@ -90,3 +90,4 @@

unset -f pathmunge
fi
# vim:ts=4:sw=4
+export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg"; }'
----------
ID: net.ipv4.ip_local_port_range
Function: sysctl.present
Result: True
Comment: Updated sysctl value net.ipv4.ip_local_port_range = 10000 65000
Started: 21:30:33.951414
Duration: 44.024 ms
Changes:
----------
net.ipv4.ip_local_port_range:
10000 65000
----------
ID: fs.file-max
Function: sysctl.present
Result: True
Comment: Updated sysctl value fs.file-max = 1000000
Started: 21:30:33.995769
Duration: 9.811 ms
Changes:
----------
fs.file-max:
1000000
----------
ID: net.ipv4.ip_forward
Function: sysctl.present
Result: True
Comment: Updated sysctl value net.ipv4.ip_forward = 1
Started: 21:30:34.006046
Duration: 16.893 ms
Changes:
----------
net.ipv4.ip_forward:
1
----------
ID: vm.swappiness
Function: sysctl.present
Result: True
Comment: Updated sysctl value vm.swappiness = 0
Started: 21:30:34.023300
Duration: 10.572 ms
Changes:
----------
vm.swappiness:
0

Summary for zabbix
------------
Succeeded: 7 (changed=6)
Failed: 0
------------
Total states run: 7
Total run time: 232.128 ms
k8s-node1:
----------
ID: /etc/resolv.conf
Function: file.managed
Result: True
Comment: File /etc/resolv.conf updated
Started: 21:30:34.044920
Duration: 246.393 ms
Changes:
----------
diff:
---
+++
@@ -0,0 +1 @@
+nameserver 114.114.114.114
----------
ID: /etc/profile
Function: file.append
Result: True
Comment: Appended 1 lines
Started: 21:30:34.291544
Duration: 2.689 ms
Changes:
----------
diff:
---

+++

@@ -76,3 +76,4 @@

unset -f pathmunge
JAVA_HOME=/usr/local/jdk
export PATH=$PATH:/usr/local/jdk/bin
+export HISTTIMEFORMAT="%F %T `whoami`"
----------
ID: /etc/bashrc
Function: file.append
Result: True
Comment: Appended 1 lines
Started: 21:30:34.294458
Duration: 3.115 ms
Changes:
----------
diff:
---

+++

@@ -90,3 +90,4 @@

unset -f pathmunge
fi
# vim:ts=4:sw=4
+export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg"; }'
----------
ID: net.ipv4.ip_local_port_range
Function: sysctl.present
Result: True
Comment: Updated sysctl value net.ipv4.ip_local_port_range = 10000 65000
Started: 21:30:34.299328
Duration: 23.361 ms
Changes:
----------
net.ipv4.ip_local_port_range:
10000 65000
----------
ID: fs.file-max
Function: sysctl.present
Result: True
Comment: Updated sysctl value fs.file-max = 1000000
Started: 21:30:34.322949
Duration: 21.344 ms
Changes:
----------
fs.file-max:
1000000
----------
ID: net.ipv4.ip_forward
Function: sysctl.present
Result: True
Comment: Updated sysctl value net.ipv4.ip_forward = 1
Started: 21:30:34.344490
Duration: 8.887 ms
Changes:
----------
net.ipv4.ip_forward:
1
----------
ID: vm.swappiness
Function: sysctl.present
Result: True
Comment: Updated sysctl value vm.swappiness = 0
Started: 21:30:34.353661
Duration: 8.257 ms
Changes:
----------
vm.swappiness:
0

Summary for k8s-node1
------------
Succeeded: 7 (changed=7)
Failed: 0
------------
Total states run: 7
Total run time: 314.046 ms
[root@zabbix init]#


4、验证结果

最新文章

  1. JNI中C调用Java方法
  2. PHP生成图片验证码demo【OOP面向对象版本】
  3. library not found for -lPods 的解决办法
  4. Servlet 3特性:异步Servlet
  5. 用C语言简单加密解密
  6. iOS学习笔记之回调(二)
  7. CI获取ip的API
  8. 使用GPUImage开启的相机进行摄像,保存写入到Path
  9. guice框架的入门使用
  10. Java基础知识强化16:深入分析Java线程中断机制
  11. PHP http(file_get_content) GET与POST请求方式
  12. NFTS数据流
  13. 机器学习基石:01 The Learning Problem
  14. 3种自增ID说明
  15. 【mysql】mysql尾部空格
  16. 【Shiro】小读Shiro Filter
  17. Python中的MySQLConnector使用介绍
  18. C语言程序设计--文件操作
  19. 《高性能MySQL》——第五章创建高性能索引
  20. install Mac OS on Vmware

热门文章

  1. MYSQL SQL高级查询技巧
  2. linxu信号种类
  3. 图像的模糊-opencv
  4. mysql学习第三天笔记
  5. idea push reject:push mater to origin/master was rejected by remote
  6. 被relativeLayout的grivate center 折腾死了
  7. 获取<考试>博文密码!o(*≧▽≦)ツ
  8. BitLocker:如何启用网络解锁
  9. Android学习记录(5)—在java中学习多线程下载之断点续传②
  10. ARC下,不显式指定任何属性关键字时,默认的关键字都有哪些