设为首页 收藏本站
查看: 1549|回复: 0

[经验分享] SaltStack实战

[复制链接]

尚未签到

发表于 2018-7-31 08:15:02 | 显示全部楼层 |阅读模式
[root@linux-node1 base]# pwd  /srv/salt/base
  [root@linux-node1 base]# mkdir init/files -p
  1、关闭selinux
  #使用了file模块的managed方法
  [root@linux-node1 init]# vim selinux.sls
  selinux-config:
  file.managed:
  - name: /etc/selinux/config
  - source: salt://salt/init/files/selinux-config
  - user: root
  - group: root
  - mode: 0644
  [root@linux-node1 init]# cp /etc/selinux/config files/selinux-config
  2、关闭firewalld
  #使用service模块的dead方法,直接关闭firewalld,并禁止开机启动
  [root@linux-node1 init]# vim firewalld.sls
  firewall-stop:
  service.dead:
  - name: firewalld.service
  - enable: False
  3、时间同步
  #先使用pkg模块安装ntp服务,再使用cron模块加入计划任务
  [root@linux-node1 init]# vim ntp.sls
  ntp-install:
  pkg.installed:
  - name: ntpdate
  cron-ntpdate:
  cron.present:
  - name: ntpdate time1.aliyun.com
  - user: root
  - minute: 5
  4、修改文件描述符
  #使用file模块的managed方法
  [root@linux-node1 init]# vim limit.sls
  limit-config:
  file.managed:
  - name: /etc/security/limits.conf
  - source: salt://init/files/limits.conf
  - user: root
  - group: root
  - mode: 0644
  [root@linux-node1 init]# cp /etc/security/limits.conf files/
  [root@linux-node1 init]# echo "*               -       nofile          65535
  " >> files/limits.conf
  5、内核优化
  #使用sysctl模块的present方法,此处演示一部分,这里没有使用name参数,所以id就相当于是name
  [root@linux-node1 init]# vim sysctl.sls
  net.ipv4.tcp_fin_timeout:
  sysctl.present:
  - value: 2
  net.ipv4.tcp_tw_reuse:
  sysctl.present:
  - value: 1
  net.ipv4.tcp_tw_recycle:
  sysctl.present:
  - value: 1
  net.ipv4.tcp_syncookies:
  sysctl.present:
  - value: 1
  net.ipv4.tcp_keepalive_time:
  sysctl.present:
  - value: 600
  6、SSH服务优化
  #使用file.managed和service.running以及watch,对ssh服务进行优化配置
  [root@linux-node1 init]# vim sshd.sls
  sshd-config:
  file.managed:
  - name: /etc/ssh/sshd_config
  - source: salt://init/files/sshd_config
  - user: root
  - gourp: root
  - mode: 0600
  service.running:
  - name: sshd
  - enable: True

  ->  - watch:
  - file: sshd-config
  [root@linux-node1 init]# cp /etc/ssh/sshd_config files/
  [root@linux-node1 init]# vim files/sshd_config
  Port 8022
  UseDNS no
  PermitRootLogin no
  PermitEmptyPasswords no
  GSSAPIAuthentication no
  7、精简开机启动的系统服务
  #举例关闭postfix开机自启动
  [root@linux-node1 init]# vim thin.sls
  postfix:
  service.dead:
  - enable: False
  8、DNS解析
  [root@linux-node1 init]# vim dns.sls
  dns-config:
  file.managed:
  - name: /etc/resolv.conf
  - source: salt://init/files/resolv.conf
  - user: root
  - group: root
  - mode: 644
  [root@linux-node1 init]# cp /etc/resolv.conf files/
  9、历史记录优化history
  #使用file.append扩展修改HISTTIMEFORMAT的值
  [root@linux-node1 init]# vim history.sls
  history-config:
  file.append:
  - name: /etc/profile
  - text:
  - export HISTTIMEFORMAT="%F %T `whoami` "
  - export HISTSIZE=5
  - export HISTFILESIZE=5
  10、设置终端超时时间
  #使用file.append扩展修改TMOUT环境变量的值
  [root@linux-node1 init]# vim tty-timeout.sls
  ty-timeout:
  file.append:
  - name: /etc/profile
  - text:
  - export TMOUT=300
  11、配置yum源
  #拷贝yum源
  [root@linux-node1 init]# vim yum-repo.sls
  /etc/yum.repos.d/epel.repo:
  file.managed:
  - source: salt://init/files/epel.repo
  - user: root
  - group: root
  - mode: 0644
  12、安装各种agent(如安装zabbix-agent)
  #相当于一个软件的安装、配置、启动,此处也使用了jinja模板和pillar
  [root@linux-node1 base]# mkdir zabbix
  [root@linux-node1 base]# vim zabbix/zabbix-agent.sls
  zabbix-agent:
  pkg.installed:
  - name: zabbix22-agent
  file.managed:
  - name: /etc/zabbix_agentd.conf
  - source: salt://zabbix/files/zabbix_agentd.conf
  - template: jinja
  - defaults:
  ZABBIX-SERVER: {{ pillar['zabbix-agent']['Zabbix_Server'] }}
  - require:
  - pkg: zabbix-agent
  service.running:
  - enable: True
  - watch:
  - pkg: zabbix-agent
  - file: zabbix-agent
  zabbix_agent.conf.d:
  file.directory:
  - name: /etc/zabbix_agentd.conf.d
  - watch_in:
  - service: zabbix-agent
  - require:
  - pkg: zabbix-agent
  - file: zabbix-agent
  [root@linux-node1 srv]# vim pillar/base/zabbix.sls
  zabbix-agent:
  Zabbix_Server: 192.168.56.11
  13、基础用户
  #增加基础管理用户www,使用user.present和group.present
  [root@linux-node1 init]# vim user-www.sls
  www-user-group:
  group.present:
  - name: www
  - gid: 1000
  user.present:
  - name: www
  - fullname: www
  - shell: /sbin/bash
  - uid: 1000
  - gid: 1000
  14、常用基础命令
  #这里因为各软件包会依赖源,所以使用include讲yum源包含进来,并在pkg.installed最后增加require依赖
  [root@linux-node1 init]# vim pkg-base.sls
  include:
  - init.yum-repo
  base-install:
  pkg.installed:
  - pkgs:
  - screen
  - lrzsz
  - tree
  - openssl
  - telnet
  - iftop
  - iotop
  - sysstat
  - wget
  - dos2unix
  - lsof
  - net-tools
  - mtr
  - unzip
  - zip
  - vim
  - bind-utils
  - require:
  - file: /etc/yum.repos.d/epel.repo
  15、用户登录提示、PS1的修改
  [root@linux-node1 init]# vim tty-ps1.sls
  /etc/bashrc:
  file.append:
  - text:
  - export PS1=' [\u@\h \w]\$ '
  16、编写一个总的状态,并写入top file中
  #将所有初始化所需要的功能编写完成,每个小功能都是一个sls文件,统一放在init目录下。此时再使用include把这些初始化的功能都包含进来。
  [root@linux-node1 init]# vim init-all.sls
  include:
  - init.dns
  - init.yum-repo
  - init.firewalld
  - init.history
  - init.limit
  - init.ntp
  - init.pkg-base
  - init.selinux
  - init.sshd
  - init.sysctl
  - init.thin
  - init.tty-timeout
  - init.tty-ps1
  - init.user-www
  #在top.sls里面给Minion指定状态并执行,强烈建议先测试,确定SaltStack会执行哪些操作然后再应用状态到服务器上
  [root@linux-node1 base]# vim top.sls
  base:
  '*':
  - init.init-all
  [root@linux-node1 base]# salt '*' state.highstate test=True
  [root@linux-node1 base]# salt '*' state.highstate

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-543847-1-1.html 上篇帖子: saltstack源码安装nginx-llliii的博客 下篇帖子: Saltstack-4:数据系统pillar
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表