暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

升级PostgreSQL Patroni集群并将Python 2升级到Python 3

原创 Jobin 2020-01-18
3214

PostgreSQL Patroni集群用Python开发,但是因为Python 2在2020年1月1日之后不再维护和更新,建议升级到Python。

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date.

本文介绍如何在最短时间内将Python2升级到Python3,同时将Patroni升级。

升级Python过程中,保留原Python2版本,以防其他程序用到,将Python 3安装到其他目录,然后再逐个升级Patroni。

1、查看版本信息

升级之前查看Python和Patroni版本。

$ ps -eaf | grep patroni postgres 17418 17066 0 10:19 pts/0 00:00:01 /bin/python /usr/bin/patroni /etc/patroni/patroni.yml postgres 17494 17470 0 10:23 pts/1 00:00:00 grep --color=auto patron $ ls -l /bin/python lrwxrwxrwx. 1 root root 7 Dec 23 10:39 /bin/python -> python2 $ /bin/python --version Python 2.7.5

2、开始升级

安装Python 3。

在CentOS和RHEL中可以使用yum直接安装

sudo yum install -y python3-pip pyOpenSSL python3-devel gcc

Ubuntu

sudo apt install python3-pip

也可以使用pip直接安装

sudo pip3 install --upgrade setuptools sudo pip3 install psycopg2-binary sudo pip3 install wheel

升级Patroni

由于Python会将老版本Patroni编译放到内存中运行,因此我们可以在不停Patroni的情况下,直接卸载Patroni。

$ sudo pip uninstall patroni DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't' be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Uninstalling patroni-1.5.3: Would remove: /usr/bin/patroni /usr/bin/patroni_aws /usr/bin/patroni_wale_restore /usr/bin/patronictl /usr/lib/python2.7/site-packages/patroni-1.5.3-py2.7.egg Proceed (y/n)? y Successfully uninstalled patroni-1.5.3 $ head /usr/bin/patroni head: cannot open '/usr/bin/patroni' for reading: No such file or directory

使用Python 3 安装最新版本Patroni

$ sudo pip3 install patroni[etcd] WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead. Collecting patroni[etcd] Using cached https://files.pythonhosted.org/packages/8f/35/37eeb1b7d54a7d47205050bb6415a74fc7db7a3128e584fc54ff0f5b4cc2/patroni-1.6.3-py3-none-any.whl ... Installing collected packages: patroni Successfully installed patroni-1.6.3 $ which patroni /usr/local/bin/patroni [postgres@pg1 ~]$ head /usr/local/bin/patroni #!/usr/bin/python3

此过程中patroni会一直正常运行,接下里使用新版本patroni接管集群,修改systemd配置文件重启即可。

$which patroni /usr/local/bin/patroni #使用vi sudo vi /etc/systemd/system/patroni.service #或者直接使用systemctl edit sudo systemctl edit --full patroni.service ExecStart=/usr/local/bin/patroni /etc/patroni/patroni.yml # 重启 sudo systemctl daemon-reload sudo systemctl restart patroni

3、验证

最后验证节点是否已经使用新版本的Patroni重新加入集群,确认Patroni是否用Python 3启动。

-bash-4.2$ patronictl -c /etc/patroni/patroni.yml list +----------+--------+------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +----------+--------+------+--------+---------+----+-----------+ | pgcluser | pg0 | pg0 | Leader | running | 2 | | | pgcluser | pg1 | pg1 | | running | 2 | 0 | | pgcluser | pg2 | pg2 | | running | 2 | 0 | +----------+--------+------+--------+---------+----+-----------+ $ ps -eaf | grep patroni postgres 16899 1 0 11:24 ? 00:00:02 /usr/bin/python3 /usr/local/bin/patroni /etc/patroni/patroni.yml postgres 16951 16462 0 11:42 pts/0 00:00:00 grep --color=auto patroni $ /usr/local/bin/patroni --version patroni 1.6.3
最后修改时间:2020-01-18 12:00:52
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论