Authorize
透過SSH設定
開始
繼續
授權
Linux
SSH
遠端存取
已下指令皆在SSH中輸入
sudo apt update
sudo apt install apache2
sudo systemctl status apache2
sudo systemctl enable apache2
sudo apt install mysql-server
sudo systemctl status mysql
sudo systemctl enable mysql
sudo systemctl restart mysql
設定MySQL可對外連接
在終端機輸入下方指令
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
修正bind-address
bind-address
#預設:bind-address = 127.0.0.1 bind-address = 0.0.0.0
更新套件庫
安裝MQTT伺服器及測試軟體
#mosquitto 是 MQTT 伺服器軟體 #mosquitto-clients 是用於測試 MQTT 伺服器的工具 sudo apt install mosquitto mosquitto-clients
啟動伺服器
sudo systemctl start mosquitto
重啟伺服器
sudo systemctl restart mosquitto
檢查伺服器狀態
sudo systemctl status mosquitto
設定開機自動啟動Server
sudo systemctl enable mosquitto sudo systemctl start mosquitto
Linux系統Mosquitto伺服器相關設定
#各作業系統檔案位置 Linux:/etc/mosquitto/mosquitto.conf macOS:/usr/local/etc/mosquitto/mosquitto.conf Windows:C:\Program Files\mosquitto\mosquitto.conf
創建使用者(輸入完會要求輸入密碼)
sudo mosquitto_passwd -c /etc/mosquitto/passwd <username>
mosquitto.conf配置選項
設置端口 listener 1883 默認是1883(非加密連線)
加密連線(尚未測試)listener 8883 cafile /path/to/ca.crt certfile /path/to/server.crt eyfile /path/to/server.key
配置密碼文件
password_file /etc/mosquitto/passwd
允許匿名訂閱訊息
allow_anonymous true
-h伺服器位置、-t發布的主題、-m訊息、-u使用者名稱、-P使用者密碼、-p prot
mosquitto_pub -h <伺服器位置> -t "test/topic" -m "Hello MQTT" -u <username> -P <password> -p <prot>
-h伺服器位置、-t訂閱的主題、-u使用者名稱、-p使用者密碼
有使用者訂閱 mosquitto_sub -h <伺服器位置> -t "test/topic" -u <username> -p <password>
匿名訂閱 mosquitto_sub -h <伺服器位置> -t "test/topic"
mosquitto.conf
listener 1883`指定MQTT的Port protocol mqtt`指定1883是給未加密的MQTT使用 listener 8083`指定加密MQTT的Port protocol websockets`啟用WebSocket服務 http_dir /var/www/html/mqtt/`指定Web的資料夾
sudo chown -R ivm1110630:ivm1110630 /var/www/html/
sudo systemctl restart apache2
設定GCP防火牆 點擊左側->虛擬私有雲網路->防火牆->建立防火牆規則
虛擬私有雲網路
防火牆
相關設定
延伸閱讀
Google Cloud Platform VM個體使用 - 2
一、透過SSH連線
Authorize
二、透過Google遠端桌面連線
透過SSH設定
->開始
繼續
->授權
Linux
的部分SSH
遠端存取
中看到可遠端的電腦三、安裝Apache網頁伺服器
已下指令皆在SSH中輸入
四、安裝MySQL
五、設定MySQL
設定MySQL可對外連接
在終端機輸入下方指令
修正
bind-address
六、安裝MQTT伺服器
更新套件庫
安裝MQTT伺服器及測試軟體
啟動伺服器
重啟伺服器
檢查伺服器狀態
設定開機自動啟動Server
Linux系統Mosquitto伺服器相關設定
創建使用者(輸入完會要求輸入密碼)
mosquitto.conf配置選項
配置密碼文件
允許匿名訂閱訊息
七、開始使用MQTT
-h伺服器位置、-t發布的主題、-m訊息、-u使用者名稱、-P使用者密碼、-p prot
-h伺服器位置、-t訂閱的主題、-u使用者名稱、-p使用者密碼
八、啟用MQTT WebSocket
mosquitto.conf
設定九、PHP資料夾給予權限
十、設定防火牆
設定GCP防火牆
點擊左側->
虛擬私有雲網路
->防火牆
->建立防火牆規則相關設定
延伸閱讀