ubuntu环境mosquitto安装及测试最大连接数

ubuntu环境mosquitto安装及测试最大连接数
1
2
3
4
5
6
7
#!/bin/bash
c=1 -d
while [ $c -le 5000 ]
do
mosquitto_sub -d -t hexiang -k 900 &
(( c++ ))
done
查看连接数
1
netstat -na | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
1
netstat -na|grep ESTAB|grep 1883|wc -l
查看cpu 占用高的线程
1
ps H -eo user,pid,ppid,tid,time,%cpu,cmd --sort=%cpu
结束进程及所有连接
1
kill -9 `ps -ef|grep mosquitto|awk '{print $2}'`
1
2
3
4
#(max processes)
ulimit -u 12000
#(max files)
ulimit -n 12000
windows dos 命令查看 连接数
1
netstat -an|find ":1883" |find  "ESTABLISHED" /c

#####订阅远程主机
mosquitto_sub -h 192.168.11.16 -t hexiang

mosquitto安装错误处理

mosquitto: error while loading shared libraries: libwebsockets.so.4.0.0: cannot open shared object file: No such file or directory

1
sudo ln -s /usr/local/lib64/libwebsockets.so.4.0.0 /usr/lib/libwebsockets.so.4.0.0
mosquitto 脚本安装 for ubuntu
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/sh
#print hello world in the console window
echo -e "开始安装-----------------------------------------------------------"
echo -e "author:hexiang"
echo -e "name:dz.hexiang"
echo -e "mail:472482006@qq.com"
echo -e "初始设置请稍等..."
sleep 3s


echo -e "开始安装wget下载工具"

yum -y install wget


echo -e "开始下载即时通信服务器源码..."
cd /home
wget http://mosquitto.org/files/source/mosquitto-1.4.9.tar.gz
echo -e "开始解压即时通信服务器源码..."
tar -xzvf mosquitto-1.4.9.tar.gz
cd mosquitto-1.4.9;

echo -e "开始进行配置..."

#WITH_SRV ,WITH_UUID,WITH_WEBSOCKETS
sed -i -E "s/^#WITH_SRV:=.*$/WITH_SRV:=yes/g" config.mk
sed -i -E "s/^WITH_SRV:=.*$/WITH_SRV:=yes/g" config.mk

sed -i -E "s/^#WITH_UUID:=.*$/WITH_UUID:=yes/g" config.mk
sed -i -E "s/^WITH_UUID:=.*$/WITH_UUID:=yes/g" config.mk

sed -i -E "s/^#WITH_WEBSOCKETS:=.*$/WITH_WEBSOCKETS:=yes/g" config.mk
sed -i -E "s/^WITH_WEBSOCKETS:=.*$/WITH_WEBSOCKETS:=yes/g" config.mk

echo -e "即时通信配置成功开始安装相关支持库..."
cd /home
wget http://c-ares.haxx.se/download/c-ares-1.10.0.tar.gz
tar xvf c-ares-1.10.0.tar.gz
cd c-ares-1.10.0
./configure
make&make install


apt install libuuid-devel -y
apt install cmake -y
apt install uuid-dev -y

cd /home;
wget https://github.com/warmcat/libwebsockets/archive/v1.3-chrome37-firefox30.tar.gz
tar zxvf v1.3-chrome37-firefox30.tar.gz
cd libwebsockets-1.3-chrome37-firefox30;
mkdir build; cd build;
cmake .. -DLIB_SUFFIX=64
make install



echo -e "即时通信开始编译安装..."
cd /home/mosquitto-1.4.9
make&make install

mv /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf


echo -e "配置相关信息..."
sed -i -E "s/^#autosave_interval 1800$/autosave_interval 1800/g" /etc/mosquitto/mosquitto.conf
sed -i -E "s/^#persistence false$/persistence true/g" /etc/mosquitto/mosquitto.conf
sed -i -E "s/^#persistence_file mosquitto.db$/persistence_file mosquitto.db/g" /etc/mosquitto/mosquitto.conf

