一台服务器上用Docker部署RabbitMQ、Redis、MongoDB、MySQL

数据采集服务器环境部署

 需求:一台服务器上用Docker部署RabbitMQ、Redis、MongoDB、MySQL

 

 


 

  • 系统:centos7.8
  • 内核:3.10.0-1127.19.1.el7.x86_64(阿里云服务器不建议升级内核)
  • 内网IP:xxx.xxx.xxx.xxx
  • 外网IP:xxx.xxx.xxx.xxx
  • 磁盘:60G+300G
    • /dev/vda1    ext4    60G    /
    • /dev/vdb1    ext4    300G    /data
 
 

1、Docker

  • 版本:20.10.5
  • Docker根目录:/data/docker
  • 配置文件:/etc/docker/daemon.json
  • 启动文件:/usr/lib/systemd/system/docker.service
 
具体安装步骤:
 
curl http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce
[ ! -d /etc/docker ] && mkdir -p /etc/docker
[ ! -d /data/docker ] && mkdir -p /data/docker
cat > /etc/docker/daemon.json <<- EOF
{
    "exec-opts": ["native.cgroupdriver=systemd"],
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "1024m",
        "max-file": "3"
    },
    "storage-driver": "overlay2",
    "storage-opts": [
    "overlay2.override_kernel_check=true"
    ],
        "data-root": "/data/docker",
    "max-concurrent-downloads": 5,
    "storage-driver": "overlay2",
    "insecure-registries": [
        "http://127.0.0.1"
    ]
}
EOF
systemctl daemon-reload
systemctl enable docker.service
systemctl start docker.service

 

2、Nginx

  • 版本:1.18.0
  • 安装目录:/etc/nginx
  • 配置文件:/etc/nginx/conf.d/default.conf
  • 访问日志目录:/data/nginx/log/*.log
  • nginx错误日志:/var/log/nginx/error.log
  • 启动文件:/usr/lib/systemd/system/nginx.service
 
wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm
rpm -ivh nginx-1.18.0-1.el7.ngx.x86_64.rpm
systemctl daemon-reload
systemctl enable nginx.service
systemctl start nginx.service

 

 
 

3、MYSQL

  • 版本:5.7
  • 数据目录:/data/mysql/data
  • 账号:monitor
  • 密码:#123456
  • 端口:63306
 
[ ! -d /data/mysql/data ] && mkdir -p /data/mysql/data
docker run -itd  --restart=always -p 63306:3306 --name mysql  -v /data/mysql/data:/var/lib/mysql  -e MYSQL_ROOT_USERNAME=monitor -e MYSQL_ROOT_PASSWORD=#123456 mysql:5.7
docker cp mysql:/etc/mysql/mysql.conf.d/mysqld.cnf ./
echo "sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" >> mysqld.cnf
sed -i 's/#log-error/log-error/g' mysqld.cnf
docker cp ./mysqld.cnf mysql:/etc/mysql/mysql.conf.d/mysqld.cnf 
docker restart mysql

 

 
 

4、MongoDB

  • 版本:4.2
  • 数据目录:/data/mongodb/db
  • 账号:BdszMongo
  • 密码:#123456
  • 端口:27028
 
[ ! -d /data/mongodb/db ] && mkdir -p /data/mongodb/db
docker run -itd --name mongodb  --restart=always -p 27028:27017 -v /data/mongodb/db:/data/db  -v /data/mongodb/config:/data/configdb  -v /data/mongodb/logs:/data/log/   -e MONGO_INITDB_ROOT_USERNAME=BdszMongo -e MONGO_INITDB_ROOT_PASSWORD=#123456   mongo:4.2  --bind_ip_all  --auth

 

 
 
 
 

5、RabbitMQ

  • 版本:3.8.3-management
  • 数据目录:/data/rabbitmq/db
  • 账号:BdszMQ
  • 密码:#123456
  • 端口:55672
 
[ ! -d /data/rabbitmq ] && mkdir -p /data/rabbitmq
echo "192.168.10.10 rabbit1 rabbit1" >> /data/rabbitmq/hosts
docker run -itd \
--restart=unless-stopped \
--name rabbit1 \
-h rabbit1 \
-p 55672:5672 \
-p 15672:15672 \
-p 25672:25672 \
-p 4369:4369 \
-v /data/rabbitmq:/var/lib/rabbitmq:z \
-v /data/rabbitmq/hosts:/etc/hosts \
-e RABBITMQ_DEFAULT_USER=BdszMQ \
-e RABBITMQ_DEFAULT_PASS=#123456 \
-e RABBITMQ_ERLANG_COOKIE='monitor_cluster_cookie' \
rabbitmq:3.8.3-management
 

6、Redis

  • 版本:5.0.9
  • 数据目录:/data/redis/data
  • 密码:#123456
  • 端口:56379
 [ ! -d /data/redis/data ] && mkdir -p /data/redis/data
docker run -itd --restart=always --privileged=true -p 56379:6379 -v /data/redis/conf/redis.conf:/etc/redis/redis.conf -v /data/redis/data:/data  --name redis redis:5.0.9 --requirepass #123456

 

 
 
 
 
 
 
 
posted @ 2021-03-23 16:45  梦里花落知多少sl  阅读(347)  评论(0编辑  收藏  举报