1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#!/bin/sh
PATH=
/sbin
:
/bin
:
/usr/sbin
:
/usr/bin
:
/usr/local/bin
:
/usr/local/sbin
SRV_PORT=
"9876"
## 端口号
SRV_PROT=
"tcp"
## 协议类型
SRV_NAME=
"rocketmq_nameserver"
## 服务名
## 是否已正确扫描
SCAN_FLAG=0
for
ETH_NAME
in
`
/sbin/ifconfig
|
grep
eth1 |
awk
'{print $1}'
`
do
ETH1_ADDR=`
/sbin/ifconfig
${ETH_NAME} |
awk
-F
':'
'/inet addr/{print $2}'
|
sed
's/[a-zA-Z ]//g'
`
[[ -z
"${ETH1_ADDR}"
]] &&
continue
||
break
done
TMP_SRV_PROT=`
echo
${SRV_PROT} |
tr
'[A-Z]'
'[a-z]'
`
if
[[
"${TMP_SRV_PROT}"
==
"tcp"
]];
then
PROT_OPT=
"S"
elif
[[
"${TMP_SRV_PROT}"
==
"udp"
]];
then
PROT_OPT=
"U"
else
echo
"未知的协议类型!"
&& exit1
fi
## 最多扫描3次,成功一次即可,以避免网络抖动而导致误判
for
((i=0; i<3; i++));
do
RETVAL=`
/usr/bin/nmap
-n -s${PROT_OPT} -p ${SRV_PORT} ${ETH1_ADDR} |
grep
open
`
[[ -n
"${RETVAL}"
]] && SCAN_FLAG=1;
break
||
sleep
10
done
if
[[ ${SCAN_FLAG} -
ne
1 ]];
then
[[ -n `
ps
aux |
grep
java |
grep
namesrv` ]] &&
kill
-9 `
ps
aux |
grep
java |
awk
'/namesrv/{print $2}'
`
cd
/usr/local/rocketmq/bin
&&
nohup
sh mqnamesrv &
fi
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#!/bin/sh
PATH=
/sbin
:
/bin
:
/usr/sbin
:
/usr/bin
:
/usr/local/bin
:
/usr/local/sbin
SRV_PORT=
"10911"
## 端口号
SRV_PROT=
"tcp"
## 协议类型
SRV_NAME=
"rocketmq_brokerserver"
## 服务名
## 是否已正确扫描
SCAN_FLAG=0
for
ETH_NAME
in
`
/sbin/ifconfig
|
grep
eth1 |
awk
'{print $1}'
`
do
ETH1_ADDR=`
/sbin/ifconfig
${ETH_NAME} |
awk
-F
':'
'/inet addr/{print $2}'
|
sed
's/[a-zA-Z ]//g'
`
[[ -z
"${ETH1_ADDR}"
]] &&
continue
||
break
done
TMP_SRV_PROT=`
echo
${SRV_PROT} |
tr
'[A-Z]'
'[a-z]'
`
if
[[
"${TMP_SRV_PROT}"
==
"tcp"
]];
then
PROT_OPT=
"S"
elif
[[
"${TMP_SRV_PROT}"
==
"udp"
]];
then
PROT_OPT=
"U"
else
echo
"未知的协议类型!"
&& exit1
fi
## 最多扫描3次,成功一次即可,以避免网络抖动而导致误判
for
((i=0; i<3; i++));
do
RETVAL=`
/usr/bin/nmap
-n -s${PROT_OPT} -p ${SRV_PORT} ${ETH1_ADDR} |
grep
open
`
[[ -n
"${RETVAL}"
]] && SCAN_FLAG=1;
break
||
sleep
10
done
if
[[ ${SCAN_FLAG} -
ne
1 ]];
then
[[ -n `
ps
aux |
grep
java |
grep
broker` ]] &&
kill
-9 `
ps
aux |
grep
java |
awk
'/broker/{print $2}'
`
cd
/usr/local/rocketmq/bin
&&
nohup
sh mqbroker -c ..
/conf/2m-noslave/broker-a
.properties &
fi
|