SaltStack salt-minion安装实践

StaltStack 应用场景

当使用terraform构建基础组件,或者基于AWS user date进行saltstack安装时,进行如下条件安装:

  1. 原始机器中安装了salt-minion,可能版本不统一或者版本较低(如果是在新的环境下安装,需要调整安装脚本的顺序,先安装salt-minion,后配置和重启)
  2. SaltStack salt-minion 安装自动化
  3. 对salt-minion进行统一配置
    下面的脚本可用于在centos上自动安装和配置salt-minion,可以根据此脚本修改为其它环境的安装。

SaltStack 安装脚本完整源码

#!/bin/bash

systemctl stop salt-minion
sleep 5
systemctl restart rsyslog

echo "master: 10.23.3.227" >> /etc/salt/minion.d/master.conf
echo `hostname` > /etc/salt/minion_id
echo "environment: water" >> /etc/salt/minion.d/environment.conf
echo "pillarenv: water" >> /etc/salt/minion.d/environment.conf

echo "hostname: `hostname`" >> /etc/salt/grains
echo "env: production" >> /etc/salt/grains
echo "location: x" >> /etc/salt/grains
echo "project: water" >> /etc/salt/grains
echo "app: water" >> /etc/salt/grains
echo "service: water" >> /etc/salt/grains

echo "startup_states: highstate" >> /etc/salt/minion.d/startup.conf

yum remove -y salt
yum remove -y salt-minion

cat > /etc/yum.repos.d/saltstack-rhel7.repo << EOF
[saltstack-rhel7]
gpgcheck=0
enabled=1
baseurl=https://arti.ss.aws.fwmrm.net/saltstack-7-x86_64-2017.7/
name=saltstack-rhel7
EOF

yum clean all
yum install -y salt-minion

sleep 5
systemctl start salt-minion

SaltStack安装脚本分析

安装

移除原有saltstack并安装

systemctl stop salt-minion
sleep 5
systemctl restart rsyslog
yum remove -y salt
yum remove -y salt-minion
cat > /etc/yum.repos.d/saltstack.repo << 'EOF'
[saltstack-repo]
name=SaltStack repo for Red Hat Enterprise Linux $releasever
baseurl=https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest
enabled=1
gpgcheck=1
gpgkey=https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest/SALTSTACK-GPG-KEY.pub
       https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest/base/RPM-GPG-KEY-CentOS-7
EOF

yum clean all
yum install -y salt-minion
sleep 5
systemctl start salt-minion

rsyslog是比syslog功能更强大的日志记录系统,可以将日志输出到文件,数据库和其它程序。
不使用此日志系统的机器,可以跳过此步

使用自定义的repo

如果需要对salt-minion的安装源进行控制,可以添加适合自己的saltstack centos repo, 例如,

cat > /etc/yum.repos.d/saltstack-rhel7.repo << EOF
[saltstack-rhel7]
gpgcheck=0
enabled=1
baseurl=https://${your repo host domain}/saltstack-7-x86_64-2017.7/
name=saltstack-rhel7
EOF

配置

基础配置

基础配置可以放在minion的配置文件/etc/salt/minion中,也可以单独放在/etc/salt/minion.d/目录中( default_include)

echo "master: 10.23.3.227" >> /etc/salt/minion.d/master.conf
echo `hostname` > /etc/salt/minion_id
echo "environment: water" >> /etc/salt/minion.d/environment.conf
echo "pillarenv: water" >> /etc/salt/minion.d/environment.conf
  1. master 用于配置saltstack master 地址
  2. minion_id 用于配置minion的唯一标示
  3. environment 用于配置salt-minion匹配的salt环境
  4. pillarenv 用于配置salt-minion匹配的pillar环境

grains 配置

grains的配置可以放在minion的配置文件/etc/salt/minion中,也可以单独放在/etc/salt/grains中(grains配置)

echo "hostname: `hostname`" >> /etc/salt/grains
echo "env: production" >> /etc/salt/grains
echo "location: x" >> /etc/salt/grains
echo "project: water" >> /etc/salt/grains
echo "app: water" >> /etc/salt/grains
echo "service: water" >> /etc/salt/grains

env用于区分环境, 例如,dev, stg, prd
location用于扩展
project用于区分不同的工程
app用于区分不同的产品
service用于区分产品中不同的服务

参考

  1. 配置salt-minion
  2. default_include
  3. 安装详细步骤
  4. centos安装
  5. centos repo文件中变量解释
  6. 避免heredoc中的变量扩展
  7. grains配置

你可能感兴趣的:(SaltStack salt-minion安装实践)