saltstack 实现系统初始化
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 实现系统初始化的更多相关文章
- saltstack系统初始化(九)
一.系统初始化需要的配置 当我们的服务器上架并安装好操作系统后,都会有一些基础的操作,所以生产环境中使用SaltStack,建议将所有服务器都会涉及的基础配置或者软件部署归类放在base环境下.此处, ...
- Saltstack生产案例之系统初始化
把之前的配置打个包 zip -r salt.zip * 拷贝到/root/tools目录 博客园文件里面也保留一份,删除之前所有的salt配置文件重新开始 想 1,系统初始化 2,功能模块:设置单独的 ...
- SaltStack生产案例-系统初始化
需求分析 一,系统初始化 1.1 关闭SELinux 1.2 关闭默认iptables 1.3 时间同步(配置NTP) 1.4 文件描述符(必备/etc/security/limmits.c ...
- centos7 系统初始化脚本
现在自己的本地虚拟机系统,直接安装的是centos7.2 mini版,安装完成发现好多东西都没有安装,所以写了一个简单的系统初始化脚本,让自己可以省一些力气,哈哈 人懒主要是. 下面贴出写的脚本,脚本 ...
- ssh下:系统初始化实现ServletContextListener接口时,获取spring中数据层对象无效的问题
想要实现的功能:SSH环境下,数据层都交由Spring管理:在服务启动时,将数据库中的一些数据加载到ServletContext中缓存起来. 系统初始化类需要实现两个接口: ServletContex ...
- 详解linux系统的启动过程及系统初始化
一.linux系统的启动流程 关于linux系统的启动流程我们可以按步进行划分为如下: POST加电自检 -->BIOS(Boot Sequence)-->加载对应引导上的MBR(boot ...
- Ztack学习笔记(2)-系统初始化分析
main函数先执行初始化工作,包括硬件.网络层.任务等的初始化. 一 系统初始化 系统初始化函数主要完成内存分配.消息队列头.定时器.电源管理.任务系统及内存栈等的初始化,具体如下代码所示: //os ...
- Linux安装系统注意事项及系统初始化
Linux安装系统注意事项 1.分区 学习用途: /boot:200M /swap :内存的1到2倍 /:根据需要分配大小,比如虚拟机下总空间是15G,那么可以分配8——10G跟/分区,如果是生产 ...
- ucos系统初始化及启动过程
之前在ucos多任务切换中漏掉了一个变量, OSCtxSwCtr标识系统任务切换次数 主要应该还是用在调试功能中 Ucos系统初始化函数为OSInit(),主要完成以下功能 全局变量初始化 就绪任务表 ...
随机推荐
- FastDFS文件管理系统
一.FastDFS介绍 FastDFS 是一个开源的高性能分布式文件系统(DFS). 它的主要功能包括:文件存储,文件同步和文件访问,以及高容量和负载平衡.主要解决了海量数据存储问题,特别适合以中小文 ...
- 原生js关闭窗口
if (navigator.userAgent.indexOf("MSIE") > 0) { if (navigator.userAgent.indexOf("MS ...
- 【jQuery】阶段(插入、复制、替换、删除)
<p>你好!</p> 你最喜欢的水果是? <ul> <li title="苹果">苹果</li> <li titl ...
- jQuery检测判断复选框是否被选中了的几种方法
方法一:if ($("#checkbox-id")get(0).checked) { // do something} 方法二:if($('#checkbox-id').is ...
- python 学习心得
多用类或是函数 我以前写的时候,不用函数,从头写到尾,后来,要改成函数,也是要花很多测试的时间,改的话还得一个调试,如果一开始就用函数的话,就能节省很多时间. 函数的功能尽可能的小 比如说像我用try ...
- Python学习笔记:Matplotlib(数据可视化)
Matplotlib是一个可以将数据绘制为图形表示的Python三方库,包括线性图(折线图,函数图).柱形图.饼图等基础而直观的图形,在平常的开发当中需要绘图时就非常有用了. 安装:pip insta ...
- 基于appium的app自动化测试框架
基于appium框架的app自动化测试 App自动化测试主要难点在于环境的搭建,appium完全是基于selenium进行的扩展,所以app测试框架也是基于web测试框架开发的 一.设备连接 (即构建 ...
- SpringMVC使用注解@RequestMapping映射请求
pringMVC通过使用@RequestMapping注解,实现指定控制器可以处理哪些URL请求. 控制器的类定义及方法定义处都可以标注@RequestMapping: 类定义处:提供初步的请求映射信 ...
- Dragger 2遇到的坑 Dragger2详解 Dragger2学习最好的资料
我是曹新雨,我为自己代言.现在的菜鸟,3年以后我就是大神.为自己加油.微信:aycaoxinyu Dragger2是什么,我就不再说了.资料一堆,而且里面的注解什么意思,我推荐两篇文章,这两篇都是我精 ...
- app图标
1.http://www.iconfont.cn/ 在里面可以搜索你想要的图标: 比如关闭. 2.选择一个好看的下载png 3.打开ps,ctrl n新建一个图层. 把你下载的png弄到上面,然后关闭 ...