2. Docker部署tomcat, nginx, redis,及docker私有仓库
部署tomcat
1.1 下载tomcat docker pull tomcat:7-jre8
1.2 部署容器 docker run -di --name=tomcat -p 8080:8080 -v /app:/usr/local/tomcat/webapps --privileged=true tomcat:7-jre8
(我们这里是自启动tomcat,并且把宿主机的app文件夹直接映射到容器的webapps文件夹,如果不映射,我们则需要把项目从宿主机中复制到webapps目录下)
1.3 因为容器默认是启动的,它会自动解压war包,所以我们可以直接通过 宿主机ip:宿主机映射端口/url 来访问!
部署nginx
2.1 下载nginx docker pull nginx
2.2 部署容器 docker run -di --name=nginx -p 80:80 nginx:latest (这里我们没有和部署tomcat一样映射文件,所以做任何操作都必须到容器里面的文件夹操作才行)
2.3 配置负载均衡
2.3.1 nginx容器的配置文件在/etc/nginx/nginx.conf文件里,我们先把它copy到宿主机上。
docker cp nginx:/etc/nginx/nginx.conf /nginx.conf
2.3.2 查看tomcat容器的IP地址。 docker inspect tomcat ===》 "IPAddress": "172.17.0.2",
2.3.3 在宿主机修改配置文件 vim /nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
#====================== 上面都是默认配置 =====================
#我们这里自定义一个反向代理
server {
# 监听80端口
listen 80;
server_name www.wulei.com;
location / {#相当于项目的WEB-INF目录
proxy_pass http://172.17.0.2:8080;#监测的是tomcat容器的ip和地址
}
}
}
2.3.4 把改好的配置文件传到容器原来的地方; docker cp /nginx.conf nginx:/etc/nginx/nginx.conf
2.3.5 重启容器, 测试。
部署redis
docker run -itd \ --name my-redis \ -p 6379:6379 \ -v /home/docker/redis/data:/data redis:6.2.4
搭建docker私库
下载仓库镜像
[root@localhost ~]# docker pull registry
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 67fa590cfc1c 2 months ago 202MB
registry latest f32a97de94e1 7 months ago 25.8MB
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 67fa590cfc1c 2 months ago 202MB
registry latest f32a97de94e1 7 months ago 25.8MB
制作容器
[root@localhost ~]# docker run -di --name=myregistry -p 5000:5000 registry
1f23f98bb7da3caab2c185ad7a72a5faa7a1b87862b2e6e8117f61e107a237d9
[root@localhost ~]#
此时浏览器就能访问了,此时由于仓库没有镜像,所以是空数组:http://127.0.0.1:5000/v2/_catalog
私库镜像上传及下载
修改配置文件,是docker信任远程仓库(添加 {"insecure-registries":["192.168.21.101:5000"]} )
[root@localhost ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["http://4e70ba5d.m.daocloud.io"] ,
"insecure-registries":["192.168.21.101:5000"]
}
重启
[root@localhost ~]# systemctl restart docker
[root@localhost file]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jdk1.8 latest b591f5c69edd 40 minutes ago 584MB
centos 7 67fa590cfc1c 2 months ago 202MB
registry latest f32a97de94e1 7 months ago 25.8MB
给镜像打标签
[root@localhost ~]# docker tag jdk1.8 192.168.21.101:5000/jdk1.8
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.21.101:5000/jdk1.8 latest b591f5c69edd 44 minutes ago 584MB
jdk1.8 latest b591f5c69edd 44 minutes ago 584MB
centos 7 67fa590cfc1c 2 months ago 202MB
registry latest f32a97de94e1 7 months ago 25.8MB
上传镜像
[root@localhost ~]# docker push 192.168.21.101:5000/jdk1.8
The push refers to repository [192.168.21.101:5000/jdk1.8]
aab02c8aa0ce: Pushing 125.4MB/381.7MB
bd90af6019ef: Pushed
877b494a9f30: Pushing 48.89MB/201.9MB
下载镜像
docker pull 192.168.21.101:5000/jdk1.8
部署mysql
部署启动 指定容器名称为mysql 存储地址挂载到宿主机 端口映射为3306 指定ROOT账户的密码为root
docker run --name mysql -v /opt/data/mysql:/var/lib/mysql -p3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.4
部署rabbitmq
这里直接用run命令,如果本地没有这个镜像的话,docker会先去下载
docker run -d --hostname my-rabbit --name rabbit -p 15672:15672 -p5672:5672 daocloud.io/library/rabbitmq:3.6.10-management
部署zookeeper
[root@docker ~]# docker run --name zookeeper -v /opt/data/zksingle:/data -p 2181:2181 -e ZOO_LOG4J_PROP="INFO,ROLLINGFILE" -d zookeeper:3.4.13 Unable to find image 'zookeeper:3.4.13' locally 3.4.13: Pulling from library/zookeeper 8e402f1a9c57: Pull complete 4866c822999c: Pull complete cf419f3f41ff: Pull complete 88430b15d43f: Pull complete d5a9723280f1: Pull complete c43110341cd8: Pull complete 9ec9c92edf13: Pull complete cdf8329cd90a: Pull complete Digest: sha256:8832a49f7ee6399c608e9a666e294adeaef0e4b1bc540c60ac75b8ec4b41f572 Status: Downloaded newer image for zookeeper:3.4.13 34c73b01afc7dd8a2e04aa8e5f91d8f9ee5add1e353f3f65df05bf33290c8a04 [root@docker ~]# docker ps | grep zookeeper 34c73b01afc7 zookeeper:3.4.13 "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 2888/tcp, 0.0.0.0:2181->2181/tcp, 3888/tcp zookeeper [root@docker ~]#
部署nacos
mysql脚本
/* Navicat Premium Data Transfer Source Server : 192.168.200.100 Source Server Type : MySQL Source Server Version : 50734 Source Host : 192.168.200.100:3306 Source Schema : nacos_config Target Server Type : MySQL Target Server Version : 50734 File Encoding : 65001 Date: 11/12/2021 12:03:21 */ SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for config_info -- ---------------------------- DROP TABLE IF EXISTS `config_info`; CREATE TABLE `config_info` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', `data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'data_id', `group_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `content` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'content', `md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'md5', `gmt_create` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', `src_user` text CHARACTER SET utf8 COLLATE utf8_bin NULL COMMENT 'source user', `src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'source ip', `app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT '租户字段', `c_desc` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `c_use` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `effect` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `type` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `c_schema` text CHARACTER SET utf8 COLLATE utf8_bin NULL, PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_configinfo_datagrouptenant`(`data_id`, `group_id`, `tenant_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'config_info' ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for config_info_aggr -- ---------------------------- DROP TABLE IF EXISTS `config_info_aggr`; CREATE TABLE `config_info_aggr` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', `data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'data_id', `group_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'group_id', `datum_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'datum_id', `content` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '内容', `gmt_modified` datetime(0) NOT NULL COMMENT '修改时间', `app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT '租户字段', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_configinfoaggr_datagrouptenantdatum`(`data_id`, `group_id`, `tenant_id`, `datum_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '增加租户字段' ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for config_info_beta -- ---------------------------- DROP TABLE IF EXISTS `config_info_beta`; CREATE TABLE `config_info_beta` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', `data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'data_id', `group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'group_id', `app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'app_name', `content` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'content', `beta_ips` varchar(1024) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'betaIps', `md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'md5', `gmt_create` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', `src_user` text CHARACTER SET utf8 COLLATE utf8_bin NULL COMMENT 'source user', `src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'source ip', `tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT '租户字段', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_configinfobeta_datagrouptenant`(`data_id`, `group_id`, `tenant_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'config_info_beta' ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for config_info_tag -- ---------------------------- DROP TABLE IF EXISTS `config_info_tag`; CREATE TABLE `config_info_tag` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', `data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'data_id', `group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'group_id', `tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT 'tenant_id', `tag_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'tag_id', `app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'app_name', `content` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'content', `md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'md5', `gmt_create` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', `src_user` text CHARACTER SET utf8 COLLATE utf8_bin NULL COMMENT 'source user', `src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'source ip', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_configinfotag_datagrouptenanttag`(`data_id`, `group_id`, `tenant_id`, `tag_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'config_info_tag' ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for config_tags_relation -- ---------------------------- DROP TABLE IF EXISTS `config_tags_relation`; CREATE TABLE `config_tags_relation` ( `id` bigint(20) NOT NULL COMMENT 'id', `tag_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'tag_name', `tag_type` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'tag_type', `data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'data_id', `group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'group_id', `tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT 'tenant_id', `nid` bigint(20) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`nid`) USING BTREE, UNIQUE INDEX `uk_configtagrelation_configidtag`(`id`, `tag_name`, `tag_type`) USING BTREE, INDEX `idx_tenant_id`(`tenant_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'config_tag_relation' ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for group_capacity -- ---------------------------- DROP TABLE IF EXISTS `group_capacity`; CREATE TABLE `group_capacity` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID', `group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'Group ID,空字符表示整个集群', `quota` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '配额,0表示使用默认值', `usage` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '使用量', `max_size` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '单个配置大小上限,单位为字节,0表示使用默认值', `max_aggr_count` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '聚合子配置最大个数,,0表示使用默认值', `max_aggr_size` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值', `max_history_count` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最大变更历史数量', `gmt_create` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_group_id`(`group_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '集群、各Group容量信息表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for his_config_info -- ---------------------------- DROP TABLE IF EXISTS `his_config_info`; CREATE TABLE `his_config_info` ( `id` bigint(64) UNSIGNED NOT NULL, `nid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'app_name', `content` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `gmt_create` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP, `gmt_modified` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP, `src_user` text CHARACTER SET utf8 COLLATE utf8_bin NULL, `src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `op_type` char(10) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT '租户字段', PRIMARY KEY (`nid`) USING BTREE, INDEX `idx_gmt_create`(`gmt_create`) USING BTREE, INDEX `idx_gmt_modified`(`gmt_modified`) USING BTREE, INDEX `idx_did`(`data_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '多租户改造' ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for permissions -- ---------------------------- DROP TABLE IF EXISTS `permissions`; CREATE TABLE `permissions` ( `role` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, `resource` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, `action` varchar(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, UNIQUE INDEX `uk_role_permission`(`role`, `resource`, `action`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for roles -- ---------------------------- DROP TABLE IF EXISTS `roles`; CREATE TABLE `roles` ( `username` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, `role` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, UNIQUE INDEX `idx_user_role`(`username`, `role`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of roles -- ---------------------------- INSERT INTO `roles` VALUES ('nacos', 'ROLE_ADMIN'); -- ---------------------------- -- Table structure for tenant_capacity -- ---------------------------- DROP TABLE IF EXISTS `tenant_capacity`; CREATE TABLE `tenant_capacity` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID', `tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'Tenant ID', `quota` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '配额,0表示使用默认值', `usage` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '使用量', `max_size` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '单个配置大小上限,单位为字节,0表示使用默认值', `max_aggr_count` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '聚合子配置最大个数', `max_aggr_size` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值', `max_history_count` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最大变更历史数量', `gmt_create` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_tenant_id`(`tenant_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '租户容量信息表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for tenant_info -- ---------------------------- DROP TABLE IF EXISTS `tenant_info`; CREATE TABLE `tenant_info` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', `kp` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'kp', `tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT 'tenant_id', `tenant_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT 'tenant_name', `tenant_desc` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'tenant_desc', `create_source` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'create_source', `gmt_create` bigint(20) NOT NULL COMMENT '创建时间', `gmt_modified` bigint(20) NOT NULL COMMENT '修改时间', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_tenant_info_kptenantid`(`kp`, `tenant_id`) USING BTREE, INDEX `idx_tenant_id`(`tenant_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'tenant_info' ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for users -- ---------------------------- DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `username` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, `password` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, `enabled` tinyint(1) NOT NULL, PRIMARY KEY (`username`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of users -- ---------------------------- INSERT INTO `users` VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1); SET FOREIGN_KEY_CHECKS = 1;
安装并启动nacos
docker run -d \ -e NACOS_AUTH_ENABLE=true \ -e MODE=standalone \ -e JVM_XMS=128m \ -e JVM_XMX=128m \ -e JVM_XMN=128m \ -p 8848:8848 \ -e SPRING_DATASOURCE_PLATFORM=mysql \ -e MYSQL_SERVICE_HOST=192.168.200.100 \ -e MYSQL_SERVICE_PORT=3306 \ -e MYSQL_SERVICE_USER=root \ -e MYSQL_SERVICE_PASSWORD=123456 \ -e MYSQL_SERVICE_DB_NAME=nacos_config \ -e MYSQL_SERVICE_DB_PARAM='characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useSSL=false' \ --restart=always \ --privileged=true \ -v /home/data/nacos/logs:/home/nacos/logs \ --name wulei_nacos \ nacos/nacos-server:2.0.2
docker-compose
安装dockercompose,并放到 /usr/local/bin 目录。如果能看到版本号就是启动成功了
https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-linux-x86_64 sudo mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose docker-compose -v
编写配置
vim docker-compose-nginx.yml
version: '3' services: nginx: image: nginx restart: always hostname: nginx container_name: nginx privileged: true ports: - 80:80 volumes: #此处为nginx配置文件 - /apps/nginx/config/nginx.conf:/etc/nginx/nginx.conf #此处为nginx示例的index目录 - /apps/nginx/home/:/usr/share/nginx/html/ #此处为日志目录 - /apps/nginx/logs/:/var/log/nginx/
【1】 mkdir -p /apps/nginx/{config,data,logs,home} 【2】 vim /apps/nginx/config/nginx.conf worker_processes 2; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; keepalive_timeout 65; server{ listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.html; } } } 【3】 vim /apps/nginx/home/index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>docker搭建nginx</title> </head> <body> <h1>Hello World!</h1> </body> </html>
启动与停止
cd /usr/local/bin/ docker-compose -f /usr/local/wulei/docker-compose-nginx.yml down docker-compose -f /usr/local/wulei/docker-compose-nginx.yml up -d
。