CentOS 7 下手动安装salt-minion方法
背景:
1、python 3.6为默认python版本
2、salt-minion默认没有安装
安装方法:
1、CentOS7 默认 systemd-python版本过低
wget http://mirrors.aliyun.com/repo/Centos-7.repo &&yum -y install systemd-python
2、
yum -y install salt-minion
3、
yum install salt-minion
sed -i ‘s/python/python2/’ /usr/bin/salt-minion
sed -i ‘s/python/python2/’ /usr/bin/yum
sed -i ‘s/python/python2/’ /usr/libexec/urlgrabber-ext-down
补充检查
/usr/bin/yum 第一行
#!/usr/bin/python2
/usr/libexec/urlgrabber-ext-down 第一行
#!/usr/bin/python2
4、 设置salt-minion自启动脚本
脚本如下:
vi /etc/init.d/salt-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/bin/salt-minion
PYTHON=/usr/bin/python2
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
S
U
S
E
R
E
L
E
A
S
E
]
;
t
h
e
n
s
t
a
r
t
p
r
o
c
−
f
−
p
/
v
a
r
/
r
u
n
/
SUSE_RELEASE ]; then startproc -f -p /var/run/
SUSERELEASE];thenstartproc−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 KaTeX parse error: Expected 'EOF', got '&' at position 14: MINION_ARGS >&̲ /dev/null; the…(pidofproc -p /var/run/$SERVICE.pid
P
R
O
C
E
S
S
)
"
]
]
;
t
h
e
n
R
E
T
V
A
L
=
PROCESS)" ]]; then RETVAL=
PROCESS)"]];thenRETVAL=?
echo -n “already running”
else
daemon --check $SERVICE $SALTMINION -d
M
I
N
I
O
N
A
R
G
S
f
i
f
i
R
E
T
V
A
L
=
MINION_ARGS fi fi RETVAL=
MINIONARGSfifiRETVAL=?
echo
return $RETVAL
}
stop() {
echo -n $“Stopping salt-minion daemon: "
if [ -f $SUSE_RELEASE ]; then
killproc -TERM
S
A
L
T
M
I
N
I
O
N
r
c
s
t
a
t
u
s
−
v
R
E
T
V
A
L
=
SALTMINION rc_status -v RETVAL=
SALTMINIONrcstatus−vRETVAL=?
elif [ -f KaTeX parse error: Expected 'EOF', got '#' at position 32: …; then #̲ Added this sin…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
P
R
O
C
E
S
S
R
E
T
V
A
L
=
PROCESS RETVAL=
PROCESSRETVAL=?
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
P
R
O
C
E
S
S
R
E
T
V
A
L
=
PROCESS RETVAL=
PROCESSRETVAL=?
fi
;;
condrestart)
[ -f KaTeX parse error: Expected 'EOF', got '&' at position 12: LOCKFILE ] &̲& restart || : …?
;;
*)
echo $“Usage: $0 {start|stop|status|restart|condrestart|reload}”
exit 1
;;
esac
exit $RETVAL
5、替换salt-minion id配置
sed -i “s/1#master:./master: 10.X.X.X/g" /etc/salt/minion
ipaddr=ip addr | grep inet | grep brd | gawk '{print $2}' | awk -F/ '{print $1}' | awk -F. '{print "zb_"$1"-"$2"-"$3"-"$4"_lin"}'
sed -i "s/2#id:./id: $ipaddr/g” /etc/salt/minion
6、服务启动
chmod 755 /etc/init.d/salt-minion
chkconfig salt-minion on
/etc/init.d/salt-minion restart
7、验证
netstat -tan | grep “10.x.x.x”