一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

基于Python 2.7使用pip安装 SaltStack的方法

时间:2022-06-30 21:09:14 编辑:袖梨 来源:一聚教程网


首先安装 Python 2.7.10

yum -y install perl-ExtUtils-Embed.x86_64 libxml2 libxml2-devel libxslt libxslt-devel libffi libffi-devel build-essential autoconf libtool gcc git libaio libaio-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libicu libicu-devel openldap openldap-devel libmcrypt libmcrypt-devel openssl openssl-devel ncurses.x86_64 ncurses-devel.x86_64 sqlite-devel bzip2-devel libdbi-devel 

 

wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz

tar xf Python-2.7.10.tgz

cd Python-2.7.10

./configure --prefix=/usr/local/python2.7

make

make install

 

vim /root/.bash_profile

----------------------------------------------

PATH=$PATH:$HOME/bin:/usr/local/python2.7/bin/     # 修改 PATH 变量,将 Python 可执行目录加入环境变量

----------------------------------------------

source .bash_profile

 

wget https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg

sh setuptools-0.6c11-py2.7.egg

 

wget https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz#md5=01026f87978932060cc86c1dc527903e

tar xf pip-1.5.6.tar.gz

cd pip-1.5.6

/usr/local/python2.7/bin/python2.7 setup.py install

 

pip install pip --upgrade

pip install setuptools --upgrade

如果使用的是国内主机,使用 pip 安装模块的话会比较慢,可以使用国内 pip 源来安装,这里使用的是中科大 pip 源

mkdir /root/.pip     # 如果目录不存在,则建立此目录

vim /root/.pip/pip.conf

 

[global]

index-url = https://pypi.mirrors.ustc.edu.cn/simple     # 源地址,末尾需要加上 /simple

[install]

trusted-host=pypi.mirrors.ustc.edu.cn     # 如果使用 https 方式,需要此参数

安装 SaltStack 依赖系统软件包

yum -y install libyaml m2crypto openpgm pciutils yum-utils zeromq3

安装 SaltStack 依赖 Python 模块

pip install babel

pip install chardet

pip install crypto

pip install jinja2

pip install ordereddict

pip install requests

pip install six

pip install urllib3

pip install zmq

pip install backports.ssl_match_hostname

pip install M2Crypto

pip install pycrypto

安装 SaltStack

pip install salt

至此 SaltStack 基于 Python 2.7.10 安装完成,完成后为了使用方便,为服务添加 init.d 脚本

master 端脚本

#!/bin/sh
#
# Salt master
###################################
# LSB header
### BEGIN INIT INFO
# Provides:          salt-master
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Salt master control daemon
# Description:       This is a daemon that controls the Salt minions.
### END INIT INFO

# chkconfig header
# chkconfig: 345 96 05
# description:  This is a daemon that controls the Salt minions
#
# processname: /usr/bin/salt-master

DEBIAN_VERSION=/etc/debian_version
SUSE_RELEASE=/etc/SuSE-release
# Source function library.
if [ -f $DEBIAN_VERSION ]; then
   break   
elif [ -f $SUSE_RELEASE -a -r /etc/rc.status ]; then
    . /etc/rc.status
else
    . /etc/rc.d/init.d/functions
fi
# Default values (can be overridden below)
SALTMASTER=/usr/local/python2.7/bin/salt-master
PYTHON=/usr/local/python2.7/bin/python2.7
MASTER_ARGS=""
if [ -f /etc/default/salt ]; then
    . /etc/default/salt
fi
SERVICE=salt-master
PROCESS=salt-master
RETVAL=0
start() {
    echo -n $"Starting salt-master daemon: "
    if [ -f $SUSE_RELEASE ]; then
        startproc -f -p /var/run/$SERVICE.pid $SALTMASTER -d $MASTER_ARGS
        rc_status -v
    elif [ -e $DEBIAN_VERSION ]; then
        if [ -f $LOCKFILE ]; then
            echo -n "already started, lock file found" 
            RETVAL=1
        elif $PYTHON $SALTMASTER -d $MASTER_ARGS >& /dev/null; then
            echo -n "OK"
            RETVAL=0
        fi
    else
        daemon --check $SERVICE $SALTMASTER -d $MASTER_ARGS
    fi
    RETVAL=$?
    echo
    return $RETVAL
}
stop() {
    echo -n $"Stopping salt-master daemon: "
    if [ -f $SUSE_RELEASE ]; then
        killproc -TERM $SALTMASTER
        rc_status -v
    elif [ -f $DEBIAN_VERSION ]; then
        # Added this since Debian's start-stop-daemon doesn't support spawned processes
        if ps -ef | grep "$PYTHON $SALTMASTER" | grep -v grep | awk '{print $2}' | xargs kill &> /dev/null; then
            echo -n "OK"
            RETVAL=0
        else
            echo -n "Daemon is not started"
            RETVAL=1
        fi
    else
        killproc $PROCESS
    fi
    RETVAL=$?
    echo
}
restart() {
   stop
   start
}
# See how we were called.
case "$1" in
    start|stop|restart)
        $1
        ;;
    status)
        if [ -f $SUSE_RELEASE ]; then
            echo -n "Checking for service salt-master "
            checkproc $SALTMASTER
            rc_status -v
        elif [ -f $DEBIAN_VERSION ]; then
            if [ -f $LOCKFILE ]; then
                RETVAL=0
                echo "salt-master is running."
            else
                RETVAL=1
                echo "salt-master is stopped."
            fi
        else
            status $PROCESS
            RETVAL=$?
        fi
        ;;
    condrestart)
        [ -f $LOCKFILE ] && restart || :
        ;;
    reload)
        echo "can't reload configuration, you have to restart it"
        RETVAL=$?
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
        exit 1
        ;;
