中间件部署脚本

自动化监控项目中间件

简单的脚本安装

java环境

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
#!/bin/bash

#检查目录
if [ -d /home/path/dir ]; then

echo "ok ";
cd /home/path/dir

#jdk
if [ -f jdk-8u281-linux-x64.tar.gz ];then echo "ok"; mkdir jdk && tar xvf jdk-8u281-linux-x64.tar.gz -C ./jdk ;else echo "jdk-8u281-linux-x64.tar.gz not fond";fi

cd jdk/jdk1.8.0_281/
pwd=$(pwd)
cat >> /etc/profile<<EOF
JAVA_HOME=$(pwd)
CLASSPATH=\$JAVA_HOME/lib
PATH=\$PATH:\$JAVA_HOME/bin
export JAVA_HOME CLASSPATH PATH
EOF

echo "======================================"
source /etc/profile
java -version
cd -
else echo "err";
fi

nginx编译安装

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash

cd /home/path/dir/
mkdir nginx && cd $_
mv ../pcre-8.43.tar.gz ../zlib-1.2.11.tar.gz ../nginx-1.18.0.tar.gz openssl-1.0.2t.tar.gz .
rpm -ivh ./gcc-c++/*.rpm #安装编译工具依赖

# pcre
cd /home/path/dir/nginx
tar xzvf pcre-8.43.tar.gz    
cd /home/path/dir/nginx/pcre-8.43
./configure
make
make install
rpm -qa pcre
cd -

# openssl
cd /home/path/dir/nginx
tar xvf openssl-1.0.2t.tar.gz
cd openssl-1.0.2t
# make && make install
./config shared --prefix=/usr/local --openssldir=/usr/local/ssl
make clean
make && make install
openssl version -a
rpm -qa openssl
cd -

# zlib
cd /home/path/dir/nginx
tar xvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
CFLAGS="-O3 -fPIC" ./configure
make && make install
rpm -qa zlib
cd -

#NG
tar xvf nginx-1.18.0.tar.gz
cd nginx-1.18.0

./configure --prefix=/home/path/dir/nginx/nginx-server \
--with-pcre=/home/path/dir/nginx/pcre-8.43 \
--with-zlib=/home/path/dir/nginx/zlib-1.2.11 \
--with-openssl=/home/path/dir/nginx/openssl-1.0.2t \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/home/path/dir/nginx/nginx-plug/client/ \
--http-proxy-temp-path=/home/path/dir/nginx/nginx-plug/proxy/ \
--http-fastcgi-temp-path=/home/path/dir/nginx/nginx-plug/fcgi/ \
--http-uwsgi-temp-path=/home/path/dir/nginx/nginx-plug/uwsgi \
--http-scgi-temp-path=/home/path/dir/nginx/nginx-plug/scgi \
--with-stream --with-stream_ssl_module

make && make install
sleep 5
echo "======================================"
cd ../nginx-server/
mkdir -p ../nginx-plug/client
./sbin/nginx -t

#config
cd /home/path/dir/nginx/nginx-server
mv conf/nginx.conf conf/nginx.conf.bak
cp ../../script/nginx.conf conf/
./sbin/nginx -s reload
./sbin/nginx -c conf/nginx.conf

nginx配置文件

nginx.conf

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
worker_processes  1;

events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;

upstream tomcat-server {
server 0.0.0.0:18080 weight=1;
server 0.0.0.0:18080 weight=1;
server 0.0.0.0:18080 weight=1;
}

server {
listen 33380;
server_name localhost;
location / {
proxy_pass http://tomcat-server;
}
}
}

tomcat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash

#tomcat
cd /home/path/dir
if [ -f apache-tomcat-x.y.z.tar.gz ];then
mkdir tomcat && tar xvf apache-tomcat-x.y.z.tar.gz -C ./tomcat;
### 配置
cd tomcat/apache-tomcat-x.y.z/
cp conf/server.xml conf/server.xml.bak
sed -i '69s/8080/98080/g' conf/server.xml ### 依据具体行号指定
source /etc/profile

./bin/startup.sh

sleep 5
netstat -nalpt |grep 98080
cd -
else
echo "apache-tomcat-x.y.z.tar.gz not found"
fi

redis

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash

# redis
cd /home/path/dir/
tar xvf redis-x.y.z.tar
cd redis-x.y.z
make
sed -i '50s/6379/36379/g' redis.conf
sed -i '42s/no/yes/g' redis.conf
./src/redis-server redis.conf
echo "====================="
sleep 5
netstat -nalpt |grep 16379
cd /home/path/dir/

mpush

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
#!/bin/bash

#alloc
cd /home/path/dir/
mkdir mpush
tar xvf alloc-release-x.y.z.tar.gz
cd mpush-alloc-x.y.z/
mv conf/mpush.conf conf/mpush.conf.bak
cp /home/path/dir/script/allloc-mpush.conf conf/mpush.conf
cd conf/
chmod +x ../bin/mp.sh
source /etc/profile #need
sleep 3
../bin/mp.sh start
echo "=================================="
ps -ef | grep alloc
sleep 3

#mpush
cd /home/path/dir/mpush
tar xvf ../mpush-release-x.y.z.tar.gz
cd mpush-x.y.z
mv conf/mpush.conf conf/mpush.conf.bak
cp /home/path/dir/script/mpush.conf conf/mpush.conf
cd conf/
source /etc/profile #need
sleep 2
./bin/mp.sh start
echo "===================================="
sleep netstat -nalpt | grep 38088

mpush.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
mp.log-level=warn
mp.core.min-heartbeat=3m
mp.security.private-key="M="
mp.security.public-key="M B"
mp.zk.server-address="127.0.0.1:32181"
mp.redis { //redis 集群配置
nodes:["127.0.0.1:16379"] //格式是ip:port
cluster-model:single //single, cluster
}
mp.net.ws-server-port=0 //websocket对外端口, 0表示禁用websocket
mp.net.gateway-server-net=tcp // 网关服务使用的网络 udp/tcp
mp.net.connect-server-port=38088 //接入服务的端口号
mp.net.public-host-mapping { //本机局域网IP和公网IP的映射关系,请添加实际的IP
//"10.0.10.156":"111.1.32.137" //请修改成实际的IP
//"10.0.10.166":"111.1.33.138" //请修改成实际的IP
}
mp.http.proxy-enabled=true //启用Http代理功能

Zookeeper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash

#Zookeeper
cd /home/path/dir/
source /etc/profile
mkdir -p zookeeper
cd zookeeper

tar xvf ../apache-zookeeper-1.2.3-bin.tar.gz
cd apache-zookeeper-1.2.3-bin/
cp conf/zoo_sample.cfg conf/zoo.cfg
sed -i 's/2181/52181/g' conf/zoo.cfg
./bin/zkServer.sh start
echo "=================="
sleep 5
netstat -nalpt |grep 52181

iptable

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash

##18080
iptables -A INPUT -p tcp --dport 18080 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 18080 -j ACCEPT

iptables -A INPUT -p udp --dport 18080 -j ACCEPT
iptables -A OUTPUT -p udp --sport 18080 -j ACCEPT

##18081
iptables -A INPUT -p tcp --dport 18081 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 18081 -j ACCEPT

iptables -A INPUT -p udp --dport 18081 -j ACCEPT
iptables -A OUTPUT -p udp --sport 18081 -j ACCEPT

##19000
iptables -A INPUT -p tcp --dport 19000 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 19000 -j ACCEPT

iptables -A INPUT -p udp --dport 19000 -j ACCEPT
iptables -A OUTPUT -p udp --sport 19000 -j ACCEPT

## 11180
iptables -A INPUT -p tcp --dport 11180 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 11180 -j ACCEPT

iptables -A INPUT -p udp --dport 11180 -j ACCEPT
iptables -A OUTPUT -p udp --sport 11180 -j ACCEPT

##5206
iptables -A INPUT -p tcp --dport 5206 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 5206 -j ACCEPT

iptables -A INPUT -p udp --dport 5206 -j ACCEPT
iptables -A OUTPUT -p udp --sport 5206 -j ACCEPT

## 18087,18088
iptables -A INPUT -p tcp --dport 18087:18088 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 18087:18088 -j ACCEPT

iptables -A INPUT -p udp --dport 18087:18088 -j ACCEPT
iptables -A OUTPUT -p udp --sport 18087:18088 -j ACCEPT

#DROP##

##18089
iptables -A INPUT -p tcp --dport 18089 -j DROP
iptables -A INPUT -p udp --dport 18089 -j DROP

## 17000,17001
iptables -A INPUT -p tcp --dport 17000:17001 -j DROP
iptables -A INPUT -p udp --dport 17000:17001 -j DROP

##12181
iptables -A INPUT -p tcp --dport 12181 -j DROP
iptables -A INPUT -p udp --dport 12181 -j DROP

##16379
iptables -A INPUT -p tcp --dport 16379 -j DROP
iptables -A INPUT -p udp --dport 16379 -j DROP

##19999
iptables -A INPUT -p tcp --dport 19999 -j DROP
iptables -A INPUT -p udp --dport 19999 -j DROP

##30000
iptables -A INPUT -p tcp --dport 30000 -j DROP
iptables -A INPUT -p udp --dport 30000 -j DROP


service iptables save
iptables -L -n

推荐文章