安装Java
官网
找个喜欢的版本
下载好了传到linux里,xshell的xftp直接拖过去就可以传
#安装rpm包管理
yum install -y rpm
or
apt-get install rpm
#查找Java
rpm -qa | grep 'java\|jdk\|gcj\|jre'
#卸载java
rpm -e --nodeps jdk-1.8-1.8.0_401-10.x86_64
#安装
rpm -ivh jdk-8u401-linux-x64.rpm
#查看是否安装成功
java -version
#查看安装位置
which java
安装Docker
Docker用不了看文章最后的解决办法
卸载旧docker
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
设置Docker存储库
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
设置镜像源vi /etc/docker/daemon.json
{
"registry-mirrors" : [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://cr.console.aliyun.com",
"https://mirror.ccs.tencentyun.com"
]
}
重启dockersystenctl restart docker
查看是否加载成功docker info
安装密钥https://mirrors.163.com/centos/
复制对应系统的密钥网址替换以下链接
rpm --import http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
安装 Docker Engine
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
启动Docker
sudo systemctl start docker
#检查服务是否开机启动
systemctl is-enabled docker
#开机启动
systemctl enable docker
#禁止开机启动
systemctl disable docker
#停止
systemctl stop docker
#重启
systemctl restart docker
#查看本地镜像
docker images
Docker自定义网络
创建一个Docker自定义网络,后面用来服务间通信
#创建自定义网络,让其他容器可以访问,link命令已被弃用
docker network create my-network
#查看哪些服务连接了my-network
docker network inspect my-network --format '{{range $container := .Containers}}{{$container.Name}} - {{$container.IPv4Address}}{{println}}{{end}}'
#更新容器启动配置,如添加自启动
docker update --restart=always ID
#取消grafana和prometheus的网络连接配置
docker unlink grafana prometheus
#添加网络配置
docker network connect my-network grafana
#取消prometheus连接my-network的网络配置
docker network disconnect my-network prometheus
#添加别名
docker network connect --alias rmqnamesrv <network_name> <container_name>
#取消别名
docker network disconnect --alias <network_name> <container_name>
1Panel安装(管理面板,服务器可以选装,需要先装Docker)
curl -sSL https://resource.fit2cloud.com/1panel/package/quick_start.sh -o quick_start.sh && sh quick_start.sh
Docker部署Mysql:5.7
装一个vim
yum install vim
or
apt-get install vim
#debian要装sudo
apt-get install sudo
mysql配置文件
#新建目录
sudo mkdir -p /opt/soft/mysql/conf /opt/soft/mysql/log /opt/soft/mysql/data
#授权
chmod 777 /opt/soft/mysql/log /opt/soft/mysql/data /opt/soft/mysql/conf
chmod 444 /etc/localtime
# 宿主机应该没有东西
ls /opt/soft/mysql/conf
#新建自定义配置文件
vim /opt/soft/mysql/conf/my.cnf
添加以下配置
[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
log-bin=mysql-bin # 开启 binlog,用于记录数据库的所有更改操作
binlog-format=ROW # 选择 ROW 模式,将每个被修改的行的内容作为一个事件记录
server-id=1 # 设置唯一id,或者设置一个唯一的服务器标识号
#mysql报错too many connections解决方法
max_connections=400
interactive_timeout=500
wait_timeout=300
group_concat_max_len=102400
[client]
MySQL客户端应用模块,只有MySQL附带的客户端应用程序保证可以读取此模块下的内容。
[mysqld]
MySQL服务端应用模块
[mysqld_safe]
指定mysqld_safe进程的配置.
父进程:mysqld_safe——管理mysqld,保证mysqld正常运行,
子进程:mysqld——工作进程, 真正对外提供服务;
mysqld_safe被杀死后,mysqld依然存在, mysqld被杀死后,mysqld_safe会重启一个mysqld
[mysql]
对 mysql命令 执行的配置
搜索并拉取镜像
docker search mysql:5.7
docker pull mysql:5.7
启动
#创建容器
docker run -p 3306:3306 --name mysql \
--privileged=true \
--restart=always \
--network my-network \
-v /opt/soft/mysql/log:/var/log/mysql \
-v /opt/soft/mysql/data:/var/lib/mysql \
-v /opt/soft/mysql/conf:/etc/mysql/conf.d \
-v /etc/localtime:/etc/localtime:ro \
-e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
# -p 3306:3306:端口映射,格式为主机(宿主)端口:容器端口
# --name mysql:创建的容器名称
# --restart=always:总是跟随docker启动(报错自动重启)
# --privileged=true:获取宿主机root权限
# -e MYSQL_ROOT_PASSWORD=123456:指定mysql环境变量,root用户的密码为123456
# -d mysql:latest:开启Daemon守护进程后台运行mysql容器,版本是5.7(8.0)
# 注意将docker容器中的数据库数据备份到服务器主机中,避免重启docker数据丢失(容器数据会实时备份到主机目录中,可以防止容器重启数据丢失
#1.重启mysql容器不会对主机存储的数据文件产生影响;
#2.重新执行下面的创建mysql容器的命令也不会对主机数据产生影响,相反主机存储的上一个mysql容器的数据文件会拷贝到新容器中的mysql中,以此实现数据的持久化):
# -v /opt/soft/mysql/log:/var/log/mysql:映射日志目录,宿主机:容器
# -v /opt/soft/mysql/data:/var/lib/mysql:映射数据目录,宿主机:容器
# -v /opt/soft/mysql/conf:/etc/mysql:映射配置目录,宿主机:容器
# -v /etc/localtime:/etc/localtime:ro :让容器的时钟与宿主机时钟同步,避免时区的问题,ro是read only的意思,就是只读
#查看日志
docker logs -f mysql
进入到 MySQL 的命令行模式来给 root 账号授权所有 ip 能够访问
#进入mysql容器
docker exec -it mysql /bin/bash
#登录mysql
mysql -uroot -p123456 --default-character-set=utf8
#授权root用户所有 IP 都能够访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
# 刷新生效
FLUSH PRIVILEGES;
# 查看 binlog 日志是否开启
show variables like 'log_%';
# 查看主结点当前状态
show master status;
#退出mysql
exit;
#退出容器
exit
binlog 日志是否开启
# 重启mysql
docker restart mysql
navicat中连接mysql
报错Access denied for user ‘root’@‘ip’ (using password: YES)
编辑配置文件跳过登录验证
vim /opt/soft/mysql/conf/my.cnf
在[mysqld]下面添加
skip-grant-tables#登录时跳过权限检查
#重启mysql
docker restart mysql
#进入mysql容器
docker exec -it mysql /bin/bash
#进入mysql,直接回车(Enter)
mysql –uroot –p
#更新密码
use mysql
# 刷新生效
FLUSH PRIVILEGES;
set password for 'root'@'localhost'=password('123456');
# 刷新生效
FLUSH PRIVILEGES;
#授权所有ip远程访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
#授权ip远程访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'170.17.0.8' IDENTIFIED BY '123456' WITH GRANT OPTION;
#授权本地
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
##删除某些授权
REVOKE ALL PRIVILEGES ON *.* FROM 'root'@'localhost';
# 刷新生效
FLUSH PRIVILEGES;
#删除授权
DELETE FROM mysql.user WHERE host='ip';
#查看授权了哪些
SELECT user, host FROM mysql.user WHERE user = 'root';
# 刷新生效
FLUSH PRIVILEGES;
#退出mysql
exit;
#退出容器
exit
#弄好了把配置文件里跳过鉴权删掉
vi /opt/soft/mysql/conf/my.cnf
#重启mysql
docker restart mysql
刷新这么多次不是是废话,有时候不刷新执行第二条会报错
Docker部署Redis
#下载最新版Redis镜像
docker pull redis
# 创建目录
mkdir -p /opt/soft/redis/conf /opt/soft/redis/data
# 创建文件
touch /opt/soft/redis/conf/redis.conf
#修改配置文件
vim /opt/soft/redis/conf/redis.conf
#添加以下内容
protected-mode no
bind 0.0.0.0
#protected-mode no #此时外部网络可以直接访问
#bind 0.0.0.0 #设置所有IP都可以访问
#查看文件内容
cat /opt/soft/redis/conf/redis.conf
#创建容器并启动
docker run \
--restart=always \
--network my-network \
--log-opt max-size=100m \
--log-opt max-file=2 \
-p 6379:6379 \
--name redis \
-v /opt/soft/redis/conf/redis.conf:/etc/redis/redis.conf \
-v /opt/soft/redis/data:/data \
-d redis redis-server /etc/redis/redis.conf \
--appendonly yes \
--requirepass 123456
#重启redis
docker restart redis
配置解释
# --name: 容器命名
#--restart=always 开机启动
#--log-opt max-size=100m 容器日志大小上限是100M
#--log-opt max-file=2 一个容器有2个日志,id+.json、id+1.json;
#-p 6379:6379 宿主机6379端口与容器内6379端口进行映射
#-v 宿主机的目录和容器映射
#--appendonly yes 开启redis 持久化
#–requirepass 123456 设置密码为123456
#redis-server /etc/redis/redis.conf 以配置文件启动redis
Redis Desktop Manager连接redis
下载地址
RocketMQ安装
安装前提
Windows/Linux64位系统
JDK1.8(64位)
源码安装需要安装Maven
1、Docker部署RocketMQ(要按顺序启动否则链接不到报错)
安装NameServer
#查找镜像
docker search rocketmq
# 我安装v4.5.1
#拉取镜像
docker pull foxiswho/rocketmq:server-4.5.1
# 创建目录
mkdir -p /opt/soft/rocketmq/namesrv/logs
# 修改权限,便于docker容器写入文件
chmod 777 /opt/soft/rocketmq/namesrv/logs
#创建容器并启动
docker run -d --name rmqnamesrv \
--restart=always \
--network my-network \
-p 9876:9876 \
-v /opt/soft/rocketmq/namesrv/logs:/home/rocketmq/logs \
-e "MAX_POSSIBLE_HEAP=100000000" \
foxiswho/rocketmq:server-4.5.1
参数解释
#-d 参数表示以后台(detached)模式运行容器。
#-p 9876:9876 参数将主机的端口 9876 映射到容器的端口 9876,这样可以通过主机的端口 9876 访问容器中运行的 RocketMQ NameServer
#--name rmqnamesrv 参数指定容器的名称为 "rmqnamesrv"。这样可以在后续的操作中使用该名称来引用容器
#--network my-network 连接到自定义网络
#-e 设置环境,rocket使用java编写,MAX_POSSIBLE_HEAP将堆内存设置为100M
#foxiswho/rocketmq:server-4.5.1 是指定要使用的 Docker 镜像
安装 Brocker
新建broker配置目录和配置文件broker.conf
mkdir -p /opt/soft/rocketmq/conf
touch /opt/soft/rocketmq/conf/broker.conf
编辑配置文件
vim /opt/soft/rocketmq/conf/broker.conf
brokerClusterName = DefaultCluster # 所属集群名称
brokerName = broker-a #Broker名称,Master和Slave使用相同的名称
brokerId = 0 #0表示Master,大于0表示不同的Slave
deleteWhen = 04 # 删除消息的时机,默认是4点
fileReservedTime = 48 #消息持久化在磁盘上的时长(小时)
brokerRole = ASYNC_MASTER #Master和Slave之间同步数据的机制:SYNC_MASTER、ASYNC_MASTER、SLAVE
flushDiskType = ASYNC_FLUSH #刷盘策略:SYNC_FLUSH 消息写入磁盘后才返回成功状态;ASYNC_FLUSH 不需要等返回成功
brokerIP1 = xx.xx.xx.xx # Broker节点所在服务器的IP地址,此处为本地虚拟机ip
# namesrvAddr = XXX.XXX.XXX.XXX:9876 # NameServer地址,用分号分割,我们通过Docker的环境变量指定
# Broker 对外服务的监听端口,默认即可
# listenPort = 10911
# 是否允许 Broker 自动创建 Topic
# autoCreateTopicEnable = true
# 是否允许 Broker 自动创建 订阅组
# autoCreateSubscriptionGroup = true
# 开启鉴权
# aclEnable = true
:wq
保存退出
创建并启动Broker容器
docker run -d \
-p 10911:10911 \
-p 10909:10909 \
--name rmqbroker \
--network my-network \
--restart=always \
-v /opt/soft/rocketmq/conf/broker.conf:/etc/rocketmq/broker.conf \
-e "NAMESRV_ADDR=rmqnamesrv:9876" \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms512m -Xmx512m" \
foxiswho/rocketmq:broker-4.5.1
安装 rocketmq控制台(默认端口为8080 我这里指定端口为8088)
#拉取镜像
docker pull pangliang/rocketmq-console-ng
#启动
docker run -d \
--name rmqconsole \
--network my-network \
--restart=always \
-p 8088:8080 \
-e "JAVA_OPTS=-Drocketmq.config.namesrvAddr=rmqnamesrv:9876 -Drocketmq.config.isVIPChannel=false" \
-t pangliang/rocketmq-console-ng
访问ip:8088即可看到控制台,看不到就看有没有启动成功,服务器看不到查看端口有没有开放
查看远程服务器端口有没有开放
telnet ip 端口
(本人买的的服务器pdd 9.9/月,最初没有安全组管理,开找客服一开始不承认没开放端口,后来让客服手动开放的一大堆端口,今天看了一下发现多了安全组,可以说是见证了一个云服务商的成长)
报错
如果是本教程,大概率是cat /opt/soft/rocketmq/conf/broker.conf
配置错了,粘贴的时候没粘全,看上面的Broker配置文件,我们通过服务名指定就不用固定ip
如果是按其他教程,broker.conf里要配置ip
brokerClusterName = DefaultCluster # 所属集群名称
brokerIP1 = xx.xx.xx.xx # Broker节点所在服务器的IP地址,此处为本地虚拟机ip
namesrvAddr = XXX.XXX.XXX.XXX:9876 # NameServer地址,用分号分割
查看rocketmq 在docker中启动情况
docker ps|grep rocketmq
或者
#查看Docker中运行中的容器
docker ps
或者
#查看所有容器的运行状态
docker ps -a
#docker查看服务间能不能ping通
docker exec -it rmqconsole ping rmqnamesrv
停掉容器
docker stop ID -t=10
# -t如果超时未能关闭则用kill强制关闭,这个时间用于容器的自己保存状态
OR
docker kill ID
#一次停多个
docker rm rmqconsole rmqbroker rmqnamesrv
重启容器
docker restart ID
docker start ID
删除容器(先停再删)
docker rm ID
#删除镜像
docker rmi ID
#一次删多个
docker rm rmqconsole rmqbroker rmqnamesrv
2、Windows安装RocketMQ(不建议,还是Linux里操作方便)
官网
解压到你喜欢的地方
添加系统环境变量
ROCKETMQ_HOME
bin目录打开CMD
启动NameServer
执行start mqnamesrv.cmd
启动Broker
执行start mqbroker.cmd -n 127.0.0.1:9876 autoCreateTopicEnable = true
出现信息框即启动成功,×框就停掉了
Docker安装部署Naocos2.0
#拉取镜像
docker pull nacos/nacos-server:latest
#新建logs/conf目录
mkdir -p /opt/soft/nacos/logs/ /opt/soft/nacos/conf/
#授权
chmod 777 /opt/soft/nacos/logs
chmod 777 /opt/soft/nacos/conf
先在mysql创建数据库nacos_config
新建查询执行以下sql建表命令
/******************************************/
/* 数据库全名 = 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,
`encrypted_data_key` text NOT NULL COMMENT '秘钥',
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 '租户字段',
`encrypted_data_key` text NOT NULL 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(20) 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 '租户字段',
`encrypted_data_key` text NOT NULL 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');
#新建配置文件
vim /opt/soft/nacos/conf/custom.properties
custom.properties内容,把数据库改成自己虚拟机或者服务器ip,这里xxx.xxx.xxx改成mysql就行
# Copyright 1999-2021 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.
#
#*************** Spring Boot Related Configurations ***************#
### Default web context path:
server.servlet.contextPath=/nacos
### Include message field
server.error.include-message=ON_PARAM
### Default web server port:
server.port=8848
#*************** Network Related Configurations ***************#
### If prefer hostname over ip for Nacos server addresses in cluster.conf:
# nacos.inetutils.prefer-hostname-over-ip=false
### Specify local server's IP:
# nacos.inetutils.ip-address=
#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://xxx.xxx.xxx:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=123456
### Connection pool configuration: hikariCP
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2
#*************** Naming Module Related Configurations ***************#
### Data dispatch task execution period in milliseconds: Will removed on v2.1.X, replace with nacos.core.protocol.distro.data.sync.delayMs
# nacos.naming.distro.taskDispatchPeriod=200
### Data count of batch sync task: Will removed on v2.1.X. Deprecated
# nacos.naming.distro.batchSyncKeyCount=1000
### Retry delay in milliseconds if sync task failed: Will removed on v2.1.X, replace with nacos.core.protocol.distro.data.sync.retryDelayMs
# nacos.naming.distro.syncRetryDelay=5000
### If enable data warmup. If set to false, the server would accept request without local data preparation:
# nacos.naming.data.warmup=true
### If enable the instance auto expiration, kind like of health check of instance:
# nacos.naming.expireInstance=true
### will be removed and replaced by `nacos.naming.clean` properties
nacos.naming.empty-service.auto-clean=true
nacos.naming.empty-service.clean.initial-delay-ms=50000
nacos.naming.empty-service.clean.period-time-ms=30000
### Add in 2.0.0
### The interval to clean empty service, unit: milliseconds.
# nacos.naming.clean.empty-service.interval=60000
### The expired time to clean empty service, unit: milliseconds.
# nacos.naming.clean.empty-service.expired-time=60000
### The interval to clean expired metadata, unit: milliseconds.
# nacos.naming.clean.expired-metadata.interval=5000
### The expired time to clean metadata, unit: milliseconds.
# nacos.naming.clean.expired-metadata.expired-time=60000
### The delay time before push task to execute from service changed, unit: milliseconds.
# nacos.naming.push.pushTaskDelay=500
### The timeout for push task execute, unit: milliseconds.
# nacos.naming.push.pushTaskTimeout=5000
### The delay time for retrying failed push task, unit: milliseconds.
# nacos.naming.push.pushTaskRetryDelay=1000
### Since 2.0.3
### The expired time for inactive client, unit: milliseconds.
# nacos.naming.client.expired.time=180000
#*************** CMDB Module Related Configurations ***************#
### The interval to dump external CMDB in seconds:
# nacos.cmdb.dumpTaskInterval=3600
### The interval of polling data change event in seconds:
# nacos.cmdb.eventTaskInterval=10
### The interval of loading labels in seconds:
# nacos.cmdb.labelTaskInterval=300
### If turn on data loading task:
# nacos.cmdb.loadDataAtStart=false
#*************** Metrics Related Configurations ***************#
### Metrics for prometheus
#management.endpoints.web.exposure.include=*
### Metrics for elastic search
management.metrics.export.elastic.enabled=false
#management.metrics.export.elastic.host=http://localhost:9200
### Metrics for influx
management.metrics.export.influx.enabled=false
#management.metrics.export.influx.db=springboot
#management.metrics.export.influx.uri=http://localhost:8086
#management.metrics.export.influx.auto-create-db=true
#management.metrics.export.influx.consistency=one
#management.metrics.export.influx.compressed=true
#*************** Access Log Related Configurations ***************#
### If turn on the access log:
server.tomcat.accesslog.enabled=true
### The access log pattern:
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i
### The directory of access log:
server.tomcat.basedir=file:.
#*************** Access Control Related Configurations ***************#
### If enable spring security, this option is deprecated in 1.2.0:
#spring.security.enabled=false
### The ignore urls of auth, is deprecated in 1.2.0:
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
### The auth system to use, currently only 'nacos' and 'ldap' is supported:
nacos.core.auth.system.type=nacos
### If turn on auth system:
nacos.core.auth.enabled=false
### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=true
### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version.
nacos.core.auth.enable.userAgentAuthWhite=false
### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=serverIdentity
nacos.core.auth.server.identity.value=security
### worked when nacos.core.auth.system.type=nacos
### The token expiration in seconds:
nacos.core.auth.plugin.nacos.token.expire.seconds=18000
### The default token:
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
### worked when nacos.core.auth.system.type=ldap,{0} is Placeholder,replace login username
#nacos.core.auth.ldap.url=ldap://localhost:389
#nacos.core.auth.ldap.basedc=dc=example,dc=org
#nacos.core.auth.ldap.userDn=cn=admin,${nacos.core.auth.ldap.basedc}
#nacos.core.auth.ldap.password=admin
#nacos.core.auth.ldap.userdn=cn={0},dc=example,dc=org
#*************** Istio Related Configurations ***************#
### If turn on the MCP server:
nacos.istio.mcp.server.enabled=false
#*************** Core Related Configurations ***************#
### set the WorkerID manually
# nacos.core.snowflake.worker-id=
### Member-MetaData
# nacos.core.member.meta.site=
# nacos.core.member.meta.adweight=
# nacos.core.member.meta.weight=
### MemberLookup
### Addressing pattern category, If set, the priority is highest
# nacos.core.member.lookup.type=[file,address-server]
## Set the cluster list with a configuration file or command-line argument
# nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809
## for AddressServerMemberLookup
# Maximum number of retries to query the address server upon initialization
# nacos.core.address-server.retry=5
## Server domain name address of [address-server] mode
# address.server.domain=jmenv.tbsite.net
## Server port of [address-server] mode
# address.server.port=8080
## Request address of [address-server] mode
# address.server.url=/nacos/serverlist
#*************** JRaft Related Configurations ***************#
### Sets the Raft cluster election timeout, default value is 5 second
# nacos.core.protocol.raft.data.election_timeout_ms=5000
### Sets the amount of time the Raft snapshot will execute periodically, default is 30 minute
# nacos.core.protocol.raft.data.snapshot_interval_secs=30
### raft internal worker threads
# nacos.core.protocol.raft.data.core_thread_num=8
### Number of threads required for raft business request processing
# nacos.core.protocol.raft.data.cli_service_thread_num=4
### raft linear read strategy. Safe linear reads are used by default, that is, the Leader tenure is confirmed by heartbeat
# nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe
### rpc request timeout, default 5 seconds
# nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000
#*************** Distro Related Configurations ***************#
### Distro data sync delay time, when sync task delayed, task will be merged for same data key. Default 1 second.
# nacos.core.protocol.distro.data.sync.delayMs=1000
### Distro data sync timeout for one sync data, default 3 seconds.
# nacos.core.protocol.distro.data.sync.timeoutMs=3000
### Distro data sync retry delay time when sync data failed or timeout, same behavior with delayMs, default 3 seconds.
# nacos.core.protocol.distro.data.sync.retryDelayMs=3000
### Distro data verify interval time, verify synced data whether expired for a interval. Default 5 seconds.
# nacos.core.protocol.distro.data.verify.intervalMs=5000
### Distro data verify timeout for one verify, default 3 seconds.
# nacos.core.protocol.distro.data.verify.timeoutMs=3000
### Distro data load retry delay when load snapshot data failed, default 30 seconds.
# nacos.core.protocol.distro.data.load.retryDelayMs=30000
创建容器
docker run -d \
--name nacos \
-p 8848:8848 \
-p 9848:9848 \
-p 9849:9849 \
--privileged=true \
--restart=always \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e MODE=standalone \
-e PREFER_HOST_MODE=hostname \
-v /opt/soft/nacos/logs:/home/nacos/logs \
-v /opt/soft/nacos/conf/custom.properties:/home/nacos/conf/custom.properties \
nacos/nacos-server
访问http://ip:8848/nacos/index.html
用户名/密码:nacos/nacos
Docker安装部署Seata:1.5.2
Seata 是一款开源的分布式事务解决方案,致力于提供高性能和简单易用的分布式事务服务。Seata 将为用户提供了 AT、TCC、SAGA 和XA 事务模式
docker run -d \
--name seata-server \
-p 8091:8091 \
-p 7091:7091 \
seataio/seata-server:1.5.2
访问ip:8091
用户名密码:seata/seata
Docker安装部署Sentinel:1.8.4
Sentinel是面向分布式服务架构的轻量级流量控制产品,主要以流量为切入点,从流量控制、熔断降级、系统负载保护等多个维度来帮助您保护服务的稳定性
#查找镜像
docker search sentinel-dashboard
#拉取镜像
docker pull bladex/sentinel-dashboard:1.8.4
# 运行容器 Sentinel默认端口 8858
docker run --name sentinel --restart=always -p 8858:8858 -td bladex/sentinel-dashboard:1.8.4
#-t分配一个伪终端(TTY)
#-d使容器在后台运行
访问ip:8858
用户/密码:sentinel/sentinel
监控不到可能是时间没同步
#查看当前时间
date -R
修改时间区
tzselect
Docker安装部署MinIO
#查找镜像
docker search minio
#拉取镜像
docker pull minio/minio
#新建目录
mkdir -p /opt/soft/minio/data /opt/soft/minio/config
#授权
chmod 777 /opt/soft/minio/data
chmod 777 /opt/soft/minio/config
#创建容器并运行
docker run -d \
-p 9000:9000 \
-p 9001:9001 \
--name minio \
--restart=always \
--network my-network \
-v /opt/soft/minio/data:/data \
-v /opt/soft/minio/config:/root/.minio \
-e "MINIO_ROOT_USER=minioadmin" \
-e "MINIO_ROOT_PASSWORD=minioadmin" \
minio/minio server \
/data --console-address ":9001" -address ":9000"
访问ip:9001
用户名/密码:minioadmin/minioadmin
创建用户
分配策略
添加组
Docker部署node_exporter
向Prometheus提供监控样本数据的程序都可以被称为一个Exporter
node_exporter 用于采集类UNIX内核的硬件以及系统指标,包括CPU、内存和磁盘
#查找镜像
docker search prom/node-exporter
#拉取镜像
docker pull prom/node-exporter
#创建容器并启动
docker run -d \
--name=node-exporter \
--restart=always \
--network my-network \
-p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
prom/node-exporter
配置解释
#/proc目录包含有关系统进程的信息
#/sys包含有关系统硬件和内核的信息
#/获取主机的整个文件系统信息
#ro只读模式挂载
访问:ip:9100
访问:ip:9100/metrics可以看到收集的信息
Docker部署Prometheus
#查找镜像
docker search prom/prometheus
#拉取镜像
docker pull prom/prometheus
#新建目录
mkdir -p /opt/soft/prometheus/conf
#授权
chmod 777 /opt/soft/prometheus/conf
#编辑配置prometheus.yml
touch /opt/soft/prometheus/conf/prometheus.yml
vim /opt/soft/prometheus/conf/prometheus.yml
#配置文件内容
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node-exporter'
scrape_interval: 5s
static_configs:
- targets: ['node-exporter:9100']
metrics_path: '/metrics'
启动
#创建容器并启动
docker run -itd \
--name prometheus \
--restart=always \
--network my-network \
-p 9090:9090 \
-v /opt/soft/prometheus/conf/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
修改为自己虚拟机或者服务器ip,这里使用了自定义网络,所以直接用服务名+端口,就不用担心ip变了。有的用的link,从Docker 1.13版本开始,不再建议使用--link
选项来连接容器
可以通过docker network connect my-network 容器名
添加网络,默认采用桥接模式,详见官网
访问ip:9090
重启docker restart prometheus
两个绿的就是成功了
Docker部署Grafana
#查找镜像
docker search grafana/grafana
#拉取镜像
docker pull grafana/grafana
#新建目录
mkdir -p /opt/soft/grafana/data
#授权
chmod 777 /opt/soft/grafana/data
#创建容器并启动
docker run -itd \
-p 3000:3000 \
--restart=always \
--network my-network \
--name=grafana \
-v /opt/soft/grafana/data:/var/lib/grafana \
grafana/grafana
访问:ip:3000
用户/密码:admin/admin
进去可以设置新密码
添加 Prometheus 数据源,拉到最下面保存
找一个模板https://grafana.com/grafana/dashboards
粘贴你找的模板id和json
改个名字导入
没有数据是因为没添加数据源,或者是时间不匹配
Docker部署cAdvisor
cAdvisor是Google 开源的一款用于展示和分析容器运行状态的可视化工具
#查找镜像
docker search cadvisor
#拉取镜像
docker pull chainguard/cadvisor
授权
chmod 666 /var/run
#创建容器并启动
docker run -d \
--name=cadvisor \
--restart=always \
--network my-network \
-p 8090:8080 \
-v /:/rootfs:ro \
-v /var/run:/var/run:rw \
-v /sys:/sys:ro \
-v /var/lib/docker/:/var/lib/docker:ro \
-v /dev/disk/:/dev/disk:ro \
chainguard/cadvisor:latest
cadvisor默认占用8080,改成8090或者其他
Linux查看端口占用netstat -tunlp | grep 8080
访问ip:8090
修改prometheus配置文件vim /opt/soft/prometheus/conf/prometheus.yml
在scrape_configs下面添加
- job_name: 'cadvisor'
scrape_interval: 5s
static_configs:
- targets: ['cadvisor:8080']
如果你用ip的方式,端口要改为映射的端口也就是8090,如果用容器名访问,在内部用8080
重启docker restart prometheus
这玩意绿了就是可以了
Docker部署mysqld-exporter
mysqld_exporter是数据库监控工具,exporter是负责收集数据并将信息汇报给Prometheus Server的组件
#查找镜像
docker search google/cadvisor
#拉取镜像
docker pull prom/mysqld-exporter
#创建容器并启动
docker run -d \
--name mysqld-exporter \
-p 9104:9104 \
--network my-network \
--restart=always \
-v /opt/soft/mysql/conf/mysqld-exporter.cnf:/etc/mysql/mysqld-exporter.cnf \
prom/mysqld-exporter --config.my-cnf=/etc/mysql/mysqld-exporter.cnf
创建一个mysqld-exporter的配置文件,host本教程可以就用mysql,其他用宿主机ip
vim /opt/soft/mysql/conf/mysqld-exporter.cnf
[client]
default-character-set=utf8mb4
host=mysql
port=3306
user=root
password=123456
mysql账户密码改成自己的,mysqlt可以改成ip,本教程可以改成容器名,避免ip变动
修改prometheus配置文件vim /opt/soft/prometheus/conf/prometheus.yml
在scrape_configs下面添加
- job_name: 'mysqld-exporter'
scrape_interval: 5s
static_configs:
- targets: ['mysqld-exporter:9104']
metrics_path: '/metrics'
重启docker restart prometheus
访问ip:9104/metrics
出来一堆就是成功了
prometheus上也能看到
找一个mysql的dashboard https://grafana.com/grafana/dashboards
找一个数据库的,像上面node-exporter一样导入就行了
没有数据看日志docker logs -f mysqld-exporter
mysqld-exporter报错Error pinging mysqld err=“Error 1045;Access denied for user ‘root’@‘ip’ (using password: YES)”,教程上面有解决办法,ctrl+f搜索本页就有
Docker部署Canal(需要有mysql且开启binlog日志)
Canal是阿里开源的框架,可以很方便地同步数据库的增量数据到其他的存储应用
开启binlog
#编辑mysql配置文件
vi /opt/soft/mysql/conf/my.cnf
#在[mysqld]下添加
[mysqld]
log-bin=mysql-bin # 开启 binlog,用于记录数据库的所有更改操作
binlog-format=ROW # 选择 ROW 模式,将每个被修改的行的内容作为一个事件记录
server-id=1 # 设置唯一id,或者设置一个唯一的服务器标识号
创建canal用户
#进入mysql容器,不是容器部署的mysql直接下一条命令
docker exec -it mysql /bin/bash
#登录mysql
mysql -uroot -p
# 创建用户名密码都是 canal 的账号
CREATE USER canal IDENTIFIED BY 'canal';
# 刷新生效
FLUSH PRIVILEGES;
#对canal 授权读取
grant SELECT, REPLICATION SLAVE, REPLICATION CLIENT on *.* to 'canal'@'%';
# 刷新生效
FLUSH PRIVILEGES;
#授权远程canal用户所有ip可以访问
# 刷新生效
FLUSH PRIVILEGES;
#退出mysql
exit;
#退出容器
exit
部署Canal
#拉取镜像
docker pull canal/canal-server
#新建目录
mkdir -p /opt/soft/canal/conf
#复制配置instance.properties,先启动sample-canal,再把配置文件复制到宿主机
docker run -p 11111:11111 --name sample-canal -d canal/canal-server
docker cp sample-canal:/home/admin/canal-server/conf/example/instance.properties /opt/soft/canal/conf
#检查有没有instance.properties
ls /opt/soft/canal/conf
#修改配置instance.properties
vi /opt/soft/canal/conf/instance.properties
#修改数据库ip,本教程使用容器名
canal.instance.master.address=mysql:3306
#修改用户/密码
canal.instance.dbUsername=canal
canal.instance.dbPassword=canal
#删除sample-canal容器
docker stop sample-canal
docker rm sample-canal
#创建并启动canal
docker run -d \
--name canal \
--network my-network \
-p 11111:11111 \
-v /opt/soft/canal/conf/instance.properties:/home/admin/canal-server/conf/example/instance.properties \
canal/canal-server
改这两部分
查看日志docker logs -f canal
,START SUCCESSFUL就是启动成功了
Docker部署elasticsearch
elasticsearch是一个开源的分布式搜索引擎,可以用来实现搜索、日志统计、分析、系统监控等功能
elastic stack(ELK)是以elasticsearch为核心的技术栈,包括beats、Logstash、kibana、elasticsearch
#查找镜像
docker search elasticsearch
#拉取镜像
docker pull elasticsearch:7.12.1
#新建挂载文件夹
mkdir -p /opt/soft/elasticsearch/data /opt/soft/elasticsearch/config /opt/soft/elasticsearch/plugins
vim /opt/soft/elasticsearch/config/elasticsearch.yml
#配置内容
http.host: 0.0.0.0# 配置host为0.0.0.0 允许远程访问
http.cors.enabled: true# 跨域配置
http.cors.allow-origin: "*"
xpack.security.enabled: true# 开启密码访问
#授权
chmod 777 /opt/soft/elasticsearch/data /opt/soft/elasticsearch/config /opt/soft/elasticsearch/plugins
#创建并启动elasticsearch
docker run -d \
--restart=always \
--name elasticsearch \
-p 9200:9200 \
-p 9300:9300 \
--network my-network \
--privileged=true \
-v /opt/soft/elasticsearch/data:/usr/share/elasticsearch/data \
-v /opt/soft/elasticsearch/config:/usr/local/es/config \
-v /opt/soft/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-e TZ=Asia/Shanghai \
-e "discovery.type=single-node" \
-e "ES_JAVA_OPTS=-Xms84m -Xmx512m" \
elasticsearch:7.12.1
访问ip:9200
安装ik插件
#进入容器
docker exec -it elasticsearch /bin/bash
cd /usr/share/elasticsearch/plugins
#安装插件
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip
#推出容器
exit
#重启
docker restart elasticsearch
Docker部署Kibana(版本和es对应)
#查找镜像
docker search kibana
#拉取镜像
docker pull kibana:7.12.1
#创建容器并启动
docker run -d \
--name kibana \
--restart=always \
--network my-network \
-p 5601:5601 \
-e ELASTICSEARCH_HOSTS=http://elasticsearch:9200 \
kibana:7.12.1
访问ip:5601/app/home#/
在kibana Dev tools搜索以下内容
GET _analyze
{
"analyzer": "ik_smart",
"text": "我是ik分词器,这篇教程能不能给个赞"
}
出来一json信息就是ik插件装成功了
Docker部署SkyWalking
SkyWalking是一个开源的分布式系统跟踪和性能监测工具
#查找镜像
docker search skywalking
#拉取镜像
docker pull apache/skywalking-oap-server:9.3.0
docker pull apache/skywalking-ui:9.3.0
#创建并启动skywalking-oap
docker run -d \
--name skywalking-oap \
--privileged=true \
-p 12800:12800 \
-p 11800:11800 \
--restart=always \
--network my-network \
-e TZ=Asia/Shanghai \
-v /etc/localtime:/etc/localtime:ro \
apache/skywalking-oap-server:9.3.0
#创建并启动skywalking-ui
docker run -d \
--privileged=true \
--name skywalking-ui \
--restart=always \
--network my-network \
-p 18080:8080 \
-e TZ=Asia/Shanghai \
-e SW_OAP_ADDRESS=http://skywalking-oap:12800 \
-v /etc/localtime:/etc/localtime:ro \
apache/skywalking-ui:9.3.0
下载agent官网
Docker部署XXL-Job
XXL-Job是大众点评于2015年开源的一款分布式任务调度平台
navicat新建查询创建数据库
CREATE database if NOT EXISTS `xxl_job` default character set utf8mb4 collate utf8mb4_unicode_ci;
use `xxl_job`;
初始化数据库,执行以下sql
SET NAMES utf8mb4;
CREATE TABLE `xxl_job_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`job_group` int(11) NOT NULL COMMENT '执行器主键ID',
`job_desc` varchar(255) NOT NULL,
`add_time` datetime DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
`author` varchar(64) DEFAULT NULL COMMENT '作者',
`alarm_email` varchar(255) DEFAULT NULL COMMENT '报警邮件',
`schedule_type` varchar(50) NOT NULL DEFAULT 'NONE' COMMENT '调度类型',
`schedule_conf` varchar(128) DEFAULT NULL COMMENT '调度配置,值含义取决于调度类型',
`misfire_strategy` varchar(50) NOT NULL DEFAULT 'DO_NOTHING' COMMENT '调度过期策略',
`executor_route_strategy` varchar(50) DEFAULT NULL COMMENT '执行器路由策略',
`executor_handler` varchar(255) DEFAULT NULL COMMENT '执行器任务handler',
`executor_param` varchar(512) DEFAULT NULL COMMENT '执行器任务参数',
`executor_block_strategy` varchar(50) DEFAULT NULL COMMENT '阻塞处理策略',
`executor_timeout` int(11) NOT NULL DEFAULT '0' COMMENT '任务执行超时时间,单位秒',
`executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT '失败重试次数',
`glue_type` varchar(50) NOT NULL COMMENT 'GLUE类型',
`glue_source` mediumtext COMMENT 'GLUE源代码',
`glue_remark` varchar(128) DEFAULT NULL COMMENT 'GLUE备注',
`glue_updatetime` datetime DEFAULT NULL COMMENT 'GLUE更新时间',
`child_jobid` varchar(255) DEFAULT NULL COMMENT '子任务ID,多个逗号分隔',
`trigger_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '调度状态:0-停止,1-运行',
`trigger_last_time` bigint(13) NOT NULL DEFAULT '0' COMMENT '上次调度时间',
`trigger_next_time` bigint(13) NOT NULL DEFAULT '0' COMMENT '下次调度时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`job_group` int(11) NOT NULL COMMENT '执行器主键ID',
`job_id` int(11) NOT NULL COMMENT '任务,主键ID',
`executor_address` varchar(255) DEFAULT NULL COMMENT '执行器地址,本次执行的地址',
`executor_handler` varchar(255) DEFAULT NULL COMMENT '执行器任务handler',
`executor_param` varchar(512) DEFAULT NULL COMMENT '执行器任务参数',
`executor_sharding_param` varchar(20) DEFAULT NULL COMMENT '执行器任务分片参数,格式如 1/2',
`executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT '失败重试次数',
`trigger_time` datetime DEFAULT NULL COMMENT '调度-时间',
`trigger_code` int(11) NOT NULL COMMENT '调度-结果',
`trigger_msg` text COMMENT '调度-日志',
`handle_time` datetime DEFAULT NULL COMMENT '执行-时间',
`handle_code` int(11) NOT NULL COMMENT '执行-状态',
`handle_msg` text COMMENT '执行-日志',
`alarm_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '告警状态:0-默认、1-无需告警、2-告警成功、3-告警失败',
PRIMARY KEY (`id`),
KEY `I_trigger_time` (`trigger_time`),
KEY `I_handle_code` (`handle_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_log_report` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`trigger_day` datetime DEFAULT NULL COMMENT '调度-时间',
`running_count` int(11) NOT NULL DEFAULT '0' COMMENT '运行中-日志数量',
`suc_count` int(11) NOT NULL DEFAULT '0' COMMENT '执行成功-日志数量',
`fail_count` int(11) NOT NULL DEFAULT '0' COMMENT '执行失败-日志数量',
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `i_trigger_day` (`trigger_day`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_logglue` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`job_id` int(11) NOT NULL COMMENT '任务,主键ID',
`glue_type` varchar(50) DEFAULT NULL COMMENT 'GLUE类型',
`glue_source` mediumtext COMMENT 'GLUE源代码',
`glue_remark` varchar(128) NOT NULL COMMENT 'GLUE备注',
`add_time` datetime DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_registry` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`registry_group` varchar(50) NOT NULL,
`registry_key` varchar(255) NOT NULL,
`registry_value` varchar(255) NOT NULL,
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `i_g_k_v` (`registry_group`,`registry_key`,`registry_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_group` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`app_name` varchar(64) NOT NULL COMMENT '执行器AppName',
`title` varchar(12) NOT NULL COMMENT '执行器名称',
`address_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '执行器地址类型:0=自动注册、1=手动录入',
`address_list` text COMMENT '执行器地址列表,多地址逗号分隔',
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL COMMENT '账号',
`password` varchar(50) NOT NULL COMMENT '密码',
`role` tinyint(4) NOT NULL COMMENT '角色:0-普通用户、1-管理员',
`permission` varchar(255) DEFAULT NULL COMMENT '权限:执行器ID列表,多个逗号分割',
PRIMARY KEY (`id`),
UNIQUE KEY `i_username` (`username`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_lock` (
`lock_name` varchar(50) NOT NULL COMMENT '锁名称',
PRIMARY KEY (`lock_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `xxl_job_group`(`id`, `app_name`, `title`, `address_type`, `address_list`, `update_time`) VALUES (1, 'xxl-job-executor-sample', '示例执行器', 0, NULL, '2018-11-03 22:21:31' );
INSERT INTO `xxl_job_info`(`id`, `job_group`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `schedule_type`, `schedule_conf`, `misfire_strategy`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`) VALUES (1, 1, '测试任务1', '2018-11-03 22:21:31', '2018-11-03 22:21:31', 'XXL', '', 'CRON', '0 0 0 * * ? *', 'DO_NOTHING', 'FIRST', 'demoJobHandler', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '2018-11-03 22:21:31', '');
INSERT INTO `xxl_job_user`(`id`, `username`, `password`, `role`, `permission`) VALUES (1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 1, NULL);
INSERT INTO `xxl_job_lock` ( `lock_name`) VALUES ( 'schedule_lock');
commit;
部署
#查找镜像
docker search xxl-job
#拉取镜像
docker pull xuxueli/xxl-job-admin:2.3.1
#新建挂载文件夹并授权
mkdir -p -m 777 /opt/soft/xxl-job/logs /opt/soft/xxl-job/conf
#新建配置文件,配置文件在下面
vim /opt/soft/xxl-job/conf/application.properties
#检查有没有配置文件
cat /opt/soft/xxl-job/conf/application.properties
#创建并启动容器
docker run -d \
-p 8085:8080 \
--name=xxl-job-admin \
--network my-network \
--restart=always \
-v /opt/soft/xxl-job/conf/application.properties:/application.properties \
-e PARAMS='--spring.config.location=/application.properties' \
xuxueli/xxl-job-admin:2.3.1
配置文件,修改mysql配置
### web
server.port=8080
server.servlet.context-path=/xxl-job-admin
### actuator
management.server.servlet.context-path=/actuator
management.health.mail.enabled=false
### resources
spring.mvc.servlet.load-on-startup=0
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/
### freemarker
spring.freemarker.templateLoaderPath=classpath:/templates/
spring.freemarker.suffix=.ftl
spring.freemarker.charset=UTF-8
spring.freemarker.request-context-attribute=request
spring.freemarker.settings.number_format=0.##########
### mybatis
mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml
#mybatis.type-aliases-package=com.xxl.job.admin.core.model
### mysql改成ip,修改用户/密码,本教程不用改
### xxl-job, datasource
spring.datasource.url=jdbc:mysql://mysql:3306/xxl_job?characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false&autoReconnect=true ###ip
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
### datasource-pool
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.maximum-pool-size=30
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.pool-name=HikariCP
spring.datasource.hikari.max-lifetime=900000
spring.datasource.hikari.connection-timeout=10000
spring.datasource.hikari.connection-test-query=SELECT 1
spring.datasource.hikari.validation-timeout=1000
### xxl-job, email
spring.mail.host=smtp.qq.com
spring.mail.port=25
spring.mail.username=xxx@qq.com
spring.mail.from=xxx@qq.com
spring.mail.password=xxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
### xxl-job, access token
xxl.job.accessToken=default_token
### xxl-job, i18n (default is zh_CN, and you can choose "zh_CN", "zh_TC" and "en")
xxl.job.i18n=zh_CN
## xxl-job, triggerpool max size
xxl.job.triggerpool.fast.max=200
xxl.job.triggerpool.slow.max=100
### xxl-job, log retention days
xxl.job.logretentiondays=30
访问ip:8085/xxl-job-admin/toLogin
用户/密码:admin/123456
如果你的服务器不能访问外网,在能访问的虚拟机上pull上面的所有镜像,执行以下命令打包镜像
docker save -o minio.tar minio/minio:latest
docker save -o cadvisor.tar chainguard/cadvisor:latest
docker save -o redis.tar redis:latest
docker save -o node-exporter.tar prom/node-exporter:latest
docker save -o grafana.tar grafana/grafana:latest
docker save -o prometheus.tar prom/prometheus:latest
docker save -o nacos-server.tar nacos/nacos-server:latest
docker save -o sentinel-dashboard.tar bladex/sentinel-dashboard:1.8.4
docker save -o mysql.tar mysql:5.7
docker save -o canal-server.tar canal/canal-server:latest
docker save -o skywalking-ui.tar apache/skywalking-ui:9.3.0
docker save -o skywalking-oap-server.tar apache/skywalking-oap-server:9.3.0
docker save -o seata-server.tar seataio/seata-server:1.5.2
docker save -o xxl-job-admin.tar xuxueli/xxl-job-admin:2.3.1
docker save -o kibana.tar kibana:7.12.1
docker save -o elasticsearch.tar elasticsearch:7.12.1
docker save -o rocketmq-console-ng.tar pangliang/rocketmq-console-ng:latest
docker save -o rocketmq-broker.tar foxiswho/rocketmq:broker-4.5.1
docker save -o rocketmq-server.tar foxiswho/rocketmq:server-4.5.1
下载并上传到不能访问外网的服务器,执行以下命令加载镜像
docker load -i minio.tar
docker load -i cadvisor.tar
docker load -i redis.tar
docker load -i node-exporter.tar
docker load -i grafana.tar
docker load -i prometheus.tar
docker load -i nacos-server.tar
docker load -i sentinel-dashboard.tar
docker load -i mysql.tar
docker load -i canal-server.tar
docker load -i skywalking-ui.tar
docker load -i skywalking-oap-server.tar
docker load -i seata-server.tar
docker load -i xxl-job-admin.tar
docker load -i kibana.tar
docker load -i elasticsearch.tar
docker load -i rocketmq-console-ng.tar
docker load -i rocketmq-broker.tar
docker load -i rocketmq-server.tar
Docker离线安装教程https://juejin.cn/post/7378318507832541238