docker环境安装mysql,redis,nacos,rabbitmq

1.docker安装nacos

1.获取镜像 
 docker pull nacos/nacos-server
2.查看 
 docker images
3.创建nacos 容器并运行
docker  run \
--name nacos -d \
-p 8848:8848 \
--privileged=true \
--restart=always \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e MODE=standalone \
-e PREFER_HOST_MODE=hostname \
nacos/nacos-server

2.docker安装mysql

1.下载Mysql镜像

docker pull mysql	

2.查看mysql镜像

docker images

3.创建挂载目录

mkdir -p /home/docker/mysql/conf && mkdir -p /home/docker/mysql/datadir

4.新建my.cnf,保存

cd /home/docker/mysql/conf
vim my.cnf
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
 
[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
 
# Custom config should go here
!includedir /etc/mysql/conf.d/

5.创建Mysql容器并运行

docker run --name mysql8 \
-p 3306:3306 -e MYSQL_ROOT_PASSWORD=root \
--mount type=bind,src=/home/docker/mysql/conf/my.cnf,dst=/etc/mysql/my.cnf \
--mount type=bind,src=/home/docker/mysql/datadir,dst=/var/lib/mysql \
--restart=on-failure:3 \
-d mysql
  • –name:为容器指定一个名字
  • -p:指定端口映射,主机端口:容器端口
  • -e:pwd=“xxx”,设置环境变量
  • –restart=on-failure:3:是指容器在未来出现异常退出(退出码非0)的情况下循环重启3次
  • -mount:绑定挂载
  • -d:后台运行容器,并返回容器 id

6.登录容器,修改mysql密码

# 进入mysql 容器
docker exec -it mysql8 bash
# 进入mysql
mysql -uroot -p
# 输入原本设置的密码root
# 修改远程登录root密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'pwd';
# 修改登录权限
grant all privileges on *.* to 'root'@'%' with grant option;
# 刷新数据库
flush privileges;
# 退出数据库
exit
# 退出容器
exit

设置mysql开机自启

docker update mysql8 --restart=always

3.docker安装redis

1.拉起redis镜像

docker pull redis

2.创建本机redis挂载目录

mkdir -p /root/redis/data /root/redis/conf

在/root/redis/conf目录中创建文件 redis.conf

touch redis.conf

3.准备redis的配置文件

因为需要redis的配置文件,直接去redis的官方去下载一个redis里面的配置文件即可

redis中文官方网站:http://www.redis.cn/download.html

下载后解压出来,拿到 redis.conf

3.配置 redis.conf 配置文件

bind 127.0.0.1           #注释掉这部分,使redis可以外部访问
daemonize no            #用守护线程的方式启动
requirepass 你的密码     #给redis设置密码
appendonly yes          #redis持久化  默认是no
tcp-keepalive 300       #防止出现远程主机强迫关闭了一个现有的连接的错误 默认是300

4.创建redis容器

 docker run -p 6379:6379 --name redis -v /root/redis/conf/redis.conf:/etc/redis/redis.conf  -v /root/redis/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes

-d 后台运行

-p 端口映射到主机的端口

-v 将主机目录挂载到容器的目录

**redis-server --appendonly yes *在容器执行redis-server启动命令,并打开redis持久化配置

5.启动redis容器

docker start redis

6.测试连接

docker环境安装mysql,redis,nacos,rabbitmq_第1张图片

4.docker安装rabbitmq

1.拉取并运行容器

docker run -dit --name rabbitmq -e RABBITMQ_DEFAULT_USER=guest -e RABBITMQ_DEFAULT_PASS=guest -p 15672:15672 -p 5672:5672 rabbitmq:management

2.访问地址

http://192.168.56.10:15672/

3.根据版本号下载延迟插件

查看mq本版,先进入日期内部
1.docker exec -it rabbitmq /bin/bash
2.查询rabbitmqctl 文件路径
find -name rabbitmqctl
3.进入对应的文件
cd /opt/rabbitmq/escript/
查询版本号
rabbitmqctl version

下载地址:https://www.rabbitmq.com/community-plugins.html

docker环境安装mysql,redis,nacos,rabbitmq_第2张图片

我的RabbitMQ 版本是3.9.11,我这里选择下载3.9.0版本的插件

docker环境安装mysql,redis,nacos,rabbitmq_第3张图片

4.安装插件并启用

将刚刚上传的插件拷贝到容器内plugins目录下

docker cp /root/rabbitmq_delayed_message_exchange-3.9.0.ez rabbitmq:/plugins

我刚刚是将插件上传到/root下了; rabbit是容器的name,也可以使用容器id

进入到RabbitMQ容器内部

docker exec -it rabbitmq /bin/bash

查看插件是否存在

rabbitmq-plugins list

启动插件

rabbitmq-plugins enable rabbitmq_delayed_message_exchange

你可能感兴趣的:(docker,java-rabbitmq,mysql)