./nginx - t : 表示检测 nginx.conf文件的语法是否有问题!
./nginx - s reload : 表示重新加载 nginx.conf文件!
./nginx - s quit : 表示强制或正常退出 Nginx 服务!
./nginx : 表示开启 Nginx 服务!服务器配置;
yum update //更新我们的 yum 源
yum -y install gcc automake autoconf libtool make //安装 make工具
yum install gcc gcc-c++ //安装g++
yum install pcre pcre-devel //安装pcre正则表达式,因为nginx的rewrite模块和http核心模块都是使用它
wget http://nginx.org/download/nginx-1.9.9.tar.gz //获取 nginx
tar -vzxf nginx-1.9.9.tar.gz //解压 nginx
cd nginx-1.9.9
./configure //先使配置文件nginx生效
yum install zlib zlib-devel //zlib提供压缩算法,nginx很多地方都会用到
yum install openssl openssl-devel //用到安全页面,所以需要 OpenSSL库
wget https://codeload.github.com/openresty/headers-more-nginx-module/tar.gz/v0.33 //这个可以适配某些JS的webSocket协议头的库。解压tar -vzxf headers-more-nginx-module-0.33.tar.gz 可能需要直接访问域名下载,WinSCP工具上传
./configure --prefix=/usr/local/nginx --add-module=/root/nginx-1.9.9/headers-more-nginx-module-0.33 --with-http_stub_status_module --with-http_ssl_module //添加模块openSSL和headers-more-nginx-module-0.33
make && make install //开始编译nginx代码
cd /usr/local/nginx/sbin && ./nginx -V //****emqttd在这个是目录****编译nginx代码后会有/usr/local/nginx目录,我们查看当前编译后有哪些模块生效了
wget https://www.emqx.io/downloads/broker/v2.3.11/emqttd-centos7-v2.3.11.zip //获取emq压缩包
yum install unzip -y //新增zip的解压工具,用来解压emq的压缩包
unzip emqttd-centos7-v2.3.11.zip //解压压缩包emq
cd emqttd/bin
./emqttd start 执行服务器emq
cd /usr/local/nginx/conf && vim nginx.conf -------------------------复制粘贴以下代码在http {}中---------------------------
server {
listen 443;
server_name mqtt.123456.cn; #你的域名
ssl on;
ssl_certificate /root/myCert/cert/mqtt.123456.cn_chain.crt; #这里是证书
ssl_certificate_key /root/myCert/cert/mqtt.123456.cn_key.key; #这里是秘钥
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
location = /mqtt {
# 8083就是我们的emq的websocket的端口号
proxy_pass http://mqtt.123456.cn:8083; #你的域名
proxy_redirect off;
proxy_set_header Host mqtt.123456.cn:8083; #你的域名
proxy_set_header Sec-WebSocket-Protocol mqtt;
# 这个是与你的 js客户端的库有关系,本博文的不需要,为了兼顾以后小伙伴,我这里注释了下!
#more_clear_headers Sec-WebSocket-Protocol;
# 这些都是 websocket必须要配置的
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}-------------------------其他---------------------------------------------------
cd /usr/local/nginx/sbin&& ./nginx -t //查看配置文件语法有问题
cd /usr/local/nginx/sbin&& ./nginx -s reload //重新加载配置文件
]]>yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
查看结果:yum repolist all | grep enabled第 2 步:安装 mosquitto
查找 mosquitto 软件包:yum list all | grep mosquitto
查看 mosquitto 信息: yum info mosquitto
安装 mosquitto 软件包: yum install mosquitto
查看安装结果:yum list installed | grep mosquitto第 3 步:测试 mosquitto
启动 mosquitto 主程序:mosquitto
第二个窗口:执行命令:mosquitto_sub -t rimelink
第三个窗口:执行命令:mosquitto_pub -t rimelink -h localhost -m "hello, mosquitto"*第二个窗口:可以看到订阅程序收到:hello, mosquitto
开机自动启动命令
systemctl enable mosquitto---------------------------常用命令-------------------------------------------
1.设置用户名和密码
cd /etc/mosquitto
vi mosquitto.conf
修改以下2点--------------------------------------
allow_anonymous
修改前:#allow_anonymous
修改后:allow_anonymous false
password_file
修改前:#password_file
2.创建用户名和密码、打开命令窗口 键入如下命令:
mosquitto_passwd -c /etc/mosquitto/pwfile.example admin*提示连续两次输入密码、创建成功。命令解释: -c 创建一个用户、/etc/mosquitto/pwfile.example 是将用户创建到 pwfile.example 文件中、admin 是用户名。
mosquitto_passwd /etc/mosquitto/pwfile.example admin开启1883端口:
firewall-cmd --add-port=1883/tcp --permanent删除端口:
firewall-cmd --zone=public --remove-port=1883/tcp --permanent刷新:
firewall-cmd --reload查询端口list:
firewall-cmd --list-ports
]]>