基於Python 2.7使用pip安裝 SaltStack的方法

來源:互聯網
上載者:User


首先安裝 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.tgztar xf Python-2.7.10.tgzcd Python-2.7.10./configure --prefix=/usr/local/python2.7makemake 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.eggsh setuptools-0.6c11-py2.7.egg wget https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz#md5=01026f87978932060cc86c1dc527903etar xf pip-1.5.6.tar.gzcd pip-1.5.6/usr/local/python2.7/bin/python2.7 setup.py install pip install pip --upgradepip 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 babelpip install chardetpip install cryptopip install jinja2pip install ordereddictpip install requestspip install sixpip install urllib3pip install zmqpip install backports.ssl_match_hostnamepip install M2Cryptopip 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-masterDEBIAN_VERSION=/etc/debian_versionSUSE_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.statuselse    . /etc/rc.d/init.d/functionsfi# Default values (can be overridden below)SALTMASTER=/usr/local/python2.7/bin/salt-masterPYTHON=/usr/local/python2.7/bin/python2.7MASTER_ARGS=""if [ -f /etc/default/salt ]; then    . /etc/default/saltfiSERVICE=salt-masterPROCESS=salt-masterRETVAL=0start() {    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        ;;esacexit $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-minionDEBIAN_VERSION=/etc/debian_versionSUSE_RELEASE=/etc/SuSE-release# Source function library.if [ -f $DEBIAN_VERSION ]; then   breakelif [ -f $SUSE_RELEASE -a -r /etc/rc.status ]; then    . /etc/rc.statuselse    . /etc/rc.d/init.d/functionsfi# Default values (can be overridden below)SALTMINION=/usr/local/python2.7/bin/salt-minionPYTHON=/usr/local/python2.7/bin/python2.7MINION_ARGS=""if [ -f /etc/default/salt ]; then    . /etc/default/saltfiSERVICE=salt-minionPROCESS=salt-minionRETVAL=0start() {    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        ;;esacexit $RETVAL

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.