转自:http://www.jeesite.net/forum.php?mod=viewthread&tid=2568
1. jdk与maven安装
项目需要自动打包部署,因此需要配置jdk与maven
安装jdk
- yum install java-1.8.0-openjdk.x86_64
安装maven
- sudo yum install -y yum-utils
- [code]yum-config-manager --add-repo http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo
- yum install -y apache-maven
配置maven仓库为阿里云
- <mirror>
- <id>nexus-aliyun</id>
- <mirrorOf>central</mirrorOf>
- <name>Nexus aliyun</name>
- <url><a
href="http://maven.aliyun.com/nexus/content/groups/public</url>"
target="_blank">http://maven.aliyun.com/nexus/content/groups/public</url></a>
- </mirror>
2. docker安装
- 1. sudo yum install -y yum-utils device-mapper-persistent-data lvm2
- 2. sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- 3. sudo yum install docker-ce
配置docker加速器(注册阿里云加速更快)、容器网段、镜像仓库
- vi /etc/docker/daemon.json
- {
- "bip":"172.18.6.1/24",
- "registry-mirrors":[" <a
href="https://kzorq22x.mirror.aliyuncs.com"
target="_blank">https://kzorq22x.mirror.aliyuncs.com</a>"],
- "insecure-registries":["192.168.244.10:5000"]
- }
配置后重启docker服务:
- systemctl daemon-reload
- systemctl restart docker
3. docker-compose安装
- sudo curl -L
https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname
-s`-`uname -m` > /usr/local/bin/docker-compose
- sudo chmod +x /usr/local/bin/docker-compose
4. docker仓库服务
- docker pull registry
- docker run -d --name reg -p 5000:5000 registry
测试仓库服务:http://192.168.244.10:5000/v2/_catalog
5. docker挂载目录约定。
- 数据目录:/docker-data
- 日志目录:/docker-log
一、 项目环境搭建
1. zk搭建
- docker run -d --name zk -p 2181:2181 zookeeper
2. dubbo-admin控制台(非必须)
- docker run -d -p
8280:8080 --name dubbo -e
dubbo.registry.address=zookeeper://192.168.244.10:2181 -e
dubbo.admin.root.password=root chenchuxin/dubbo-admin
3. redis搭建
- docker run -d --name redis -p 6379:6379 redis --requirepass "123456"
4. mysql主从搭建
A. 创建mysql主从库配置目录
- mkdir -p /docker-data/mysql/master/conf
- mkdir -p /docker-data/mysql/slave/conf
B. 在/docker-data/mysql/master/conf下,创建my.cnf配置文件
- [client]
- port=3306
- default-character-set=utf8
- [mysql]
- default-character-set=utf8
- [mysqld]
- character_set_server=utf8
- sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
- # 配置大小写不敏感
- lower_case_table_names=1
- ## 同一局域网内注意要唯一
- server-id=100
- ## 开启二进制日志功能(关键)
- log-bin=mysql-bin
C. 在/docker-data/mysql/slave/conf下,创建my.cnf配置文件
- [client]
- port=3306
- default-character-set=utf8
- [mysql]
- default-character-set=utf8
- [mysqld]
- character_set_server=utf8
- sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
- # 配置大小写不敏感
- lower_case_table_names=1
- ## 同一局域网内注意要唯一
- server-id=101
D. 使用docker-compose来管理mysql主从库,
在/docker-data/mysql下创建docker-compose.yaml:
vi docker-compose.yaml
- version: ‘3‘
- services:
- mysql-slave:
- image: mysql:5.7
- depends_on:
- - mysql-master
- links:
- - mysql-master
- volumes:
- - /docker-data/mysql/slave/data:/var/lib/mysql
- - /docker-data/mysql/slave/conf:/etc/mysql
- - /docker-data/mysql/slave/log:/var/log/mysql
- ports:
- - "3308:3306"
- restart: always
- environment:
- MYSQL_ROOT_PASSWORD: root
- container_name: mysql-slave
- mysql-master:
- image: mysql:5.7
- volumes:
- - /docker-data/mysql/master/data:/var/lib/mysql
- - /docker-data/mysql/master/conf:/etc/mysql
- - /docker-data/mysql/master/log:/var/log/mysql
- ports:
- - "3307:3306"
- restart: always
- environment:
- MYSQL_ROOT_PASSWORD: root
- container_name: mysql-master
E. 启动compose来启动mysql
F. 主数据库配置,连接主库并创建数据同步用户
- CREATE USER ‘slave‘@‘%‘ IDENTIFIED BY ‘123456‘;
- GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO ‘slave‘@‘%‘;
-
- SHOW MASTER STATUS ;
G. 从数据库配置,连接从库配置从库同步连接(指定连接的ip/port/user/passwd以及上图中show master status命令得到的file和position值)
- CHANGE MASTER TO
MASTER_HOST=‘192.168.244.10‘,MASTER_PORT=3307,MASTER_USER=‘slave‘,MASTER_PASSWORD=‘123456‘,MASTER_LOG_FILE=‘mysql-bin.000003‘,MASTER_LOG_POS=609;
- #启动同步进程
- START SLAVE;
- H. 测试结果状态
- 主库查询进程:SHOW PROCESSLIST
-
- 从库查询进程:SHOW PROCESSLIST
5. mongodb搭建
- docker run -d --name mongo -p 27017:27017 -v /docker-data/mongo:/data/db mongo
6. fastdfs图片服务
创建fastdfs容器服务,并进入容器内部
- docker run --add-host
fastdfs.net:192.168.244.10 --name fastdfs --net=host -e TRACKER_ENABLE=1
-e NGINX_PORT=8181 -v /docker-data/fastdfs:/storage/fastdfs -it
mypjb/fastdfs
修改mod_fastdfs配置,vi /usr/local/nginx/modules/fastdfs/src/mod_fastdfs.conf
修改nginx配置,vi /usr/local/nginx/conf/nginx.conf
重启nginx服务,
退出容器(ctrl + Q)
7. rabbitMQ服务
- docker run -d --name
mq -p 5672:5672 -p 15672:15672 -v
/docker-data/rabbitmq:/var/lib/rabbitmq -e RABBITMQ_DEFAULT_USER=admin
-e RABBITMQ_DEFAULT_PASS=admin rabbitmq:3.7.14-management
8. nginx服务
可先放置了配置文件目录到宿主机,方便后续nginx编辑配置
进入/docker-data/nginx/conf.d目录下,添加以下配置文件
vi sso.conf
- server {
- listen 80;
- server_name self.sso.com;
- location /mall-account {
- proxy_pass <a href="http://192.168.244.10:8180;" target="_blank">http://192.168.244.10:8180;</a>
- }
- location ~ /picture/M00{
- proxy_pass <a href="http://192.168.244.10:8181;" target="_blank">http://192.168.244.10:8181;</a>
- }
- }
vi www.conf
- server {
- listen 80;
- server_name <a href="http://www.mall.com" target="_blank">www.mall.com</a> mng.mall.com mall.com;
- if ($http_host ~ "^mall.com[ DISCUZ_CODE_25 ]quot;) {
- rewrite ^(.*) <a href="http://www.mall.com" target="_blank">http://www.mall.com</a>$1 permanent;
- }
- location /mall {
- proxy_pass <a href="http://192.168.244.10:8186;" target="_blank">http://192.168.244.10:8186;</a>
- }
- location /mall-mng {
- proxy_pass <a href="http://192.168.244.10:8185;" target="_blank">http://192.168.244.10:8185;</a>
- }
- location /picture/M00 {
- proxy_pass <a href="http://192.168.244.10:8181;" target="_blank">http://192.168.244.10:8181;</a>
- }
- location / {
- if ($http_host ~ "^mng.mall.com[ DISCUZ_CODE_25 ]quot;) {
- rewrite ^(.*) /mall-mng permanent;
- }
- rewrite ^(.*) /mall permanent;
- } }
创建nginx命令:
- docker run --name nginx -d -p 80:80 \
- -v /docker-data/nginx/html:/usr/share/nginx/html \
- -v /docker-data/nginx/log:/var/log/nginx/ \
- -v /docker-data/nginx/conf.d:/etc/nginx/conf.d \
- nginx
Docker环境搭建入门
原文:https://www.cnblogs.com/coolSome/p/10937027.html