赞
踩
- yum install wget.x86_64 -y
- rm -rf /etc/yum.repos.d/*
- wget -O /etc/yum.repos.d/centos7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
- wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
- wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- yum install docker-ce-20.10.11 -y
- systemctl start docker
- systemctl enable docker
- docker version
配置docker加速器
- mkdir -p /etc/docker
- tee /etc/docker/daemon.json <<-'EOF'
- {
- "registry-mirrors": ["https://2tefyfv7.mirror.aliyuncs.com"]
- }
- EOF
- systemctl daemon-reload
- systemctl restart docker
- #可以自己选择安装的数据库版本
- docker pull mysql:8.0.27
- #下载完成后创建在/home/mysql/下新建两个对应文件夹,可以代码实现,也可以通过图形化工具手动创建
- mkdir -p /home/mysql/{date,conf}
- #创建完成后在conf文件中新建my.conf文件进行配置:
创建my.cnf文件
vim /home/mysql/conf/my.cnf
- [mysqld]
- #Mysql服务的唯一编号 每个mysql服务Id需唯一
- server-id=1
-
- #服务端口号 默认3306
- port=3306
-
- #mysql安装根目录(default /usr)
- #basedir=/usr/local/mysql
-
- #mysql数据文件所在位置
- datadir=/var/lib/mysql
-
- #pid
- pid-file=/var/run/mysqld/mysqld.pid
-
- #设置socke文件所在目录
- socket=/var/lib/mysql/mysql.sock
-
- #设置临时目录
- #tmpdir=/tmp
-
- # 用户
- user=mysql
-
- # 允许访问的IP网段
- bind-address=0.0.0.0
-
- # 跳过密码登录
- #skip-grant-tables
-
- #主要用于MyISAM存储引擎,如果多台服务器连接一个数据库则建议注释下面内容
- #skip-external-locking
-
- #只能用IP地址检查客户端的登录,不用主机名
- #skip_name_resolve=1
-
- #事务隔离级别,默认为可重复读,mysql默认可重复读级别(此级别下可能参数很多间隙锁,影响性能)
- #transaction_isolation=READ-COMMITTED
-
- #数据库默认字符集,主流字符集支持一些特殊表情符号(特殊表情符占用4个字节)
- character-set-server=utf8mb4
-
- #数据库字符集对应一些排序等规则,注意要和character-set-server对应
- collation-server=utf8mb4_general_ci
-
- #设置client连接mysql时的字符集,防止乱码
- init_connect='SET NAMES utf8mb4'
-
- #是否对sql语句大小写敏感,1表示不敏感
- lower_case_table_names=1
-
- #最大连接数
- max_connections=400
-
- #最大错误连接数
- max_connect_errors=1000
-
- #TIMESTAMP如果没有显示声明NOT NULL,允许NULL值
- explicit_defaults_for_timestamp=true
-
- #SQL数据包发送的大小,如果有BLOB对象建议修改成1G
- max_allowed_packet=128M
-
- #MySQL连接闲置超过一定时间后(单位:秒)将会被强行关闭
- #MySQL默认的wait_timeout 值为8个小时, interactive_timeout参数需要同时配置才能生效
- interactive_timeout=1800
- wait_timeout=1800
-
- #内部内存临时表的最大值 ,设置成128M。
- #比如大数据量的group by ,order by时可能用到临时表,
- #超过了这个值将写入磁盘,系统IO压力增大
- tmp_table_size=134217728
- max_heap_table_size=134217728
-
- #禁用mysql的缓存查询结果集功能
- #后期根据业务情况测试决定是否开启
- #大部分情况下关闭下面两项
- #query_cache_size = 0
- #query_cache_type = 0
-
- #数据库错误日志文件
- #log-error=/var/log/mysqld.log
-
- #慢查询sql日志设置
- #slow_query_log=1
- #slow_query_log_file=/var/log/mysqld_slow.log
-
- #检查未使用到索引的sql
- log_queries_not_using_indexes=1
-
- #针对log_queries_not_using_indexes开启后,记录慢sql的频次、每分钟记录的条数
- log_throttle_queries_not_using_indexes=5
-
- #作为从库时生效,从库复制中如何有慢sql也将被记录
- log_slow_slave_statements=1
-
- #慢查询执行的秒数,必须达到此值可被记录
- long_query_time=8
-
- #检索的行数必须达到此值才可被记为慢查询
- min_examined_row_limit=100
-
- #mysql binlog日志文件保存的过期时间,过期后自动删除
- #expire_logs_days=5
- binlog_expire_logs_seconds=604800
启动MySQL容器
docker run -itd -p 3306:3306 --name mysql -v /home/mysql/conf/my.cnf:/etc/my.cnf -v /home/mysql/data:/var/lib/mysql --privileged=true --restart=always -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.27
初始账号密码:root/root
使用工具连接mysql
如果测试连接报错:
Public Key Retrieval is not allowed Public Key Retrieval is not allowed
修改连接属性
拉取对应的镜像文件
docker pull nacos/nacos-server:v2.1.1
挂载目录:
-
- mkdir -p /mydata/nacos/logs/ #新建logs目录
启动nacos容器
- docker run \
- --name nacos -d \
- -p 8848:8848 \
- --privileged=true \
- --restart=always \
- -e JVM_XMS=256m \
- -e JVM_XMX=256m \
- -e MODE=standalone \
- -e PREFER_HOST_MODE=hostname \
- -v /mydata/nacos/logs:/home/nacos/logs \
- nacos/nacos-server:v2.1.1
此时nacos容器就安装成功了可以打开浏览器进行登录:
账号:nacos 密码:nacos
Nacos 以standalone(单机模式)启动后,默认使用的内嵌式数据库 Derby;
在MySQL中创建nacos数据库
执行sql脚本
- -- nacos.config_info definition
-
- CREATE TABLE `config_info` (
- `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id',
- `data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT 'data_id',
- `group_id` varchar(255) COLLATE utf8_bin DEFAULT NULL,
- `content` longtext CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'content',
- `md5` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT 'md5',
- `gmt_create` datetime DEFAULT '2010-05-05 00:00:00' COMMENT '创建时间',
- `gmt_modified` datetime DEFAULT '2010-05-05 00:00:00' COMMENT '修改时间',
- `src_user` text COLLATE utf8_bin COMMENT 'source user',
- `src_ip` varchar(20) COLLATE utf8_bin DEFAULT NULL COMMENT 'source ip',
- `app_name` varchar(128) COLLATE utf8_bin DEFAULT NULL,
- `tenant_id` varchar(128) COLLATE utf8_bin DEFAULT '' COMMENT '租户字段',
- `c_desc` varchar(256) COLLATE utf8_bin DEFAULT NULL,
- `c_use` varchar(64) COLLATE utf8_bin DEFAULT NULL,
- `effect` varchar(64) COLLATE utf8_bin DEFAULT NULL,
- `type` varchar(64) COLLATE utf8_bin DEFAULT NULL,
- `c_schema` text COLLATE utf8_bin,
- `encrypted_data_key` varchar(255) COLLATE utf8_bin DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `uk_configinfo_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='config_info';
-
-
- -- nacos.config_info_aggr definition
-
- CREATE TABLE `config_info_aggr` (
- `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id',
- `data_id` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'data_id',
- `group_id` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'group_id',
- `datum_id` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'datum_id',
- `content` longtext COLLATE utf8_bin NOT NULL COMMENT '内容',
- `gmt_modified` datetime NOT NULL COMMENT '修改时间',
- `app_name` varchar(128) COLLATE utf8_bin DEFAULT NULL,
- `tenant_id` varchar(128) COLLATE utf8_bin DEFAULT '' COMMENT '租户字段',
- PRIMARY KEY (`id`),
- UNIQUE KEY `uk_configinfoaggr_datagrouptenantdatum` (`data_id`,`group_id`,`tenant_id`,`datum_id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='增加租户字段';
-
-
- -- nacos.config_info_beta definition
-
- CREATE TABLE `config_info_beta` (
- `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id',
- `data_id` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'data_id',
- `group_id` varchar(128) COLLATE utf8_bin NOT NULL COMMENT 'group_id',
- `app_name` varchar(128) COLLATE utf8_bin DEFAULT NULL COMMENT 'app_name',
- `content` longtext COLLATE utf8_bin NOT NULL COMMENT 'content',
- `beta_ips` varchar(1024) COLLATE utf8_bin DEFAULT NULL COMMENT 'betaIps',
- `md5` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT 'md5',
- `gmt_create` datetime NOT NULL DEFAULT '2010-05-05 00:00:00' COMMENT '创建时间',
- `gmt_modified` datetime NOT NULL DEFAULT '2010-05-05 00:00:00' COMMENT '修改时间',
- `src_user` text COLLATE utf8_bin COMMENT 'source user',
- `src_ip` varchar(20) COLLATE utf8_bin DEFAULT NULL COMMENT 'source ip',
- `tenant_id` varchar(128) COLLATE utf8_bin DEFAULT '' COMMENT '租户字段',
- PRIMARY KEY (`id`),
- UNIQUE KEY `uk_configinfobeta_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='config_info_beta';
-
-
- -- nacos.config_info_tag definition
-
- CREATE TABLE `config_info_tag` (
- `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id',
- `data_id` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'data_id',
- `group_id` varchar(128) COLLATE utf8_bin NOT NULL COMMENT 'group_id',
- `tenant_id` varchar(128) COLLATE utf8_bin DEFAULT '' COMMENT 'tenant_id',
- `tag_id` varchar(128) COLLATE utf8_bin NOT NULL COMMENT 'tag_id',
- `app_name` varchar(128) COLLATE utf8_bin DEFAULT NULL COMMENT 'app_name',
- `content` longtext COLLATE utf8_bin NOT NULL COMMENT 'content',
- `md5` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT 'md5',
- `gmt_create` datetime NOT NULL DEFAULT '2010-05-05 00:00:00' COMMENT '创建时间',
- `gmt_modified` datetime NOT NULL DEFAULT '2010-05-05 00:00:00' COMMENT '修改时间',
- `src_user` text COLLATE utf8_bin COMMENT 'source user',
- `src_ip` varchar(20) COLLATE utf8_bin 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=utf8mb3 COLLATE=utf8_bin COMMENT='config_info_tag';
-
-
- -- nacos.config_tags_relation definition
-
- CREATE TABLE `config_tags_relation` (
- `id` bigint NOT NULL COMMENT 'id',
- `tag_name` varchar(128) COLLATE utf8_bin NOT NULL COMMENT 'tag_name',
- `tag_type` varchar(64) COLLATE utf8_bin DEFAULT NULL COMMENT 'tag_type',
- `data_id` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'data_id',
- `group_id` varchar(128) COLLATE utf8_bin NOT NULL COMMENT 'group_id',
- `tenant_id` varchar(128) COLLATE utf8_bin DEFAULT '' COMMENT 'tenant_id',
- `nid` bigint 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=utf8mb3 COLLATE=utf8_bin COMMENT='config_tag_relation';
-
-
- -- nacos.group_capacity definition
-
- CREATE TABLE `group_capacity` (
- `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
- `group_id` varchar(128) COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'Group ID,空字符表示整个集群',
- `quota` int unsigned NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值',
- `usage` int unsigned NOT NULL DEFAULT '0' COMMENT '使用量',
- `max_size` int unsigned NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
- `max_aggr_count` int unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数,,0表示使用默认值',
- `max_aggr_size` int unsigned NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
- `max_history_count` int unsigned NOT NULL DEFAULT '0' COMMENT '最大变更历史数量',
- `gmt_create` datetime NOT NULL DEFAULT '2010-05-05 00:00:00' COMMENT '创建时间',
- `gmt_modified` datetime NOT NULL DEFAULT '2010-05-05 00:00:00' COMMENT '修改时间',
- PRIMARY KEY (`id`),
- UNIQUE KEY `uk_group_id` (`group_id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='集群、各Group容量信息表';
-
-
- -- nacos.his_config_info definition
-
- CREATE TABLE `his_config_info` (
- `id` bigint unsigned NOT NULL,
- `nid` bigint unsigned NOT NULL AUTO_INCREMENT,
- `data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
- `group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
- `app_name` varchar(128) COLLATE utf8_bin DEFAULT NULL COMMENT 'app_name',
- `content` longtext CHARACTER SET utf8 COLLATE utf8_bin,
- `md5` varchar(32) COLLATE utf8_bin DEFAULT NULL,
- `gmt_create` datetime NOT NULL DEFAULT '2010-05-05 00:00:00',
- `gmt_modified` datetime NOT NULL DEFAULT '2010-05-05 00:00:00',
- `src_user` text COLLATE utf8_bin,
- `src_ip` varchar(20) COLLATE utf8_bin DEFAULT NULL,
- `op_type` char(10) COLLATE utf8_bin DEFAULT NULL,
- `tenant_id` varchar(128) COLLATE utf8_bin DEFAULT '' COMMENT '租户字段',
- `encrypted_data_key` varchar(255) COLLATE utf8_bin DEFAULT NULL,
- PRIMARY KEY (`nid`),
- KEY `idx_gmt_create` (`gmt_create`),
- KEY `idx_gmt_modified` (`gmt_modified`),
- KEY `idx_did` (`data_id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='多租户改造';
-
-
- -- nacos.permissions definition
-
- CREATE TABLE `permissions` (
- `role` varchar(50) NOT NULL,
- `resource` varchar(512) NOT NULL,
- `action` varchar(8) NOT NULL,
- UNIQUE KEY `uk_role_permission` (`role`,`resource`,`action`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
- -- nacos.roles definition
-
- CREATE TABLE `roles` (
- `username` varchar(50) NOT NULL,
- `role` varchar(50) NOT NULL,
- UNIQUE KEY `uk_username_role` (`username`,`role`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
- -- nacos.tenant_capacity definition
-
- CREATE TABLE `tenant_capacity` (
- `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
- `tenant_id` varchar(128) COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'Tenant ID',
- `quota` int unsigned NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值',
- `usage` int unsigned NOT NULL DEFAULT '0' COMMENT '使用量',
- `max_size` int unsigned NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
- `max_aggr_count` int unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数',
- `max_aggr_size` int unsigned NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
- `max_history_count` int unsigned NOT NULL DEFAULT '0' COMMENT '最大变更历史数量',
- `gmt_create` datetime NOT NULL DEFAULT '2010-05-05 00:00:00' COMMENT '创建时间',
- `gmt_modified` datetime NOT NULL DEFAULT '2010-05-05 00:00:00' COMMENT '修改时间',
- PRIMARY KEY (`id`),
- UNIQUE KEY `uk_tenant_id` (`tenant_id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='租户容量信息表';
-
-
- -- nacos.tenant_info definition
-
- CREATE TABLE `tenant_info` (
- `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id',
- `kp` varchar(128) COLLATE utf8_bin NOT NULL COMMENT 'kp',
- `tenant_id` varchar(128) COLLATE utf8_bin DEFAULT '' COMMENT 'tenant_id',
- `tenant_name` varchar(128) COLLATE utf8_bin DEFAULT '' COMMENT 'tenant_name',
- `tenant_desc` varchar(256) COLLATE utf8_bin DEFAULT NULL COMMENT 'tenant_desc',
- `create_source` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT 'create_source',
- `gmt_create` bigint NOT NULL COMMENT '创建时间',
- `gmt_modified` bigint NOT NULL COMMENT '修改时间',
- PRIMARY KEY (`id`),
- UNIQUE KEY `uk_tenant_info_kptenantid` (`kp`,`tenant_id`),
- KEY `idx_tenant_id` (`tenant_id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='tenant_info';
-
-
- -- nacos.users definition
-
- CREATE TABLE `users` (
- `username` varchar(50) NOT NULL,
- `password` varchar(500) NOT NULL,
- `enabled` tinyint(1) NOT NULL,
- PRIMARY KEY (`username`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
- INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE);
-
- INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');
修改nacos配置文件
进入nacos容器
docker exec -it nacos bash
cat /home/nacos/conf/application.properties
vi /home/nacos/conf/application.properties
推出容器,重启nacos容器
docker restart nacos
验证是否持久化mysql
创建用户
查看mysql数据库中是否有该用户
nacos持久化MySQL成功
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。