esac
exit $RETVAL

 

minion 端脚本

#!/bin/sh
#
# Salt minion
###################################
# LSB header
### BEGIN INIT INFO
# Provides:          salt-minion
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Salt minion daemon
# Description:       This is the Salt minion daemon that can be controlled by the
#                    Salt master.
### END INIT INFO

# chkconfig header
# chkconfig: 345 97 04
# description:  This is the Salt minion daemon that can be controlled by the Salt master.
#
# processname: /usr/bin/salt-minion

DEBIAN_VERSION=/etc/debian_version
SUSE_RELEASE=/etc/SuSE-release
# Source function library.
if [ -f $DEBIAN_VERSION ]; then
   break
elif [ -f $SUSE_RELEASE -a -r /etc/rc.status ]; then
    . /etc/rc.status
else
    . /etc/rc.d/init.d/functions
fi
# Default values (can be overridden below)
SALTMINION=/usr/local/python2.7/bin/salt-minion
PYTHON=/usr/local/python2.7/bin/python2.7
MINION_ARGS=""
if [ -f /etc/default/salt ]; then
    . /etc/default/salt
fi
SERVICE=salt-minion
PROCESS=salt-minion
RETVAL=0
start() {
    echo -n $"Starting salt-minion daemon: "
    if [ -f $SUSE_RELEASE ]; then
        startproc -f -p /var/run/$SERVICE.pid $SALTMINION -d $MINION_ARGS
        rc_status -v
    elif [ -e $DEBIAN_VERSION ]; then
        if [ -f $LOCKFILE ]; then
            echo -n "already started, lock file found"
            RETVAL=1
        elif $PYTHON $SALTMINION -d $MINION_ARGS >& /dev/null; then
            echo -n "OK"
            RETVAL=0
        fi
    else
        if [[ ! -z "$(pidofproc -p /var/run/$SERVICE.pid $PROCESS)" ]]; then
            RETVAL=$?
            echo -n "already running"
        else
            daemon --check $SERVICE $SALTMINION -d $MINION_ARGS
        fi
    fi
    RETVAL=$?
    echo
    return $RETVAL
}
stop() {
    echo -n $"Stopping salt-minion daemon: "
    if [ -f $SUSE_RELEASE ]; then
        killproc -TERM $SALTMINION
        rc_status -v
        RETVAL=$?
    elif [ -f $DEBIAN_VERSION ]; then
        # Added this since Debian's start-stop-daemon doesn't support spawned processes
        if ps -ef | grep "$PYTHON $SALTMINION" | grep -v grep | awk '{print $2}' | xargs kill &> /dev/null; then
            echo -n "OK"
            RETVAL=0
        else
            echo -n "Daemon is not started"
            RETVAL=1
        fi
    else
        killproc $PROCESS
        RETVAL=$?
    fi
    echo
}
restart() {
   stop
   start
}
# See how we were called.
case "$1" in
    start|stop|restart)
        $1
        ;;
    status)
        if [ -f $SUSE_RELEASE ]; then
            echo -n "Checking for service salt-minion "
            checkproc $SALTMINION
            rc_status -v
        elif [ -f $DEBIAN_VERSION ]; then
            if [ -f $LOCKFILE ]; then
                RETVAL=0
                echo "salt-minion is running."
            else
                RETVAL=1
                echo "salt-minion is stopped."
            fi
        else
            status $PROCESS
            RETVAL=$?
        fi
        ;;
    condrestart)
        [ -f $LOCKFILE ] && restart || :
        ;;
    reload)
        echo "can't reload configuration, you have to restart it"
        RETVAL=$?
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
        exit 1
        ;;
esac
exit $RETVAL

热门栏目