zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    为系统添加语言包
    除掉任务栏上的隐藏小按钮
    叠加多个无线网络
    在win7中通过手机投放媒体
    开关WI-Fi显示列表
    hibernate(二)对象的三种状态、一级缓存、多对一、inverse、cascade
    hibernate(一)helloworld、api、事务、配置文件、映射文件
    SQL Server2019安装
    Windows server2012搭建FTP服务器
    Gradle的使用教程
  • 原文地址:https://www.cnblogs.com/jrri/p/15167956.html
Copyright © 2011-2022 走看看