資源清單#
主機 | IP |
---|---|
rabbitmq | 10.0.0.1 |
軟體 | 版本 |
---|---|
docker | 20.10.12 |
docker-compose | 1.23.1 |
rabbitmq | 3.8.34 |
一、Docker
安裝#
1. 使用國內 yum
源#
# yum install -y yum-utils device-mapper-persistent-data lvm2
# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2. 卸載舊版本的 docker
#
## 如果主機上已經有docker存在且不是想要安裝的版本,需要先進行卸載。
# yum remove -y docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine \
container*
3. 安裝 Docker20.10
版本#
# yum -y install docker-ce-20.10.12-3.el7 docker-ce-cli-20.10.12-3.el7
4. 設置鏡像加速#
# mkdir /etc/docker
# vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://xxxxxxxxx.mirror.aliyuncs.com"]
}
5. 啟動 docker
#
# systemctl start docker
# systemctl enable docker
# systemctl status docker
二、Docker-compose
安裝#
1. Docker-compose
安裝#
## github.com 可能訪問超時,可以使用下面的獲取下載下來後上傳伺服器即可
# curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# curl -k "https://dl.cactifans.com/zabbix_docker/docker-compose" -o /usr/bin/docker-compose
# chmod a+x /usr/bin/docker-compose
2. 查看 docker-compose
版本#
# docker-compose version
三、部署服務#
1. docker-compose.yaml
資源清單#
version: '3'
services:
rabbitmq:
image: rabbitmq:3.8.34-management
hostname: rabbitmq
container_name: rabbitmq
deploy:
resources:
limits:
cpus: '1'
memory: 2G
ports:
- "15672:15672"
- "15692:15692"
- "5672:5672"
# rabbitmq-exporter port
- "9419:9419"
volumes:
- /data/rabbitmq/:/var/lib/rabbitmq
- /etc/localtime:/etc/localtime
restart: always
rabbitmq_exporter:
image: kbudde/rabbitmq-exporter:1.0.0-RC19
container_name: rabbitmq_exporter
environment:
RABBIT_USER: admin
RABBIT_PASSWORD: admin
depends_on:
- rabbitmq
network_mode: "service:rabbitmq"
restart: always
2. 部署服務#
# docker-compose up -d
# docker-compose ps -a
3. 初始化 rabbimq 帳號資訊#
# cat init_rabbitmq.sh
#!/bin/bash
# reset first node
echo "1、Reset first rabbitmq node."
docker exec rabbitmq /bin/bash -c 'rabbitmqctl stop_app'
docker exec rabbitmq /bin/bash -c 'rabbitmqctl reset'
docker exec rabbitmq /bin/bash -c 'rabbitmqctl start_app'
# add user and userrole
echo "2、Starting to create user."
docker exec rabbitmq /bin/bash -c 'rabbitmqctl add_user admin admin'
echo "3、Set tags for new user."
docker exec rabbitmq /bin/bash -c 'rabbitmqctl set_user_tags admin administrator'
echo "4、Grant permissions to new user."
docker exec rabbitmq /bin/bash -c "rabbitmqctl set_permissions -p '/' admin '.*' '.*' '.*'"
echo "5、Delete guest user"
docker exec rabbitmq /bin/bash -c "rabbitmqctl delete_user guest"
# bash init_rabbitmq.sh