• salt-minion自动安装与配置


    #!/bin/bash
    
    # 需结合各版本的repo库与yum模板配置文件使用
    
    SCRIPT_DIR=`readlink -f $0|xargs dirname`
    CUR_USER=`whoami`
    # LINUX_V=`cat /etc/redhat-release |awk '{print $3}'`
    LINUX_V=`cat /etc/redhat-release |sed -r "s#.*release ([0-9].[0-9]).?[0-9]{0,5}.*#1#g"`
    REPO_DIR="$SCRIPT_DIR/$REPO_V/"
    
    
    # 前置检查
    function preCheck(){
    	if [[ $CUR_USER == "root" ]]; then
    		echo "[OK] user is $CUR_USER"
    	else
    		echo "[ERROR] user is $CUR_USER,please change to root"
    		exit 1
    	fi
    
    	if [[ ${LINUX_V:0:1} == "6" ]]; then
    		REPO_V="el6"
    		SER_RESTART="service salt-minion restart"
    	elif [[ ${LINUX_V:0:1} == "7" ]]; then
    		REPO_V="el7"
    		SER_RESTART="systemctl restart salt-minion"
    	else
    		REPO_V="el${LINUX_V:0:1}"
    		SER_RESTART="systemctl restart salt-minion"
    	fi
    
    	# 检查本地库,修改repo库配置文件
    	if [[ -e "$REPO_DIR" ]]; then
    		echo "[OK] $REPO_DIR is local repo"
    	else
    		echo "Doesn't has repo directory"
    		exit 1
    	fi
    }
    
    # salt安装状态
    function saltStatus(){
    	saltStatus=`salt-minion --version`
    	if [[ $saltStatus == "" ]]; then
    		return 0
    	else
    		return 1
    	fi
    }
    
    function installMinion(){
    	# 修改配置文件
    	if [[ -e "$REPO_DIR/salt.repo" ]]; then
    		sed -i -e "s#(baseurl=file://).*#1$REPO_DIR#g" ./$REPO_DIR/salt.repo
    		cp $SCRIPT_DIR/$REPO_DIR/salt.repo /etc/yum.repos.d/
    	else
    		echo "No configure file of repo, check it"
    	fi
    
    	# 更新
    	yum repolist
    	yum clean all && yum makecache
    	# yum list salt-minion
    	yum install -y salt-minion
    	# 查看
    	if [[ saltStatus ]]; then
    		echo "salt-minion installed success"
    	else
    		echo "install failed"
    		exit 1
    	fi
    
    }
    
    function configMinion(){
    	echo "==Configing=="
    	cp /etc/salt/minion /etc/salt/minion.bak
    	# 修改文件内容
    	echo 
    "default_include: minion.d/*.conf
    master: 192.68.1.1
    id: `ifconfig $(route -n |grep ^0.0.0.0|awk '{print $8}')|grep -E "inets+"|awk '{print $2}'|sed -r "s#.*:([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}).*#1#g"`
    hash_type: sha256
    log_level_logfile: debug" > /etc/salt/minion
    	
    	$SER_RESTART
    }
    
    
    preCheck
    
    if [[ saltStatus ]]; then
    	configMinion
    else
    	installMinion
    	configMinion
    fi
    
  • 相关阅读:
    常用搜索指令
    chrome浏览器常用快捷键
    倒排文档
    hdu4570Multi-bit Trie (间隙DP)
    HTTP工作原理
    腾讯和58都市“聘请”秘诀是什么?
    Atitit。团队建设--管理最佳实践--如何留住关键人才,防止人才外流 ??
    于Eclipse传导C/C++配置方法开发(20140721新)
    通过京东淘宝的技术发展和技术演进,探索未来的技术和体系结构
    C++ Primer 学习笔记_41_STL实践与分析(15)--先来看看算法【下一个】
  • 原文地址:https://www.cnblogs.com/jrri/p/15167956.html
Copyright © 2020-2023  润新知