安装Docker
卸载原有的环境:
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
安装对应的依赖环境和镜像地址
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
安装过慢设置镜像
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
直接安装docker CE
sudo yum install -y docker-ce docker-ce-cli containerd.io
启动docker
sudo systemctl start docker
查看docker 版本
sudo docker version
配置阿里云的镜像地址
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新yum
yum makecache fast
开机启动docker
sudo systemctl enable docker
安装Mysql
项目软件统一安装在 /mydata 目录下
docker拉取镜像命令
docker pull mysql:5.7
docker安装MySQL命令
docker run -d -p 3306:3306 --name mysql
-v /mydata/mysql/log:/var/log/mysql
-v /mydata/mysql/data:/var/lib/mysql
-v /mydata/mysql/conf:/var/etc/mysql
-v /mydata/mysql/-files:/var/lib/mysql-files
-e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
修改MySQL的配置文件 vim /mydata/mysql/conf/my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect="SET collation_connection = utf8_unicode_ci"
init_connect="SET NAMES utf8"
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
安装Redis
拉取Redis最新版本镜像
docker pull redis
先创建对应的Redis的映射配置文件
mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf
创建容器命令
docker run -d -p 6379:6379 --name mall-redis -v /mydata/redis/data:/data -v /mydata/redis/conf:/etc/redis redis redis-server /etc/redis/redis.conf
启动后测试连接:
[root@manager-node conf]# docker exec -it 4e redis-cli
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379>
安装Nacos
docker pull nacos\
docker run -p 8848:8848 -p 9848:9848 -p 9849:9849 \
-e MODE=standalone \
--name nacos -v /app/docker/nacos/conf:/home/nacos/conf -d nacos/nacos-server:v2.1.1
安装Nginx
拉取Nginx最新版本镜像
docker pull nginx
先创建对应的nginx的文件夹
mkdir -p /app/docker/nginx/conf
mkdir -p /app/docker/nginx/log
mkdir -p /app/docker/nginx/html
容器中的nginx.conf文件和conf.d文件夹复制到宿主机
# 生成容器
docker run --name nginx -p 80:80 -d nginx
# 将容器nginx.conf文件复制到宿主机
docker cp nginx:/etc/nginx/nginx.conf /app/docker/nginx/conf/nginx.conf
# 将容器conf.d文件夹下内容复制到宿主机
docker cp nginx:/etc/nginx/conf.d /app/docker/nginx/conf/conf.d
# 将容器中的html文件夹复制到宿主机
docker cp nginx:/usr/share/nginx/html /app/docker/nginx/html
# 删除容器
docker stop nginx
docker rm nginx
启动容器命令
docker run \
-p 80:80 -p 443:443 \
--name nginx \
-v /app/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /app/docker/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /app/docker/nginx/log:/var/log/nginx \
-v /app/docker/nginx/html:/usr/share/nginx/html \
-d nginx:latest
设置自启动
docker update --restart=always nginx
安装higress
curl -fsSL https://higress.io/standalone/get-higress.sh | bash -s -- -c nacos://127.0.0.1/:8848 --nacos-username=nacos --nacos-password=DQtPvYhdgwoGI9Oa -p
安装RocketMQ
docker run -d --restart=always --name rockermq_server\
--privileged=true -p 9876:9876 \
-v /app/docker/rocketmq/nameserver/logs:/root/logs\
-v /app/docker/rocketmq/nameserver/store:/root/store\
-e "MAX_POSSIBLE_HEAP=100000000" rocketmqinc/rocketmq sh mqnamesrv
docker run -d \
--restart=always \
--name rmqnamesrv \
-p 9876:9876 \
-v /docker/rocketmq/data/namesrv/logs:/root/logs \
-v /docker/rocketmq/data/namesrv/store:/root/store \
-e "MAX_POSSIBLE_HEAP=100000000" \
rocketmqinc/rocketmq \
sh mqnamesrv
docker run -d -p 9876:9876 --name rocketmq \
-v /app/docker/rocketmq/nameserver/logs:/root/logs \
-v /app/docker/rocketmq/nameserver/store:/root/store \
--restart=always --privileged=true -e MAX_POSSIBLE_HEAP=100000000 rocketmqinc/rocketmq sh rocketmq
安装Consul
docker pull consul
docker run --restart=always --name consul -p 8500:8500 \
-v /opt/consul/conf/:/consul/conf/ \
-v /opt/consul/data/:/consul/data/ \
-d consul agent -server \
-ui -node=10.0.190.125 -bind=0.0.0.0 \
-client=0.0.0.0 \
-data-dir /consul/data -config-dir /consul/conf -bootstrap-expect=1
设置容器自启动
[root@localhost ~]# docker update --restart=always mysql
mysql
[root@localhost ~]# docker update --restart=always mall-redis
mall-redis
docker update --restart=always nacos