sed -i -E "s/^autosave_interval 1800$/#autosave_interval 1800/g" /etc/mosquitto/mosquitto.conf
sed -i -E "s/^persistence true$/#persistence true/g" /etc/mosquitto/mosquitto.conf
sed -i -E "s/^persistence_file mosquitto.db$/#persistence_file mosquitto.db/g" /etc/mosquitto/mosquitto.conf
sed -i -E "s/^persistence_location \/var\/mosquitto\/$/#persistence_location \/var\/mosquitto\//g" /etc/mosquitto/mosquitto.conf
sed -i -E "s/^listener 1883$/#listener 1883/g" /etc/mosquitto/mosquitto.conf
sed -i -E "s/^listener 8888$/#listener 8888/g" /etc/mosquitto/mosquitto.conf
sed -i -E "s/^protocol websockets$/#protocol websockets/g" /etc/mosquitto/mosquitto.conf
sed -i -E "s/^user root$/#user root/g" /etc/mosquitto/mosquitto.conf
sed -i -E "s/^allow_anonymous true$/#allow_anonymous true/g" /etc/mosquitto/mosquitto.conf

sed -i -E '$ a autosave_interval 1800' /etc/mosquitto/mosquitto.conf
sed -i -E "$ a persistence true" /etc/mosquitto/mosquitto.conf
sed -i -E '$ a persistence_file mosquitto.db' /etc/mosquitto/mosquitto.conf
sed -i -E '$ a persistence_location /var/mosquitto/' /etc/mosquitto/mosquitto.conf
sed -i -E '$ a listener 1883' /etc/mosquitto/mosquitto.conf
sed -i -E '$ a listener 8888' /etc/mosquitto/mosquitto.conf
sed -i -E '$ a protocol websockets' /etc/mosquitto/mosquitto.conf
sed -i -E '$ a user root' /etc/mosquitto/mosquitto.conf
sed -i -E '$ a allow_anonymous true' /etc/mosquitto/mosquitto.conf

#sed -i -E '$ a --------------' /etc/mosquitto/mosquitto.conf

touch /etc/ld.so.conf.d/liblocal.conf
#添加下面两行配置

echo -e '/usr/local/lib64\n/usr/local/lib'>/etc/ld.so.conf.d/liblocal.conf

#刷新
ldconfig

echo -e "启动即时通信服务..."
cd /usr/local/sbin
mosquitto -c /etc/mosquitto/mosquitto.conf -d


echo -e "-----------------------------------------------------------"
echo -e "配置防火墙..."


#安装iptables-services
yum install iptables-services -y
#启动firewalld服务
echo -e "设置开机启动防火墙..."
systemctl enable firewalld.service
echo -e "启动防火墙..."
systemctl start firewalld.service
echo -e "设置开机启动防火墙规则..."
systemctl enable iptables.service
echo -e "启动防火墙规则..."
systemctl start iptables.service
#查看iptables现有规则
iptables -L -n
#先允许所有,不然有可能会杯具
iptables -P INPUT ACCEPT
#清空所有默认规则
iptables -F
#清空所有自定义规则
iptables -X

#所有计数器归0
iptables -Z
echo -e "开启各种服务端口..."
#开放1888 端口
iptables -A INPUT -p tcp --dport 1888 -j ACCEPT
#开放8888端口
iptables -A INPUT -p tcp --dport 1883 -j ACCEPT

iptables -A INPUT -p tcp --dport 8888 -j ACCEPT
#开放8888端口

iptables -A INPUT -p udp --dport 5060 -j ACCEPT

#开放8888端口
iptables -A INPUT -p tcp --dport 8087 -j ACCEPT
iptables -A INPUT -p tcp --dport 8088 -j ACCEPT
iptables -A INPUT -p tcp --dport 8086 -j ACCEPT
iptables -A INPUT -p tcp --dport 8085 -j ACCEPT
iptables -A INPUT -p tcp --dport 1935 -j ACCEPT
#保存上述规则
service iptables save


#查看状态
systemctl restart iptables.service




echo -e "下面设置开机自动启动各种服务..."



#echo -e 'mosquitto -c /etc/mosquitto/mosquitto.conf -d\ncd /usr/local/sbin/ ; ./opensipsctl start\nsystemctl restart WowzaStreamingEngine.service\nsystemctl restart iptables.service'>/etc/rc.d/rc.local

#2.加入以下命令


chmod +x /etc/rc.d/rc.local
sed -i -E '$ a mosquitto -c \/etc\/mosquitto\/mosquitto.conf -d' /etc/rc.d/rc.local
sed -i -E '$ a cd \/usr\/local\/sbin\/ ; .\/opensipsctl start' /etc/rc.d/rc.local
sed -i -E '$ a systemctl restart iptables.service' /etc/rc.d/rc.local
sed -i -E '$ a systemctl restart WowzaStreamingEngine.service' /etc/rc.d/rc.local