JoyLau's Blog

JoyLau 的技术学习与思考

导出主库全部数据

mysqldump -A -F --single-transaction --master-data=1 > /tmp/full.sql

-A: 导出全部数据
-F: 同参数–flush-logs, dump 前生成新的 bin log 日志
–master-data=1:参数会在 sql 中打印出 binlog 的信息

例如:
CHANGE MASTER TO MASTER_LOG_FILE='binlog.000248', MASTER_LOG_POS=156;

当指定为 2 时,改行为注释的情况,为 1 时不注释
这时就相当于改变了从主库读取 binlog 的文件和位置信息,
之后将导出的数据导入从库

mysql -p < /tmp/full.sql

耐心的等待

完成后查看从节点的信息:

show slave status;

主要看 Master_Log_File 和 Read_Master_Log_Pos 的数据是否和上面的一致

此时再开启主从同步

start slave ;

完成;

查看信息

使用 choose 标签

1
2
3
4
5
6
7
8
<choose>
<when test="isReSend">
and (info.batchId is not null)
</when>
<otherwise>
and (info.batchId = '' or info.batchId is null)
</otherwise>
</choose>

或者

1
2
3
4
5
6
7
8
<choose>
<when test="isReSend==true">
and (info.batchId is not null)
</when>
<otherwise>
and (info.batchId = '' or info.batchId is null)
</otherwise>
</choose>

按照晚上的教程,配置了
JAVA_TOOL_OPTIONS=”-Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8”
和 LANG=C.UTF-8

这些都没有解决问题

问题解决

主要问题是主节点配置连接从节点的账号 jenkins 没有初始化环境变量
查看从节点的系统信息,可以看到 file.encoding 是 ASNI 编码
解决办法就是新建一个用户使用 -d 指定 home 目录,

useradd -d /home/jenkins jenkins

目的是为了生成 .bashrc .bash_logout .bash_profile 三个文件,将这 3 个文件拷贝到 Jenkins 的home 目录下并授权, 就解决了
再去看从节点的 file.encoding 已经变成 UTF-8 了

使用 @ConfigurationProperties(prefix = "xxxx") 注解配置类

在 Nacos 配置中心里修改相应的配置会自动的刷新属性(配置类上不需要注解 @RefreshScope)

还可以通过发送 POST 请求手动刷新 /actuator/refresh 配置

修改保存后会发现日志打印出如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
2021-09-29 01:02:22.081 INFO [etc-gateway,,] 2664 --- [xxx_6101] c.a.n.client.config.impl.ClientWorker : [fixed-xxxx_6101] [polling-resp] config changed. dataId=etc-gateway.yaml, group=DEFAULT_GROUP
2021-09-29 01:02:22.081 INFO [etc-gateway,,] 2664 --- [xxx_6101] c.a.n.client.config.impl.ClientWorker : get changedGroupKeys:[etc-gateway.yaml+DEFAULT_GROUP]
2021-09-29 01:02:22.129 INFO [etc-gateway,,] 2664 --- [xxx_6101] c.a.n.client.config.impl.ClientWorker : [fixed-xxx_6101] [data-received] dataId=etc-gateway.yaml, group=DEFAULT_GROUP, tenant=null, md5=5b9beb32de2d18493f8f840ecdabc9d5, content=spring:
application:
name: etc-gateway
profiles:
include: base
cloud:
gateway:
..., type=yaml

2021-09-29 01:02:23.891 INFO [etc-gateway,,] 2664 --- [xxx_6101] o.s.c.e.event.RefreshEventListener : Refresh keys changed: [swagger.production]

这里记录我遇到的坑:
控制台打印:

