“Saltstack的配置管理salt.states”的版本间的差异
跳到导航
跳到搜索
(未显示同一用户的13个中间版本) | |||
第87行: | 第87行: | ||
</pre> | </pre> | ||
=salt系统初始化例子= | =salt系统初始化例子= | ||
+ | |||
+ | |||
+ | https://github.com/evan886/saltops | ||
+ | |||
+ | |||
+ | |||
+ | 下面介绍 使用top.sls 入口文件同时对多台服务器进行的配置管理 | ||
+ | |||
+ | salt-master --log-level=debug | ||
+ | |||
+ | == 环境配置 配置file_roots and pillar_roots 正式例子 == | ||
+ | <pre> | ||
+ | # Example: 注意 各空两格下去 级级下去 我搞了半天 呀 一开始 | ||
+ | file_roots: | ||
+ | base: | ||
+ | # - /srv/salt/base | ||
+ | # dev: | ||
+ | # - /srv/salt/dev/services | ||
+ | # - /srv/salt/dev/states | ||
+ | prod: | ||
+ | - /srv/salt/prod/ | ||
+ | # - /srv/salt/prod/states | ||
+ | |||
+ | |||
+ | pillar_roots: | ||
+ | base: | ||
+ | - /srv/pillar/base | ||
+ | # | ||
+ | prod: | ||
+ | - /srv/pillar/prod | ||
+ | |||
+ | |||
+ | mkdir -p /srv/salt/base /srv/salt/prod | ||
+ | |||
+ | mkdir -p /srv/pillar/base /srv/pillar/prod | ||
+ | |||
+ | /etc/init.d/salt-master restart | ||
+ | </pre> | ||
+ | == 系统初始化== | ||
+ | === dns config === | ||
+ | |||
+ | <pre> | ||
+ | cat /srv/salt/base/init/dns.sls | ||
+ | /etc/resolv.conf: | ||
+ | file.managed: | ||
+ | - source: salt://init/files/resolv.conf | ||
+ | - user: root | ||
+ | - group: root | ||
+ | - mode: 644 | ||
+ | |||
+ | |||
+ | cat /srv/salt/base/init/files/resolv.conf | ||
+ | # Generated by NetworkManager | ||
+ | nameserver 192.168.88.1 | ||
+ | nameserver fd67:f843:530::1 | ||
+ | |||
+ | |||
+ | </pre> | ||
+ | |||
+ | ===history记录时间 === | ||
<pre> | <pre> | ||
+ | cat /srv/salt/base/init/history.sls | ||
+ | /etc/bashrc: | ||
+ | file.append: | ||
+ | - text: | ||
+ | - HISTTIMEFORMAT="%F %T `whoamii` " | ||
+ | cmd.run: | ||
+ | - name: source /etc/bashrc | ||
+ | # or | ||
+ | cat /srv/salt/base/init/history.sls | ||
+ | /etc/profile: | ||
+ | file.append: | ||
+ | - text: | ||
+ | - HISTTIMEFORMAT="%F %T `whoamii` " | ||
+ | cmd.run: | ||
+ | - name: source /etc/bashrc | ||
+ | </pre> | ||
+ | |||
+ | ===初始化环境引用 === | ||
+ | <pre> | ||
+ | cat /srv/salt/base/init/env_init.sls | ||
+ | include: | ||
+ | - init.dns | ||
+ | - init.history | ||
+ | |||
+ | |||
+ | tree /srv/salt/base/ | ||
+ | /srv/salt/base/ | ||
+ | ├── init | ||
+ | │ ├── dns.sls | ||
+ | │ ├── dns.slsbak | ||
+ | │ ├── env_init.sls | ||
+ | │ ├── files | ||
+ | │ │ └── resolv.conf | ||
+ | │ └── history.sls | ||
+ | ├── top.sls | ||
+ | |||
+ | |||
+ | cat /srv/salt/base/top.sls | ||
+ | base: | ||
+ | '*': | ||
+ | - init.env_init | ||
+ | |||
+ | salt '*' state.highstate test=True | ||
+ | salt '*' state.highstate | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | =站内资源= | ||
+ | [[Saltstack文件管理]] | ||
+ | |||
+ | = install nginx= | ||
+ | [[saltstack state安装nignx]] | ||
+ | |||
+ | =trouble shooting= | ||
+ | <pre> | ||
+ | trouble | ||
+ | Rendering SLS 'base:init.dns' failed: mapping values are not allowed here; line 2 | ||
+ | |||
+ | cat init/dns.sls | ||
+ | /etc/resolv.conf: 少了这个的原因 ? 老报错 不有 第二行 要空4格 这书本 看起来是空了3格 | ||
+ | file.managed: | ||
+ | - source: salt://init/files/resolv.conf | ||
+ | - user: root | ||
+ | - group: root | ||
+ | - mode: 644 | ||
+ | |||
+ | 参考一下别人发现的错 | ||
</pre> | </pre> | ||
第94行: | 第221行: | ||
https://docs.saltproject.io/en/latest/ref/states/all/salt.states.file.html | https://docs.saltproject.io/en/latest/ref/states/all/salt.states.file.html | ||
+ | |||
+ | [https://www.zhb127.com/archives/saltstack-how-to-use-salt-states.html SaltStack 学习:如何使用配置管理good] | ||
+ | |||
+ | [https://www.cnblogs.com/yanjieli/p/10877258.html SaltStack--配置管理 ] | ||
[https://blog.csdn.net/weixin_30266829/article/details/95576657 Salt 系统初始化] | [https://blog.csdn.net/weixin_30266829/article/details/95576657 Salt 系统初始化] | ||
[https://www.jianshu.com/p/65253efcc0a0 saltstack 的日常使用(一)] | [https://www.jianshu.com/p/65253efcc0a0 saltstack 的日常使用(一)] | ||
+ | |||
+ | [https://www.jianshu.com/p/fa3a067b7c1b good saltstack-的日常使用 (二) redis sls] | ||
+ | |||
+ | [https://www.jianshu.com/p/ff70dd688aba saltstack 的日常使用 (三)] | ||
+ | |||
+ | |||
+ | |||
+ | [https://www.cnblogs.com/guigujun/p/8516324.html saltstack 初始化LINUX系统 ] | ||
+ | |||
+ | [https://blog.csdn.net/weixin_30788731/article/details/98583404?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-12.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-12.control saltstack 初始化LINUX系统] | ||
+ | |||
+ | [[category:ops]] [[category:saltstack]] |
2021年9月8日 (三) 04:15的最新版本
目录
最简单的sls state
vim /srv/salt/top.sls #正则匹配 base: '*': - webserver vim /srv/salt/webserver.sls lynx: # 标签定义 pkg: # state declaration - installed # function declaration 第一行被称为(ID declaration) 标签定义,在这里被定义为安装包的名。注意:在不同发行版软件包命名不同,比如 fedora 中叫httpd的包 Debian/Ubuntu中叫apache2 第二行被称为(state declaration)状态定义, 在这里定义使用(pkg state module) 第三行被称为(function declaration)函数定义, 在这里定义使用(pkg state module)调用 installed 函数 salt '*' state.highstate -v test=True salt '*' state.highstate 2.9 配置管理从这里开始 p27 1.查看支持的所有states 列表 salt 'gitlabzbx' sys.list_state_modules gitlabzbx: - alias - alternatives - apt - archive - artifactory - beacon - bigip 5. 从一个简单的实例理解states cat /srv/salt/one.sls /tmp/foo.conf: file.managed: - source: salt://foo.conf - user: root - group: root - mode: 644 - backup: minion root@myxp:~# echo "salt books" > /srv/salt/foo.conf 这样就把 master上的 /src/salt/foo.conf 分发到 minon的 /tmp/foo.conf root@myxps:/srv/salt# salt '*' state.sls one zbxAgent: ---------- ID: /tmp/foo.conf Function: file.managed Result: True Comment: File /tmp/foo.conf updated Started: 08:31:01.737749 Duration: 45.764 ms Changes: ---------- diff: New file mode: 0644 Summary for zbxAgent ------------ Succeeded: 1 (changed=1) Failed: 0 ------------ Total states run: 1 Total run time: 45.764 ms gitlabzbx: ---------- ID: /tmp/foo.conf
salt系统初始化例子
https://github.com/evan886/saltops
下面介绍 使用top.sls 入口文件同时对多台服务器进行的配置管理
salt-master --log-level=debug
环境配置 配置file_roots and pillar_roots 正式例子
# Example: 注意 各空两格下去 级级下去 我搞了半天 呀 一开始 file_roots: base: # - /srv/salt/base # dev: # - /srv/salt/dev/services # - /srv/salt/dev/states prod: - /srv/salt/prod/ # - /srv/salt/prod/states pillar_roots: base: - /srv/pillar/base # prod: - /srv/pillar/prod mkdir -p /srv/salt/base /srv/salt/prod mkdir -p /srv/pillar/base /srv/pillar/prod /etc/init.d/salt-master restart
系统初始化
dns config
cat /srv/salt/base/init/dns.sls /etc/resolv.conf: file.managed: - source: salt://init/files/resolv.conf - user: root - group: root - mode: 644 cat /srv/salt/base/init/files/resolv.conf # Generated by NetworkManager nameserver 192.168.88.1 nameserver fd67:f843:530::1
history记录时间
cat /srv/salt/base/init/history.sls /etc/bashrc: file.append: - text: - HISTTIMEFORMAT="%F %T `whoamii` " cmd.run: - name: source /etc/bashrc # or cat /srv/salt/base/init/history.sls /etc/profile: file.append: - text: - HISTTIMEFORMAT="%F %T `whoamii` " cmd.run: - name: source /etc/bashrc
初始化环境引用
cat /srv/salt/base/init/env_init.sls include: - init.dns - init.history tree /srv/salt/base/ /srv/salt/base/ ├── init │ ├── dns.sls │ ├── dns.slsbak │ ├── env_init.sls │ ├── files │ │ └── resolv.conf │ └── history.sls ├── top.sls cat /srv/salt/base/top.sls base: '*': - init.env_init salt '*' state.highstate test=True salt '*' state.highstate
站内资源
install nginx
trouble shooting
trouble Rendering SLS 'base:init.dns' failed: mapping values are not allowed here; line 2 cat init/dns.sls /etc/resolv.conf: 少了这个的原因 ? 老报错 不有 第二行 要空4格 这书本 看起来是空了3格 file.managed: - source: salt://init/files/resolv.conf - user: root - group: root - mode: 644 参考一下别人发现的错
see also
https://docs.saltproject.io/en/latest/ref/states/all/salt.states.file.html
good saltstack-的日常使用 (二) redis sls