JoyLau's Blog

JoyLau 的技术学习与思考

proxy_cookie_path source target;
source 源路径
target 目标路径

使用原因

cookie 的 path 与地址栏上的 path 不一致
浏览器就不会接受这个 cookie,无法传入 JSESSIONID 的 cookie
导致登录验证失败

使用场景

当 nginx 配置的反向代理的路径和源地址路径不一致时使用

使用 Demo

1
2
3
4
5
6
7
8
9
# elastic-job 代理配置
location /etc-job/api/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.55.3.139:8088/api/;
proxy_cookie_path / /etc-job/api/;
proxy_set_header Cookie $http_cookie;
}

  1. 下载 minIO 客户端

http://dl.minio.org.cn/client/mc/release/linux-amd64/mc

拷贝到 MySQL 服务器的 /usr/bin 目录下并授权

chmod +x /usr/bin/mc

  1. 配置 mc 客户端

mc config host add minio http://10.55.3.132:9000 "AKIAIOSFODNN7EXAMPLE" "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"

文档地址: https://docs.min.io/minio/baremetal/reference/minio-cli/minio-mc.html

  1. 添加备份脚本

mysql-backup.sh

1
2
3
4
5
6
7
8
9
#!/bin/sh

# 创建桶 mysql-backup
mc mb minio/mysql-backup

docker exec mysql-slave-1 mysqldump -h 10.55.3.123 -u root -pKaiyuan@2020 etc | mc pipe --attr "Artist=mysql" minio/mysql-backup/etc-`date "+%Y-%m-%d_%H-%M-%S"`.sql

# 删除 10 天前的备份
mc rm --older-than=10d --force --recursive minio/mysql-backup/

chmod +x mysql-backup.sh

  1. 添加定时任务
1
2
3
4
crontab -e

30 4 * * * /root/backup-mysql.sh>/root/backup-mysql.log 2>&1 &

说明

公司内网的 GitLab 服务很久没升级了,记录下最近的升级步骤

现有部署情况

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
version: "3"
services:
gitlab:
image: gitlab/gitlab-ce:15.4.2-ce.0
container_name: gitlab
ports:
- 80:80
- 443:443
- 22:22
volumes:
- ./config:/etc/gitlab
- ./log:/var/log/gitlab
- ./data:/var/opt/gitlab
restart: always

gitlab.rc 文件配置:

1
2
3
external_url 'http://192.168.1.41'
#备份保存时间为 2 天, 单位为秒
gitlab_rails['backup_keep_time'] = 172800

只配置了这 2 项, 其他均为默认配置

升级步骤

首先备份当前服务的数据, docker exec 进入容器, 执行

gitlab-backup create

耐心等待备份完成
后续出问题要恢复的话,执行
gitlab-backup restore BACKUP=11493107454_2018_04_25_10.6.4-ce

接下来开始升级,升级的思路是逐步升级到一个大版本开始和结束,一层层往上升级,这里官方给出的升级路线是:

8.11.Z -> 8.12.0 -> 8.17.7 -> 9.5.10 -> 10.8.7 -> 11.11.8 -> 12.0.12 -> 12.1.17 -> 12.10.14 -> 13.0.14 -> 13.1.11 -> 13.8.8 -> 13.12.15 -> 14.0.12 -> 14.3.6 -> 14.9.5 -> 14.10.Z -> 15.0.Z -> 15.4.0 -> latest 15.Y.Z

官方文档

还有个升级路径检测 工具

根据上述路径, 我们只需要每次更改 image: gitlab/gitlab-ce:15.4.2-ce.0 的版本号,重启容器,等容器 Gitlab 正常提供服务,再重复步骤即可

步骤

https://copr.fedorainfracloud.org/coprs/ibotty/prometheus-exporters/

curl -Lo /etc/yum.repos.d/_copr_ibotty-prometheus-exporters.repo https://copr.fedorainfracloud.org/coprs/ibotty/prometheus-exporters/repo/epel-7/ibotty-prometheus-exporters-epel-7.repo

yum -y install node_exporter

systemctl enable node_exporter

systemctl start node_exporter

echo “success”

关闭机器防火墙:

systemctl stop firewalld.service

systemctl disable firewalld.service

在test.jar 的同目录下新建一个与 NeedReplace 类的全路径相同的目录,执行以下命令
md com\lovedata\bigdata\jar
执行 java -jar 来进行替换
jar uvf test.jar com\lovedata\bigdata\jar\NeedReplace.class

主:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
version: "3"
services:
mysql:
image: mysql:8.0.22
container_name: mysql
restart: always
security_opt:
- seccomp:unconfined
ports:
- 3306:3306
volumes:
- ./mysql-data:/var/lib/mysql
- ./my.cnf:/etc/mysql/my.cnf
environment:
- MYSQL_ROOT_PASSWORD=Kaiyuan@2020
- TZ=Asia/Shanghai

my.cnf:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL

# Custom config should go here
!includedir /etc/mysql/conf.d/

max_connections=1024

sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

server-id=1

最主要的配置: server-id=1

从:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
version: "3"
services:
mysql:
image: mysql:8.0.22
container_name: mysql-slave-1
restart: always
security_opt:
- seccomp:unconfined
ports:
- 3306:3306
volumes:
- ./mysql-data:/var/lib/mysql
- ./my.cnf:/etc/mysql/my.cnf
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
- MYSQL_ROOT_PASSWORD=Kaiyuan@2020
- TZ=Asia/Shanghai

my.cnf:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL

# Custom config should go here
!includedir /etc/mysql/conf.d/

max_connections=1024

sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

server-id=2
super-read-only

和主不同的是, server-id=2, super-read-only 开启只读模式

init.sql:

1
2
3
change master to master_host='10.55.3.122',master_port=3306,master_user='root',master_password='Kaiyuan@2020';
reset slave;
start slave;

配置

  1. 将原先的接口提取出来,单独写一份
    @FeignClient(value = “etc-exchange”, contextId = “etc-exchange-2”, fallback = PsamRemoteServiceFallback2.class)
    重新声明一个 contextId

  2. 添加配置项

1
2
3
4
5
6
feign:
client:
config:
etc-exchange-2:
connect-timeout: 3000
read-timeout: 3000
0%