ProxySQL升级时对默认部署的实例的影响

公司有使用默认安装目录的ProxySQL跑业务. 在升级2.0.8 至 2.0.12的时候发现卸载2.0.8后这些使用默认方式安装的ProxySQL实例就会被关闭.

原因是rpm包安装和卸载前后执行了一些动作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
[root@bj1-mysql-manager-prod-01 tmp]# rpm --scripts -qp  /tmp/proxysql-2.0.8-1-centos7.x86_64.rpm 
preinstall scriptlet (using /bin/sh):
# Cleanup artifacts
if [ -f /var/lib/proxysql/PROXYSQL_UPGRADE ]; then
rm -fr /var/lib/proxysql/PROXYSQL_UPGRADE
fi
postinstall scriptlet (using /bin/sh):
# Create relevant user, directories and configuration files
if [ ! -d /var/run/proxysql ]; then /bin/mkdir /var/run/proxysql ; fi
if [ ! -d /var/lib/proxysql ]; then /bin/mkdir /var/lib/proxysql ; fi
if ! id -u proxysql > /dev/null 2>&1; then useradd -r -U -s /bin/false -d /var/lib/proxysql -c "ProxySQL Server" proxysql; fi
/bin/chown -R proxysql: /var/lib/proxysql /var/run/proxysql
/bin/chown root:proxysql /etc/proxysql.cnf
/bin/chmod 640 /etc/proxysql.cnf
# Configure systemd appropriately.
/bin/systemctl daemon-reload
/bin/systemctl enable proxysql.service
# Notify that a package update is in progress in order to start service.
if [ $1 -eq 2 ]; then /bin/touch /var/lib/proxysql/PROXYSQL_UPGRADE ; fi
preuninstall scriptlet (using /bin/sh):
# When uninstalling always try stop the service, ignore failures
/bin/systemctl stop proxysql || true
postuninstall scriptlet (using /bin/sh):
if [ $1 -eq 0 ]; then
# This is a pure uninstall, systemd unit file removed
# only daemon-reload is needed.
/bin/systemctl daemon-reload
else
# This is an upgrade, ProxySQL should be started. This
# logic works for packages newer than 2.0.7 and ensures
# a faster restart time.
/bin/systemctl start proxysql.service
/bin/rm -fr /var/lib/proxysql/PROXYSQL_UPGRADE
fi
posttrans scriptlet (using /bin/sh):
if [ -f /var/lib/proxysql/PROXYSQL_UPGRADE ]; then
# This is a safeguard to start the service after an update
# which supports legacy "preun" / "postun" logic and will
# only execute for packages before 2.0.7.
/bin/systemctl start proxysql.service
/bin/rm -fr /var/lib/proxysql/PROXYSQL_UPGRADE
fi

安装

preinstall

1
2
3
if [ -f /var/lib/proxysql/PROXYSQL_UPGRADE ]; then 
rm -fr /var/lib/proxysql/PROXYSQL_UPGRADE
fi

这就是看如果有PROXYSQL_UPGRADE这个文件就删除掉,这个文件主要是rpm -Uvh升级时会用到

postinstall

1
2
3
4
5
6
7
8
9
10
11
12
# Create relevant user, directories and configuration files
if [ ! -d /var/run/proxysql ]; then /bin/mkdir /var/run/proxysql ; fi
if [ ! -d /var/lib/proxysql ]; then /bin/mkdir /var/lib/proxysql ; fi
if ! id -u proxysql > /dev/null 2>&1; then useradd -r -U -s /bin/false -d /var/lib/proxysql -c "ProxySQL Server" proxysql; fi
/bin/chown -R proxysql: /var/lib/proxysql /var/run/proxysql
/bin/chown root:proxysql /etc/proxysql.cnf
/bin/chmod 640 /etc/proxysql.cnf
# Configure systemd appropriately.
/bin/systemctl daemon-reload
/bin/systemctl enable proxysql.service
# Notify that a package update is in progress in order to start service.
if [ $1 -eq 2 ]; then /bin/touch /var/lib/proxysql/PROXYSQL_UPGRADE ; fi

