上才艺:
1规划节点
IP | 主机名 | 节点 |
192.168.9.130 | master | docker-compose节点 |
2基础准备
Docker和Docker Compose已安装完成,将提供的软件包mall-swarm.tar.gz上传至master节点/root目录下并解压。
需要mall-swarm.tar.g资源包的,看个人简介,或者评论区,这里不方便给出
3案例实施
1.Mariadb容器化部署
(1)编写Dockerfile
编写.repo仓库
[root@master ~]# cd mall-swarm
[root@master mall-swarm]# cat local.repo
[mall]
name=mall
baseurl=file:///opt/mall-repo
gpgcheck=0
enabled=1
编写初始化脚本init.sh:
[root@master mall-swarm]# cat init.sh
#!/bin/bash
mysql_install_db --user=root
mysqld_safe --user=root &
sleep 8
mysqladmin -u root password 'root'
mysql -uroot -proot -e "grant all on *.* to 'reader'@'%' identified by '123456'; flush privileges;"
mysql -uroot -proot -e "create database mall; use mall; source /opt/mall.sql;"
编写Dockerfile文件:
[root@master mall-swarm]# cat Dockerfile-mariadb
FROM centos:centos7.5.1804
MAINTAINER skill
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY mall-repo /opt/mall-repo
COPY mall.sql /opt/
COPY init.sh /opt/
ENV LC_ALL en_US.UTF-8
RUN yum -y install mariadb-server && bash /opt/init.sh
EXPOSE 3306
CMD ["mysqld_safe","--user=root"]
(2)构建镜像
构建镜像:
[root@master mall-swarm]# docker build -t mall-mysql:v1.0 -f Dockerfile-mariadb .
Sending build context to Docker daemon 410.3MB
Step 1/11 : FROM centos:centos7.5.1804
---> cf49811e3cdb
Step 2/11 : MAINTAINER skill
---> Using cache
---> 612224da592d
Step 3/11 : RUN rm -rf /etc/yum.repos.d/*
---> Using cache
---> d88b0763dfe4
Step 4/11 : COPY local.repo /etc/yum.repos.d/
---> Using cache
---> 60047baa075d
Step 5/11 : COPY mall-repo /opt/mall-repo
---> Using cache
---> ae7f67e9bf08
Step 6/11 : COPY mall.sql /opt/
---> Using cache
---> c387a39ef1aa
Step 7/11 : COPY init.sh /opt/
---> Using cache
---> a29b78a53fea
Step 8/11 : ENV LC_ALL en_US.UTF-8
---> Using cache
---> 19cf25317911
Step 9/11 : RUN yum -y install mariadb-server && bash /opt/init.sh
---> Using cache
---> 1e8fbec2cc00
Step 10/11 : EXPOSE 3306
---> Using cache
---> 9c4a6fb7bd6b
Step 11/11 : CMD ["mysqld_safe","--user=root"]
---> Using cache
---> c689d4e7ea97
Successfully built c689d4e7ea97
Successfully tagged mall-mysql:v1.0
2.Redis容器化部署
(1)编写Dockerfile
编写Dockerfile文件:
[root@master mall-swarm]# cat Dockerfile-redis
FROM centos:centos7.5.1804
MAINTAINER skill
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY mall-repo /opt/mall-repo
RUN yum -y install redis
RUN sed -i 's/127.0.0.1/0.0.0.0/g' /etc/redis.conf && \
sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis.conf
EXPOSE 6379
CMD ["/usr/bin/redis-server","/etc/redis.conf"]
(2)构建镜像
构建镜像:
[root@master mall-swarm]# docker build -t mall-redis:v1.0 -f Dockerfile-redis .
Sending build context to Docker daemon 410.3MB
Step 1/9 : FROM centos:centos7.5.1804
---> cf49811e3cdb
Step 2/9 : MAINTAINER skill
---> Using cache
---> dfdbec4d294b
Step 3/9 : RUN rm -rf /etc/yum.repos.d/*
---> Using cache
---> cade39fa5cbd
Step 4/9 : COPY local.repo /etc/yum.repos.d/
---> Using cache
---> 83d77407ada3
Step 5/9 : COPY mall-repo /opt/mall-repo
---> Using cache
---> fa10113c62ac
Step 6/9 : RUN yum -y install redis
---> Using cache
---> 1b70d0d9faf5
Step 7/9 : RUN sed -i 's/127.0.0.1/0.0.0.0/g' /etc/redis.conf && sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis.conf
---> Using cache
---> f9e69a29089d
Step 8/9 : EXPOSE 6379
---> Using cache
---> b45b59562c57
Step 9/9 : CMD ["/usr/bin/redis-server","/etc/redis.conf"]
---> Using cache
---> 44b9fefbf4e2
Successfully built 44b9fefbf4e2
Successfully tagged mall-redis:v1.0
3.RabbitMQ容器化部署
(1)编写Dockerfile
创建RabbitMQ用户脚本
[root@master mall-swarm]# cat rabbitmq-user.sh
#!/bin/bash
/usr/lib/rabbitmq/bin/rabbitmq-server restart
sleep 8
/usr/lib/rabbitmq/bin/rabbitmqctl add_vhost mall
/usr/lib/rabbitmq/bin/rabbitmqctl add_user mall mall
/usr/lib/rabbitmq/bin/rabbitmqctl set_user_tags mall administrator
/usr/lib/rabbitmq/bin/rabbitmqctl set_permissions -p mall mall '.*' '.*' '.*'
/usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management
/usr/lib/rabbitmq/bin/rabbitmq-server restart
编写Dockerfile文件:
[root@master mall-swarm]# cat Dockerfile-rabbitmq
FROM centos:centos7.5.1804
MAINTAINER skill
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY rabbitmq-user.sh /opt/rabbitmq-user.sh
COPY mall-repo /opt/mall-repo
RUN yum -y install rabbitmq-server
EXPOSE 5672 15672
CMD ["/bin/bash","/opt/rabbitmq-user.sh"]
(2)构建镜像
[root@master mall-swarm]# docker build -t mall-rabbit:v1.0 -f Dockerfile-rabbitmq .
Sending build context to Docker daemon 410.3MB
Step 1/9 : FROM centos:centos7.5.1804
---> cf49811e3cdb
Step 2/9 : MAINTAINER skill
---> Using cache
---> 02855371e6e9
Step 3/9 : RUN rm -rf /etc/yum.repos.d/*
---> Using cache
---> 5f56a1e30007
Step 4/9 : COPY local.repo /etc/yum.repos.d/
---> Using cache
---> ff9431065417
Step 5/9 : COPY rabbitmq-user.sh /opt/rabbitmq-user.sh
---> Using cache
---> d3d36333b8df
Step 6/9 : COPY mall-repo /opt/mall-repo
---> Using cache
---> 0efec0dea187
Step 7/9 : RUN yum -y install rabbitmq-server
---> Using cache
---> 918e0aea03a2
Step 8/9 : EXPOSE 5672 15672
---> Using cache
---> b796230efa8d
Step 9/9 : CMD ["/bin/bash","/opt/rabbitmq-user.sh"]
---> Using cache
---> 67d8b40d90ad
Successfully built 67d8b40d90ad
Successfully tagged mall-rabbit:v1.0
4.容器化部署前端服务
编写Dockerfile:
[root@master mall-swarm]# cat Dockerfile-nginx
FROM centos:centos7.5.1804
MAINTAINER skill
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY mall-repo /opt/mall-repo
RUN yum -y install nginx
COPY dist/ /usr/share/nginx/html/
EXPOSE 80
CMD ["nginx","-g","daemon off;"]
(2)构建镜像
[root@master mall-swarm]# docker build -t mall-nginx:v1.0 -f Dockerfile-nginx .
Sending build context to Docker daemon 700.1MB
Step 1/9 : FROM centos:centos7.5.1804
---> cf49811e3cdb
Step 2/9 : MAINTAINER skill
---> Using cache
---> 02855371e6e9
Step 3/9 : RUN rm -rf /etc/yum.repos.d/*
---> Using cache
---> 5f56a1e30007
Step 4/9 : COPY local.repo /etc/yum.repos.d/
---> Using cache
---> ff9431065417
Step 5/9 : COPY mall-repo /opt/mall-repo
---> Using cache
---> 0a63c0b0b053
Step 6/9 : RUN yum -y install nginx
---> Using cache
---> 69686a3a123e
Step 7/9 : COPY dist/ /usr/share/nginx/html/
---> Using cache
---> 1b12b034cef7
Step 8/9 : EXPOSE 80
---> Using cache
---> 3435ab9920cb
Step 9/9 : CMD ["nginx","-g","daemon off;"]
---> Using cache
---> 758615ecb15e
Successfully built 758615ecb15e
Successfully tagged mall-nginx:v1.0
5.Nacos部署
......后续更
6.编排Mall-Swarm
......后续更
7.浏览器访问
在浏览器中输入:192.168.9.130:8888访问mall-swarm
登录密码:用户:admin 密码:macro23
我所遇见问题的解决
1.登录Web界面时出现“Network Error”,这个有很多情况,如下排除:
此节点配置是否可以,需要4vcpu,内存4G,磁盘有个差不多就行
在想和就是,查看mall-admin容器是否exit退出,如果退出查看Mysql的配置是否正确