1
2
3
4
2021-09-29 01:06:18.896 INFO [etc-gateway,,] 3640 --- [xxx_6101] c.a.nacos.client.config.impl.CacheData : [fixed-xxx_6101] [notify-context] dataId=etc-gateway.yaml, group=DEFAULT_GROUP, md5=4c20b06be83314e17467d3f41d821094
2021-09-29 01:06:19.293 WARN [etc-gateway,,] 3640 --- [xxx_6101] c.a.c.n.c.NacosPropertySourceBuilder : Ignore the empty nacos configuration and get it based on dataId[null.yaml] & group[DEFAULT_GROUP]
2021-09-29 01:06:19.329 WARN [etc-gateway,,] 3640 --- [xxx_6101] c.a.c.n.c.NacosPropertySourceBuilder : Ignore the empty nacos configuration and get it based on dataId[null-base.yaml] & group[DEFAULT_GROUP]

这里说明没有正确读到 application.name
在 bootstrap.yml 配置文件里正确配置

1
2
3
spring:
application:
name: etc-gateway

即可

我这里 bootstrap.yml 配置时多个项目公用的,可以配置环境变量 -Dspring.application.name=etc-gateway

配置 https:

1
2
3
4
5
6
7
8
listen       80 ssl;
ssl_certificate /etc/nginx/conf.d/epark.ahhtk.com.pem;
ssl_certificate_key /etc/nginx/conf.d/epark.ahhtk.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
#表示使用的加密套件的类型。
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #表示使用的TLS协议的类型。
ssl_prefer_server_ciphers on;

正常情况下使用 80 和 443 端口实现 http 自动跳转 https 的话配置:

1
2
3
4
5
6
7
8
server {
listen 80;
server_name yourdomain.com; #需要将yourdomain.com替换成证书绑定的域名。
rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。
location / {
index index.html index.htm;
}
}

如果不是正常的端口的话,注释掉上面的 rewrite 配置,新增如下配置即可

error_page 497 301 https://$http_host$request_uri;

1
2
3
4
5
6
7
8
9
10
11
stream {

upstream rabbit {
server 172.30.241.82:5672;
}

server{
listen 45672;
proxy_pass rabbit;
}
}

stream 放到和 http 同一级

别忘了开启防火墙端口

firewall-cmd --zone=public --add-port=45672/tcp --permanent
firewall-cmd --reload

如果提示错误 unknown directive "stream"
则需要加载相应的模块

在 nginx.conf 配置

1
load_module /usr/lib64/nginx/modules/ngx_stream_module.so;

这里是我用的包
Modules

使用源码编译包

下载源码

地址 :https://nginx.org/en/download.html

启动一个 docker 容器用来编译打包

docker run -it -v /tmp/nginx-1.18.0/:/data centos:7.4.1708 bash

安装编译工具等

1
yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
1
yum groupinstall 'Development Tools'

配置,编译,安装

1
2
3
4
5
./configure --prefix=/usr/local/nginx  --with-http_stub_status_module --with-http_ssl_module --with-stream

make

make install

然后直接拷贝编译好的 nginx 二进制文件用就行

暴露挂载点的机器:

yum -y install nfs-utils

mkdir -p /nfs/data/

chmod -R 777 /nfs/data

vim /etc/exports

写入以下内容:

/nfs/data *(rw,no_root_squash,sync)

生效配置并查看

exportfs -r
exportfs

启动服务:

systemctl restart rpcbind && systemctl enable rpcbind
systemctl restart nfs-server && systemctl enable nfs-server

其他需要进行挂载的机器:

1
2
3
yum -y install nfs-utils
systemctl start nfs rpcbind
systemctl enable nfs rpcbind

测试挂载:
showmount -e 192.168.1.2

直接挂载到本地查看:
mount 192.168.1.2:/nfs/data /opt

卸载挂载:
umount /opt

Pod 挂载使用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
apiVersion: v1
kind: Pod
metadata:
labels:
run: nginx
name: podxx
spec:
volumes:
- name: nfs
nfs:
server: 192.168.1.244
path: /nfs/data
containers:
- image: nginx
name: nginx
volumeMounts:
- mountPath: /usr/share/nginx/html
name: nfs
0%