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. linux下csv导出文件中文乱码问题

    近日在服务器端通过导出csv文件,将数据从linux服务器端保存到windows桌面端,以便用户可以通过excel打开使用数据. 但是在使用excel打开csv文件时,出现了中文乱码的情况,但是使用记 ...

  2. JAVAOOP集合框架

    集合框架三大内容:对外的接口.接口的实现和对集合运算的算法 集合有三大类接口:List.Set.Map 共同点:都是集合接口,都可以用来存储很多对象 不同:Collection接口存储一组不唯一(允许 ...

  3. vue笔记v-bind

    把message的信息绑定给title,运行出来的结果是<span title="you loaded this page on +Mon Nov 21 2016 18:28:38 G ...

  4. linux poll用法

    相对于select来说,poll 也是在指定时间内论询一定数量的文件描述符,来测试其中是否有就绪的,不过,poll 提供了一个易用的方法,来实现 i/o 复用. 声明如下: #include < ...

  5. Android 网络通用类 NetUtil

    1.整体分析 1.1.源代码如下,可以直接Copy. public class NetUtil { /** * 用户是否连接网络 * * @param context Context */ publi ...

  6. Android Studio的Log日志调试

    本人菜鸟一枚,极大发挥了搜索的功能.现记录一番,以备后患. 用断点真的很烦,因为之前写linux的时候,就是用最蠢但是也是挺有帮助的printf()来进行调试. 其实用Log输出日志的原理也是差不多的 ...

  7. stop-hbase.sh出现stopping hbasecat:/tmp/hbase-root-master.pid:No such file or directory

    stop-hbase.sh出现stopping hbasecat:/tmp/hbase-root-master.pid:No such file or directory解决办法:在hbase-env ...

  8. 【Insert Interval】cpp

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

  9. ASP NET Core ---FluentValidation

    官方文档:https://fluentvalidation.net/ 一.安装: 二.应用: 1.建立PostValidator: public class PostValidator:Abstrac ...

  10. C++ Primer 第2章 变量和基本类型

    C++ Primer 第2章 变量和基本类型 C Primer 第2章 变量和基本类型 1 基本内置类型 算数类型 类型转换 字面值常量 2 变量 变量定义 3 复合类型 引用d左引用 指针d 4 c ...