• SaltStack 02-SaltStack安装配置(yum安装)


    环境说明

    主机名 IP地址 模式 系统
    saltStack01 10.123.209.34 master Centos 7
    centos6 10.123.209.41 minion Centos 6

    1.安装salt-master和salt-minion

    [root@saltStack01 ~]# yum install -y salt-master salt-minion
    [root@centos6 ~]# yum install -y salt-minion
    

    2.启动salt-master

    [root@saltStack01 ~]# systemctl start salt-master
    

    3、配置salt-minion

    # 可以是主机名需要解析(指定服务端的IP地址),冒号有空格
    [root@centos6 salt]# sed '16a master: 10.123.209.34' /etc/salt/minion -i
    [root@centos6 salt]# cat /etc/salt/minion |grep -v '^#' |grep master:   
    master: 10.123.209.34
    
    # id:唯一标识符,可以不配,不配默认就是主机名
    [root@centos6 salt]# sed -i "79a id: centos6 /etc/salt/minion
    

    4、启动salt-minion

    [root@saltStack01 ~]# systemctl start salt-minion 
    [root@centos6 salt]# service salt-minion start
    

    5、配置salt-master和slat-minion通信

    [root@linux-node1 salt]# salt-key
    Accepted Keys:       	# 同意的
    Denied Keys:         	# 拒绝的
    Unaccepted Keys:     	# 等待同意的
    saltStack01
    centos6
    Rejected Keys:
    

    同意认证的方法分为三种

    salt-key -A
    salt-key -a 指定id
    salt-key -a 支持通配符
    

    salt-key 命令参数简单介绍

    • -L --列出所有
    • -d --删除指定的支持通配符
    • -D --删除所有
    • -A --添加所有
    • -a --指定添加

    salt-key 同意之后生成的文件

    pki/
    ├── master
    │   ├── master.pem
    │   ├── master.pub
    │   ├── minions
    │   │   ├── saltStack01
    │   │   └── centos6
    │   ├── minions_autosign
    │   ├── minions_denied
    │   ├── minions_pre
    │   └── minions_rejected
    └── minion
        ├── minion_master.pub  # 同意之后master发送公钥
        ├── minion.pem
        └── minion.pub
    

    6、修改id配置

    • minion配置中有一个id配置,默认是hostname
    • 如果id配置和hostname不一致会导致无法进行通信

    关闭salt-minion

    • 此处必须先停掉minion修改,并删除相应的文件,否则会默认地去查找原先的配置
    CentOS7:systemctl stop salt-minion
    CentOS6:service salt-minion stop
    

    在master上删除minion的id

    salt-key -d id
    

    minion上删除pki目录

    rm -rf /etc/salt/pki
    

    minion上删除minion_id文件

    rm -rf /etc/salt/minion_id
    

    修改完成,启动minion

    CentOS7:systemctl start salt-minion
    CentOS6:service salt-minion start
    

    salt-minion修改id脚本

    #!/bin/bash
    # liangjingfu
    
    # 判断是否传参
    if [[ $# == 0 ]]; then
    	echo "please input id content!"
    	exit 1
    else
    	id=$1
    fi
    
    # 判断系统版本,目前只是判断系统是否为centos6、centos7
    issix=`cat /etc/redhat-release | grep 6.`
    isseven=`cat /etc/redhat-release | grep 7.`
    
    if [[ -n ${issix} ]]; then
    	sysType=6
    elif [[ -n ${isseven} ]]; then
    	sysType=7
    fi
    
    # 根据系统版本关闭salt-minion
    stop_salt_minion(){
    	if [[ ${sysType} == 6 ]]; then
    		service salt-minion stop
    	elif [[ ${sysType} == 7 ]]; then
    		systemctl stop salt-minion
    	fi
    }
    
    # 删除相应文件
    rm_file(){
    	if [[ -d "/etc/salt/pki"  ]]; then
    		rm -rf /etc/salt/pki
    	fi
    
    	if [[ -f "/etc/salt/minion_id" ]]; then
    		rm -rf /etc/salt/minion_id
    	fi
    }
    
    # 修改salt-minion配置文件id
    mv_id(){
    	isid=`cat /etc/salt/minion |grep -v '^#' |grep 'id:'`
    	if [[ -z $isid ]]; then
    		sed -i "79a id: ${id}" /etc/salt/minion
    	elif [[ -n $isid ]]; then
    		sed -i "s#${isid}#id: ${id}#g" /etc/salt/minion
    	fi
    }
    
    # 根据系统版本开启salt-minion
    start_salt_minion(){
    	if [[ ${sysType} == 6 ]]; then
    		service salt-minion start
    	elif [[ ${sysType} == 7 ]]; then
    		systemctl start salt-minion
    	fi
    }
    
    # 运行方法
    stop_salt_minion
    rm_file
    mv_id
    start_salt_minion
    
    运行方式:
    sh saltminionid.sh 10.123.209.41-centos6.liang.com
    
  • 相关阅读:
    ModuleNotFoundError: No module named 'rest_framework_swagger'
    ModuleNotFoundError: No module named 'suit'
    HTTPS连接的前几毫秒发生了什么
    网络通信之 字节序转换原理与网络字节序、大端和小端模式
    聊聊HTTPS和SSL/TLS协议
    ECShop 调用自定义广告
    ECSHOP商城网站建设之自定义调用广告方法(二)
    https原理:证书传递、验证和数据加密、解密过程解析
    图解openssl实现私有CA
    SSL/TLS协议运行机制的概述
  • 原文地址:https://www.cnblogs.com/liangjingfu/p/9492450.html
Copyright © 2020-2023  润新知