创建目录, 创建用户, 设置开机启动proxysql.service.

这里主要就是一点, 用systemd管理rpm包安装的proxysql

卸载

preuninstall

1
2
# When uninstalling always try stop the service, ignore failures
/bin/systemctl stop proxysql || true

这里就是把rpm包安装的proxysql实例给关了. 所有如果用默认方式安装的ProxySQL实例, 卸载rpm包的时候这个实例就会被关闭, 所以不建议用这个实例, 应该自己创建, 并且建议把rpm包生成的配置文件, systemd都mv改名, 否则机器重启默认实例启动会占用6032,6033端口

preuninstall

1
2
3
4
5
6
7
8
9
10
11
12
13
14
preuninstall scriptlet (using /bin/sh):

postuninstall scriptlet (using /bin/sh):
if [ $1 -eq 0 ]; then
# This is a pure uninstall, systemd unit file removed
# only daemon-reload is needed.
/bin/systemctl daemon-reload
else
# This is an upgrade, ProxySQL should be started. This
# logic works for packages newer than 2.0.7 and ensures
# a faster restart time.
/bin/systemctl start proxysql.service
/bin/rm -fr /var/lib/proxysql/PROXYSQL_UPGRADE
fi

这里$1我不知道咋取的, 总之就是如果是写在就删了proxysql.service文件后systemctl daemon-reload

另外,为提供操作中可参考的信息,rpm还提供了一种信号机制:不同的操作会返回不同的信息,并放到默认变量$1中。

0代表卸载、1代表安装、2代表升级

如果是升级则会再启动

可以使用rpm -Uvh升级吗?

ansible yum可以完成升级工作, 但不要使用ansible yum升级, 使用此方式升级2.0.8 - 2.0.12会自动安装并启动一个proxysql

1
2
proxysql 125223      1  0 21:17 ?        00:00:00 /usr/bin/proxysql --idle-threads -c /etc/proxysql.cnf
proxysql 125225 125223 0 21:17 ? 00:00:00 /usr/bin/proxysql --idle-threads -c /etc/proxysql.cnf

这个proxysql会占用6032 和 6033 端口. 这种方式实际上应该是使用rpm -Uvh完成的升级, 我手动使用rpm -Uvh升级效果和ansible yum是一致的

应该通过shell rpm -e 2.0.8 再rpm -ivh 2.0.12进行升级, 这种方式不影响(影响rpm默认安装的proxysql实例,因为会关闭)已经运行的proxysql进程 (文件句柄没有释放)

1
2
3
4
5
6
7
[root@centos-1 data]# lsof | grep delete| grep proxysql
proxysql 118312 root txt REG 253,0 36156384 101426928 /usr/bin/proxysql (deleted)
proxysql 118313 root txt REG 253,0 36156384 101426928 /usr/bin/proxysql (deleted)
proxysql 118313 118315 root txt REG 253,0 36156384 101426928 /usr/bin/proxysql (deleted)
proxysql 118313 118316 root txt REG 253,0 36156384 101426928 /usr/bin/proxysql (deleted)
proxysql 118313 118317 root txt REG 253,0 36156384 101426928 /usr/bin/proxysql (deleted)
proxysql 118313 118318 root txt REG 253,0 36156384 101426928 /usr/bin/proxysql (deleted)

另外升级后请
1
2
3
mv /etc/proxysql.cnf /etc/proxysql.cnf.bak
mv /etc/systemd/system/proxysql.service /etc/systemd/system/proxysql.service.bak
mv /etc/systemd/system/proxysql-initial.service /etc/systemd/system/proxysql-initial.service.bak

目前上海的proxysql我都是采用这种方式升级

结论

检查是否有rpm默认安装的proxysql实例, 如果有, 请先升级这个proxysql实例!

Powered by Hexo and Hexo-theme-hiker

Copyright © 2013 - 2022 Fan() All Rights Reserved.

访客数 : | 访问量 :