本文主要以图文的形式讲解mall在Linux环境下的部署,涉及在Docker容器中安装Mysql、Redis、Nginx、RabbitMQ、Elasticsearch、Mongodb,以及SpringBoot应用部署,基于CenterOS7.6。
yum install -y yum-utils device-mapper-persistent-data lvm2 复制代码
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 复制代码
yum install docker-ce 复制代码
systemctl start docker 复制代码
docker pull mysql:5.7 复制代码
docker run -p 3306:3306 --name mysql / -v /mydata/mysql/log:/var/log/mysql / -v /mydata/mysql/data:/var/lib/mysql / -v /mydata/mysql/conf:/etc/mysql / -e MYSQL_ROOT_PASSWORD=root / -d mysql:5.7 复制代码
docker exec -it mysql /bin/bash 复制代码
mysql -uroot -proot --default-character-set=utf8 复制代码
create database mall character set utf8 复制代码
yum -y install lrzsz 复制代码
docker cp /mydata/mall.sql mysql:/ 复制代码
use mall; source /mall.sql; 复制代码
grant all privileges on *.* to 'reader' @'%' identified by '123456'; 复制代码
docker pull redis:3.2 复制代码
docker run -p 6379:6379 --name redis / -v /mydata/redis/data:/data / -d redis:3.2 redis-server --appendonly yes 复制代码
docker exec -it redis redis-cli 复制代码
docker pull nginx:1.10 复制代码
docker run -p 80:80 --name nginx / -v /mydata/nginx/html:/usr/share/nginx/html / -v /mydata/nginx/logs:/var/log/nginx / -d nginx:1.10 复制代码
docker container cp nginx:/etc/nginx /mydata/nginx/ 复制代码
mv nginx conf 复制代码
docker stop nginx docker rm nginx 复制代码
docker run -p 80:80 --name nginx / -v /mydata/nginx/html:/usr/share/nginx/html / -v /mydata/nginx/logs:/var/log/nginx / -v /mydata/nginx/conf:/etc/nginx / -d nginx:1.10 复制代码
docker pull rabbitmq:3.7.15 复制代码
docker run -d --name rabbitmq / --publish 5671:5671 --publish 5672:5672 --publish 4369:4369 / --publish 25672:25672 --publish 15671:15671 --publish 15672:15672 / rabbitmq:3.7.15 复制代码
docker exec -it rabbitmq /bin/bash rabbitmq-plugins enable rabbitmq_management 复制代码
firewall-cmd --zone=public --add-port=15672/tcp --permanent firewall-cmd --reload 复制代码
docker pull elasticsearch:6.4.0 复制代码
sysctl -w vm.max_map_count=262144 复制代码
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch / -e "discovery.type=single-node" / -e "cluster.name=elasticsearch" / -v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins / -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data / -d elasticsearch:6.4.0 复制代码
chmod 777 /mydata/elasticsearch/data/ 复制代码
docker exec -it elasticsearch /bin/bash #此命令需要在容器中运行 elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.0.zip docker restart elasticsearch 复制代码
firewall-cmd --zone=public --add-port=9200/tcp --permanent firewall-cmd --reload 复制代码
docker pull kibana:6.4.0 复制代码
docker run --name kibana -p 5601:5601 / --link elasticsearch:es / -e "elasticsearch.hosts=http://es:9200" / -d kibana:6.4.0 复制代码
firewall-cmd --zone=public --add-port=5601/tcp --permanent firewall-cmd --reload 复制代码
docker pull mongo:3.2 复制代码
docker run -p 27017:27017 --name mongo / -v /mydata/mongo/db:/data/db / -d mongo:3.2 复制代码
## Docker全部环境安装完成 - 所有下载镜像文件: ![展示图片](http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/blog/refer_screen_82.png) - 所有运行在容器里面的应用: ![展示图片](http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/blog/refer_screen_83.png) ## SpringBoot应用部署 ### 构建所有Docker镜像并上传 - 打开pom.xml中使用docker插件的注释: ![展示图片](http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/blog/refer_screen_84.png) - 修改dockerHost为你自己的docker服务器地址: - 构建镜像并上传: ![展示图片](http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/blog/refer_screen_85.png) ![展示图片](http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/blog/refer_screen_86.png) ### 部署mall-admin ```shell docker run -p 8080:8080 --name mall-admin / --link mysql:db / -v /etc/localtime:/etc/localtime / -v /mydata/app/admin/logs:/var/logs / -d mall/mall-admin:1.0-SNAPSHOT 复制代码
注意
:CenterOS7.2版本需要加入此行,否则容器时区和宿主机无法同步
-v /etc/timezone:/etc/timezone / 复制代码
docker run -p 8081:8081 --name mall-search / --link elasticsearch:es / --link mysql:db / -v /etc/localtime:/etc/localtime / -v /mydata/app/search/logs:/var/logs / -d mall/mall-search:1.0-SNAPSHOT 复制代码
docker run -p 8085:8085 --name mall-portal / --link mysql:db / --link redis:redis / --link mongo:mongo / --link rabbitmq:rabbit / -v /etc/localtime:/etc/localtime / -v /mydata/app/portal/logs:/var/logs / -d mall/mall-portal:1.0-SNAPSHOT 复制代码
firewall-cmd --zone=public --add-port=8080/tcp --permanent firewall-cmd --zone=public --add-port=8081/tcp --permanent firewall-cmd --zone=public --add-port=8085/tcp --permanent firewall-cmd --reload 复制代码