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、验证结果

saltstack 实现系统初始化的更多相关文章

  1. saltstack系统初始化(九)

    一.系统初始化需要的配置 当我们的服务器上架并安装好操作系统后,都会有一些基础的操作,所以生产环境中使用SaltStack,建议将所有服务器都会涉及的基础配置或者软件部署归类放在base环境下.此处, ...

  2. Saltstack生产案例之系统初始化

    把之前的配置打个包 zip -r salt.zip * 拷贝到/root/tools目录 博客园文件里面也保留一份,删除之前所有的salt配置文件重新开始 想 1,系统初始化 2,功能模块:设置单独的 ...

  3. SaltStack生产案例-系统初始化

    需求分析 一,系统初始化 1.1  关闭SELinux 1.2  关闭默认iptables 1.3  时间同步(配置NTP)  1.4  文件描述符(必备/etc/security/limmits.c ...

  4. centos7 系统初始化脚本

    现在自己的本地虚拟机系统,直接安装的是centos7.2 mini版,安装完成发现好多东西都没有安装,所以写了一个简单的系统初始化脚本,让自己可以省一些力气,哈哈 人懒主要是. 下面贴出写的脚本,脚本 ...

  5. ssh下:系统初始化实现ServletContextListener接口时,获取spring中数据层对象无效的问题

    想要实现的功能:SSH环境下,数据层都交由Spring管理:在服务启动时,将数据库中的一些数据加载到ServletContext中缓存起来. 系统初始化类需要实现两个接口: ServletContex ...

  6. 详解linux系统的启动过程及系统初始化

    一.linux系统的启动流程 关于linux系统的启动流程我们可以按步进行划分为如下: POST加电自检 -->BIOS(Boot Sequence)-->加载对应引导上的MBR(boot ...

  7. Ztack学习笔记(2)-系统初始化分析

    main函数先执行初始化工作,包括硬件.网络层.任务等的初始化. 一 系统初始化 系统初始化函数主要完成内存分配.消息队列头.定时器.电源管理.任务系统及内存栈等的初始化,具体如下代码所示: //os ...

  8. Linux安装系统注意事项及系统初始化

      Linux安装系统注意事项 1.分区 学习用途: /boot:200M /swap :内存的1到2倍 /:根据需要分配大小,比如虚拟机下总空间是15G,那么可以分配8——10G跟/分区,如果是生产 ...

  9. ucos系统初始化及启动过程

    之前在ucos多任务切换中漏掉了一个变量, OSCtxSwCtr标识系统任务切换次数 主要应该还是用在调试功能中 Ucos系统初始化函数为OSInit(),主要完成以下功能 全局变量初始化 就绪任务表 ...

随机推荐

  1. 解决scp命令pemission denied,please try again的问题

    问题描述:输入命令scp a.txt root@192.168.0.105:/tmp(将当前目录下的文件a.txt复制到服务器IP为192.168.0.105的root用户的/tmp/目录下),结果会 ...

  2. photoshop入门笔记1:PS的快捷键

    PS部分快捷键: 1.魔棒的作用:比较快捷的抠图工具,对于一些分界线比较明显的图像,通过魔棒工具可以很快速的将图像抠出,魔棒的作用是可以知道你点击的那个地方的颜色,并自动获取附近区域相同的颜色,使它们 ...

  3. POJ 1222 反转

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12469   Accepted: 7 ...

  4. [CodeForces948B]Primal Sport(数论)

    Description 题目链接 Solution 设f(x)为x的最大质因子 那么由题意易得\(X_1\)的范围在\([X_2-f(X_2)+1,X2]\) 同理\(X_0\)的范围在\([X_1- ...

  5. 阿里巴巴Java开发规约Eclipse插件安装及使用

    技术交流群:233513714 插件安装 环境:JDK1.8,Eclipse4+.有同学遇到过这样的情况,安装插件重启后,发现没有对应的菜单项,从日志上也看不到相关的异常信息,最后把JDK从1.6升级 ...

  6. miniui IE对省略号即text-overflow:ellipsis显示不一样的问题

    做miniui项目中发现,IE对文本以英文或数字结尾的是英文的省略号,以汉字结尾的就是中文的省略号.只要将字体变为统一宋体即可解决.即 .mini-grid-cell-inner    {       ...

  7. easyui-datagrid单选模式下隐藏表头的全选框

    easyui-datagrid可以不使用复选框来进行单选,直接使用onSelect和 singleSelect:true就可以实现单选,但是有一些用户会比较习惯使用勾选框,这时会加一列checkbox ...

  8. JavaSE总结--多线程

    进程: 进程之间内存隔离,内存不共享. 线程: 可以共享内存. 每个线程都是一个栈. 多线程的好处: 1)防止程序阻塞. wait与notify的区别: 针对等待队列而言. wait:进入等待队列.必 ...

  9. OVGap 原生与JS交互

    源代码:https://github.com/windshg/OVGap OVGap:一个轻量级的类库,能够让iOS应用和远程网页的 Javascript 代码进行通信,也就是说,远程的 Javasc ...

  10. 【Insert Interval】cpp

    题目: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if nec ...