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
docker-compose:批量管理docker容器
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
systemctl enable docker --now
这个命令的作用是设置docker开机启动并且现在启动,是将原来的启动docker的命令和设置docker开机启动的命令合并的
# 启动docker
systemctl start docker
# 设置docker开机启动
systemctl enable docker
去自己的阿里云的控制台,搜索容器镜像,然后选择镜像加速器,把Centos里面的复制出来运行
docker run [参数项] 镜像(镜像名:tag) [镜像的启动命令] [参数...]
-p 外部端口:内部端口
docker run -d -p 88:80 nginx:1.23.2
docker run -d -p 88:80 -v /app/nginx/html:/usr/share/nginx/html nginx:1.23.2
这样的话修改首页就不需要再进去容器了,直接在外层修改就可以了
继续优化
docker run -d -p 88:80 -v /app/nginx/html:/usr/share/nginx/html -v nginxconf:/etc/nginx nginx:1.23.2
-v 绝对路径:容器内部路径
挂载:在linux主机外部这个绝对路径位置和容器内部进行映射
-v /app/nginx/conf:/etc/nginx
效果:以外部为准
-v 随便不以/开始:容器内部路径
绑定:-v nginxconf:/etc/nginx
docker内部管理了一个卷名叫 nginxconf,
查看docker容器的ip地址
docker inspect [CONTAINER ID]
IPAddress就是docker给里面的容器分配的ip地址
假设tomcat要链接的nginx是172.17.0.2的ip地址
带88端口还不通,得带默认80端口
docker每启动一个容器都会在当前主机内部,给这个容器分配一个唯一ip,容器之间直接可以使用这个ip访问即可;
推荐使用自定义网络来启动所有容器,这样使用容器的名字也能访问
启动一个容器的三要素:挂载、网络、端口映射
docker run -p xxx -v xxx --network xx --name 容器名 镜像
编写一个compose.yaml批量文件。配置好要启动哪些容器,怎么启动,怎么挂载等
docker compose -f compose.yaml up -d #后台启动compose.yaml中指定的所有容器,上线所有容器
docker compose -f compose.yaml down #下线:删除所有容器和网络,数据不删
docker compose -f compose.yaml stop #批量停
docker compose -f compose.yaml start #批量启
docker compose -f compose.yaml restart #批量重启
#服务
services:
mysql-01:
#镜像
image: mysql:5.7
#端口映射
ports:
- "3306:3306"
#卷
volumes:
- "mysql01-log:/var/log/mysql"
- "mysql01-data:/var/lib/mysql"
- "mysql01-conf:/etc/mysql/conf.d"
#容器退出之后自动重启
restart: always
#环境变量
environment:
- "MYSQL_ROOT_PASSWORD=root"
#自定义网络
networks:
- mall-net
#卷
volumes:
mysql01-log:
mysql01-data:
mysql01-conf:
#k8s管理docker集群
networks:
mall-net:
ipam:
driver: default
config:
- subnet: 172.100.0.0/16
#服务
services:
mysql-01:
#镜像
image: mysql:5.7
#端口映射
ports:
- "3306:3306"
#卷
volumes:
- "mysql01-log:/var/log/mysql"
- "mysql01-data:/var/lib/mysql"
- "mysql01-conf:/etc/mysql/conf.d"
#开机自启动
restart: always
#环境变量
environment:
- "MYSQL_ROOT_PASSWORD=root"
#自定义网络
networks:
- mall-net
mysql-02:
#镜像
image: mysql:5.7
#端口映射
ports:
- "3307:3306"
#卷
volumes:
- "mysql02-log:/var/log/mysql"
- "mysql02-data:/var/lib/mysql"
- "mysql02-conf:/etc/mysql/conf.d"
#开机自启动
restart: always
#环境变量
environment:
- "MYSQL_ROOT_PASSWORD=root"
#自定义网络
networks:
- mall-net
depends_on:
- mysql-01
mysql-03:
#镜像
image: mysql:5.7
#端口映射
ports:
- "3308:3306"
#卷
volumes:
- "mysql03-log:/var/log/mysql"
- "mysql03-data:/var/lib/mysql"
- "mysql03-conf:/etc/mysql/conf.d"
#开机自启动
restart: always
#环境变量
environment:
- "MYSQL_ROOT_PASSWORD=root"
#自定义网络
networks:
- mall-net
depends_on:
- mysql-01
redis:
image: redis:6.2.5
ports:
- "6379:6379"
volumes:
- "redis-data:/data"
- "redis-conf:/etc/redis" #redis-conf位置自己创建一个 redis.conf 文件,就是redis的配置文件。 redis-server
restart: always
entrypoint: ["redis-server","/etc/redis/redis.conf"]
networks:
- mall-net
elasticsearch:
image: elasticsearch:7.13.4
ports:
- "9200:9200"
- "9300:9300"
environment:
- "discovery.type=single-node" #ES以单节点方式启动
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" #ES启动时占用的内存大小
- "bootstrap.memory_lock=true" #内存锁死,不让动态扩容
volumes:
- "es-config:/usr/share/elasticsearch/config"
- "es-data:/usr/share/elasticsearch/data"
- "es-plugin:/usr/share/elasticsearch/plugins"
#限制数
ulimits:
nproc: 65535
nofile:
soft: 65535
hard: 65535
memlock: -1
restart: always
networks:
- mall-net
#elasticsearch的可视化工具
kibana:
image: kibana:7.13.4
ports:
- "5601:5601"
environment:
- "ELASTICSEARCH_HOSTS=http://elasticsearch:9200"
restart: always
networks:
- mall-net
#日志收集器
filebeat:
image: elastic/filebeat:7.13.4
volumes:
- "/var/log:/var/log" #挂主机整个日志文件夹
- "filebeat-conf:/usr/share/filebeat"
restart: always
networks:
- mall-net
rabbitmq:
image: rabbitmq:3.8-management
environment:
- "RABBITMQ_DEFAULT_USER=admin"
- "RABBITMQ_DEFAULT_PASS=admin"
ports:
- "15672:15672" #web管理界面的访问端口
- "5672:5672" #发消息的端口
volumes:
- "rabbit-data:/var/lib/rabbitmq"
- "rabbit-conf:/etc/rabbitmq"
hostname: rabbitmq
restart: always
networks:
- mall-net
zipkin:
image: openzipkin/zipkin:2
ports:
- "9411:9411"
restart: always
networks:
- mall-net
sentinel:
image: leifengyang/sentinel:1.8.2
ports:
- "8858:8080"
restart: always
networks:
- mall-net
nacos:
image: nacos/nacos-server:2.0.2
ports:
- "8848:8848"
environment:
- "MODE=standalone" #单节点模式
- "SPRING_DATASOURCE_PLATFORM=mysql" #指定nacos要操作的平台
- "MYSQL_SERVER_HOST=mysql-01"
- "MYSQL_SERVER_PORT=3306"
- "MYSQL_SERVER_DB_NAME=nacos_db"
- "MYSQL_SERVER_USER=root"
- "MYSQL_SERVER_PASSWORD=root"
- "JVM_XMX=256m"
- "JVM_XMS=256m"
volumes:
- "nacos-conf:/home/nacos/init.d"
restart: always
networks:
- mall-net
#分布式对象存储
minio:
image: minio/minio
ports:
- "9000:9000"
- "9001:9001"
environment:
- "MINIO_ACCESS_KEY=admin"
- "MINIO_SECRET_KEY=admin123456"
volumes:
- "minio-data:/data"
- "minio-conf:/root/.minio"
- "/etc/localtime:/etc/localtime:ro"
command: [ "server","--console-address",":9001","/data" ]
restart: always
networks:
- mall-net
nginx:
image: nginx:1.22.0
ports:
- "80:80"
volumes:
- "nginx-html:/usr/share/nginx/html"
- "nginx-conf:/etc/nginx"
restart: always
networks:
- mall-net
#卷
volumes:
mysql01-log:
mysql01-data:
mysql01-conf:
mysql02-log:
mysql02-data:
mysql02-conf:
mysql03-log:
mysql03-data:
mysql03-conf:
redis-data:
redis-conf:
es-config:
es-data:
es-plugin:
filebeat-conf:
rabbit-data:
rabbit-conf:
nacos-conf:
minio-data:
minio-conf:
nginx-html:
nginx-conf:
#k8s管理docker集群
networks:
mall-net:
ipam:
driver: default
config:
- subnet: 172.100.0.0/16
docker rm -f $(docker ps -aq)
docker volume ls
docker volume prune
docker system prune
docker image prune
yum install lrzsz -y
输入rz选择文件上传
组件 | 访问地址 | 账号密码 |
---|---|---|
mysql-01 | 服务器ip:3306 | root/root |
mysql-02 | 服务器ip:3307 | root/root |
mysql-03 | 服务器ip:3308 | root/root |
redis | 服务器ip:6379 | |
filebeat | ||
kibana | 服务器ip:5601 | |
elasticsearch | 服务器ip:9200 | |
nacos | 服务器ip:8848 | nacos/nacos |
nginx | 服务器ip | |
sentinel | 服务器ip:8858 | sentinel/sentinel |
rabbitmq | 服务器ip:15672 | admin/admin |
zipkin | 服务器ip:9411 | |
minio | 服务器ip:9000 | admin/admin123456 |
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
init_connect='SET collation_connection = utf8mb4_unicode_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
[mysqld]
server-id=1
log-bin=mysql-bin
binlog-ignore-db=mysql
binlog-ignore-db=infomation_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
binlog_format=STATEMENT
[mysqld]
server-id=2
relay-log=mysql-relay
[mysqld]
server-id=3
relay-log=mysql-relay
两个从服务器的配置的server-id是不一样的
然后重启mysql
#分配了一个 slave账号密码是 123456,以后从机就用这个账密链接主机
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' IDENTIFIED BY '123456';
flush privileges;
CHANGE MASTER TO MASTER_HOST='mysql-01',
MASTER_USER='slave',MASTER_PASSWORD='123456',
MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=0;
start slave; #开启从同步
show slave status; #查看同步状态,一定要都是 YES YES
appendonly yes
bind 0.0.0.0
port 6379
requirepass NewBeeMu #密码
进入nacos的github,选择2.0.2版本,nacos-mysql.sql
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/******************************************/
/* 数据库全名 = nacos_config */
/* 表名称 = config_info */
/******************************************/
CREATE TABLE `config_info` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`data_id` varchar(255) NOT NULL COMMENT 'data_id',
`group_id` varchar(255) DEFAULT NULL,
`content` longtext NOT NULL COMMENT 'content',
`md5` varchar(32) DEFAULT NULL COMMENT 'md5',
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
`src_user` text COMMENT 'source user',
`src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
`app_name` varchar(128) DEFAULT NULL,
`tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
`c_desc` varchar(256) DEFAULT NULL,
`c_use` varchar(64) DEFAULT NULL,
`effect` varchar(64) DEFAULT NULL,
`type` varchar(64) DEFAULT NULL,
`c_schema` text,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_configinfo_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info';
/******************************************/
/* 数据库全名 = nacos_config */
/* 表名称 = config_info_aggr */
/******************************************/
CREATE TABLE `config_info_aggr` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`data_id` varchar(255) NOT NULL COMMENT 'data_id',
`group_id` varchar(255) NOT NULL COMMENT 'group_id',
`datum_id` varchar(255) NOT NULL COMMENT 'datum_id',
`content` longtext NOT NULL COMMENT '内容',
`gmt_modified` datetime NOT NULL COMMENT '修改时间',
`app_name` varchar(128) DEFAULT NULL,
`tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_configinfoaggr_datagrouptenantdatum` (`data_id`,`group_id`,`tenant_id`,`datum_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='增加租户字段';
/******************************************/
/* 数据库全名 = nacos_config */
/* 表名称 = config_info_beta */
/******************************************/
CREATE TABLE `config_info_beta` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`data_id` varchar(255) NOT NULL COMMENT 'data_id',
`group_id` varchar(128) NOT NULL COMMENT 'group_id',
`app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
`content` longtext NOT NULL COMMENT 'content',
`beta_ips` varchar(1024) DEFAULT NULL COMMENT 'betaIps',
`md5` varchar(32) DEFAULT NULL COMMENT 'md5',
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
`src_user` text COMMENT 'source user',
`src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
`tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_configinfobeta_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_beta';
/******************************************/
/* 数据库全名 = nacos_config */
/* 表名称 = config_info_tag */
/******************************************/
CREATE TABLE `config_info_tag` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`data_id` varchar(255) NOT NULL COMMENT 'data_id',
`group_id` varchar(128) NOT NULL COMMENT 'group_id',
`tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id',
`tag_id` varchar(128) NOT NULL COMMENT 'tag_id',
`app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
`content` longtext NOT NULL COMMENT 'content',
`md5` varchar(32) DEFAULT NULL COMMENT 'md5',
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
`src_user` text COMMENT 'source user',
`src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_configinfotag_datagrouptenanttag` (`data_id`,`group_id`,`tenant_id`,`tag_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_tag';
/******************************************/
/* 数据库全名 = nacos_config */
/* 表名称 = config_tags_relation */
/******************************************/
CREATE TABLE `config_tags_relation` (
`id` bigint(20) NOT NULL COMMENT 'id',
`tag_name` varchar(128) NOT NULL COMMENT 'tag_name',
`tag_type` varchar(64) DEFAULT NULL COMMENT 'tag_type',
`data_id` varchar(255) NOT NULL COMMENT 'data_id',
`group_id` varchar(128) NOT NULL COMMENT 'group_id',
`tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id',
`nid` bigint(20) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`nid`),
UNIQUE KEY `uk_configtagrelation_configidtag` (`id`,`tag_name`,`tag_type`),
KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_tag_relation';
/******************************************/
/* 数据库全名 = nacos_config */
/* 表名称 = group_capacity */
/******************************************/
CREATE TABLE `group_capacity` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`group_id` varchar(128) 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 NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='集群、各Group容量信息表';
/******************************************/
/* 数据库全名 = nacos_config */
/* 表名称 = 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) NOT NULL,
`group_id` varchar(128) NOT NULL,
`app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
`content` longtext NOT NULL,
`md5` varchar(32) DEFAULT NULL,
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`src_user` text,
`src_ip` varchar(50) DEFAULT NULL,
`op_type` char(10) DEFAULT NULL,
`tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
PRIMARY KEY (`nid`),
KEY `idx_gmt_create` (`gmt_create`),
KEY `idx_gmt_modified` (`gmt_modified`),
KEY `idx_did` (`data_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='多租户改造';
/******************************************/
/* 数据库全名 = nacos_config */
/* 表名称 = tenant_capacity */
/******************************************/
CREATE TABLE `tenant_capacity` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`tenant_id` varchar(128) 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 NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='租户容量信息表';
CREATE TABLE `tenant_info` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`kp` varchar(128) NOT NULL COMMENT 'kp',
`tenant_id` varchar(128) default '' COMMENT 'tenant_id',
`tenant_name` varchar(128) default '' COMMENT 'tenant_name',
`tenant_desc` varchar(256) DEFAULT NULL COMMENT 'tenant_desc',
`create_source` varchar(32) DEFAULT NULL COMMENT 'create_source',
`gmt_create` bigint(20) NOT NULL COMMENT '创建时间',
`gmt_modified` bigint(20) NOT NULL COMMENT '修改时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_tenant_info_kptenantid` (`kp`,`tenant_id`),
KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='tenant_info';
CREATE TABLE `users` (
`username` varchar(50) NOT NULL PRIMARY KEY,
`password` varchar(500) NOT NULL,
`enabled` boolean NOT NULL
);
CREATE TABLE `roles` (
`username` varchar(50) NOT NULL,
`role` varchar(50) NOT NULL,
UNIQUE INDEX `idx_user_role` (`username` ASC, `role` ASC) USING BTREE
);
CREATE TABLE `permissions` (
`role` varchar(50) NOT NULL,
`resource` varchar(255) NOT NULL,
`action` varchar(8) NOT NULL,
UNIQUE INDEX `uk_role_permission` (`role`,`resource`,`action`) USING BTREE
);
INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE);
INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');
服务器ip:8848/nacos 用户名/密码:nacos/nacos