0x01飘诗、安裝依賴erlang
由于rabbitMq需要erlang語言的支持界逛,在安裝rabbitMq之前需要安裝erlang
sudo apt-get install erlang-nox
0x02、安裝Rabbitmq
先更新apt源
sudo apt-get update
然后安裝rabbitmq
sudo apt-get install rabbitmq-server
啟動溉潭、停止喳瓣、重啟、狀態(tài)rabbitMq命令畏陕,詳情使用鏈接請點(diǎn)擊這里
服務(wù)啟動關(guān)閉
rabbitmq-server -detached # 可以后臺啟動
rabbitmqctl stop # 可以停止
下面是一些命令蹭秋,但是有些測試了出現(xiàn)不能起作用
sudo rabbitmq-server start # 這個(gè)啟動不能再后臺啟動,so不推薦使用
sudo rabbitmq-server stop # 好像不能使用這條命令羽莺,停止的正確命令在下面的命令洞豁,報(bào)錯(cuò)ERROR: node with name "rabbit" already running on "develop"
sudo rabbitmq-server restart # 這條好像也是不能起作用,報(bào)錯(cuò)ERROR: node with name "rabbit" already running on "develop"
sudo rabbitmqctl status # 可以查看運(yùn)行的狀態(tài)信息
0x03刁卜、添加admin蛔趴,并賦予administrator權(quán)限
添加admin用戶例朱,密碼設(shè)置為admin。
sudo rabbitmqctl add_user admin admin
賦予權(quán)限
sudo rabbitmqctl set_user_tags admin administrator
賦予virtual host中所有資源的配置箫荡、寫羔挡、讀權(quán)限以便管理其中的資源
sudo rabbitmqctl set_permissions -p / admin '.*' '.*' '.*'
0x04间唉、RabbitMQ GUID使用
1终吼、官方提供的一個(gè)web管理工具(rabbitmq_management)點(diǎn)擊我進(jìn)行了解)
2氯哮、安裝了Rabbitmq后,默認(rèn)也安裝了該管理工具姆打,執(zhí)行命令即可啟動
sudo rabbitmq-plugins enable rabbitmq_management #(先定位到rabbitmq安裝目錄)
3肠虽、瀏覽器訪問http://你的rabbitmq ip:15672/
輸入剛剛創(chuàng)建的賬號密碼即可訪問(這里我設(shè)置的都是admin,你們的需要根據(jù)實(shí)際情況來調(diào)整)
0x05痊剖、總結(jié)常用命令
rabbitmq-server -detached # 后臺啟動
sudo rabbitmq-server start # 阻塞啟動垒玲,一直處于阻塞狀態(tài),不能后臺合愈,想后臺掛起的話,需要啟動后按Ctrl+z才行
rabbitmqctl stop # 停止
rabbitmqctl status # 查看服務(wù)器狀態(tài)
rabbitmqctl list_queues # 查看隊(duì)列信息
rabbitmqctl add_user admin admin # 添加用戶及密碼
rabbitmqctl set_user_tags admin administrator # 給admin用戶賦權(quán)限
rabbitmqctl set_permissions -p / admin '.*' '.*' '.*' # 賦予virtual host中所有資源的配置益老、寫捺萌、讀權(quán)限以便管理其中的資源
rabbitmq-plugins enable # 激活管理工具
查看到存在的參數(shù)有:
{start|stop|status|rotate-logs|restart|condrestart|try-restart|reload|force-reload}
另外補(bǔ)充的:
service rabbitmq-server start
service rabbitmq-server stop
service rabbitmq-server status
service rabbitmq-server rotate-logs|
service rabbitmq-server restart
service rabbitmq-server condrestart
service rabbitmq-server try-restart
service rabbitmq-server reload
service rabbitmq-server force-reload
ps -ef | grep rabbitmq 查看rabbitMq進(jìn)程
kill -9 pid
netstat -anplt | grep LISTEN rabbitmq默認(rèn)監(jiān)聽端口15672/5672
0x06互婿、限制rabbitmq只監(jiān)聽本地的localhost慈参,防外網(wǎng)入侵的驮配,簡單做法(這樣描述如有不到位請指出)
參考鏈接
原文(英文):https://stackoverflow.com/questions/57225331/bind-rabbitmq-to-localhost-on-ubuntu-server-18-04/57225410#57225410
中文版:https://codeday.me/bug/20181105/356153.html
可以查看監(jiān)聽情況
lsof -n -a -i -urabbitmq
兩個(gè)主要文件內(nèi)容:
/etc/rabbitmq/rabbitmq-env.conf(存在)
export RABBITMQ_CONFIG_FILE="/etc/rabbitmq/rabbit"
# Defaults to rabbit. This can be useful if you want to run more than one node
# per machine - RABBITMQ_NODENAME should be unique per erlang-node-and-machine
# combination. See the clustering on a single machine guide for details:
# http://www.rabbitmq.com/clustering.html#single-machine
#NODENAME=rabbit
# By default RabbitMQ will bind to all interfaces, on IPv4 and IPv6 if
# available. Set this if you only want to bind to one network interface or#
# address family.
#NODE_IP_ADDRESS=127.0.0.1
# Defaults to 5672.
#NODE_PORT=5672
# 2019-10-30 添加下邊的讓rabbitmq和epmd只是監(jiān)聽本地的
export RABBITMQ_NODENAME=rabbit@localhost
export RABBITMQ_NODE_IP_ADDRESS=127.0.0.1
export ERL_EPMD_ADDRESS=127.0.0.1
/etc/rabbitmq/rabbitmq.config(自建)
# [{kernel,[{inet_dist_use_interface,{127,0,0,1}}]}].
[
{rabbitmq_management, [
{listener, [{port, 15672}, {ip, "127.0.0.1"}]}
]},
{kernel, [
{inet_dist_use_interface,{127,0,0,1}}
]}
].
本篇文章由一文多發(fā)平臺ArtiPub自動發(fā)布