首页
解决方案
数据库专业技术服务全栈式PostgreSQL解决方案Oracle分布式存储化数据库云PolarDB一体化解决方案
产品
CLup:PostgreSQL高可用集群平台 CMiner: PostgreSQL中的CDC CData高性能数据库云一体机 CBackup数据库备份恢复云平台 CPDA高性能双子星数据库机 CSYun超融合虚拟机产品 ZQPool数据库连接池 ConshGuard数据保护产品 APCC: Greenplum管理平台
文档
文章
客户及伙伴
中启开源
关于我们
公司简介 联系我们
中启开源
修改标题
往前插入
往后插入
删除

开源版本的安装

1. 开源版安装说明

CLup开源版本需要运行在Python3.9以上的Python环境中,而有些操作系统没有相适配的Python3,而这时可以用我们准备了好的Python3.9的软件包,这个软件包称为csupy。

目前开源版本支持的系统架构和版本请参照CLup简介-3.2 开源版支持平台。部分未提供csupy的环境,需要根据下面2. Python环境准备自行准备Python3的虚拟环境。

以下文档中示例环境的操作系统为Rocky Linux 8,如果是其他操作系统,请根据情况修改命令。

2. Python环境准备

查看系统的Python3版本,如果小于Python3.9.16,则需要先安装Python3

  1. python3 --version

2.1 安装Python3

Python3的安装方法网上有很多参考文档,这里不再赘述,需要注意的一点是如果是自行编译安装,需要开启ssl模块,方法如下:

修改Python源码目录下的Modules/Setup,把已注释掉的几行取消注释:

  1. # Socket module helper for socket(2)
  2. _socket socketmodule.c
  3. # Socket module helper for SSL support; you must comment out the other
  4. # socket line above, and possibly edit the SSL variable:
  5. #SSL=/usr/local/ssl
  6. _ssl _ssl.c \
  7. -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
  8. -L$(SSL)/lib -lssl -lcrypto

然后再进行编译安装操作。

2.2 创建Python虚拟环境

  1. 创建Python的虚拟环境

    1. /opt/Your_Python3_Path/bin/python3 -m venv /opt/csu_pyenv
  2. 加载虚拟环境

    1. source /opt/csu_pyenv/bin/activate
  3. 配置国内的pip镜像源(此处使用的是阿里的pip源),已配置则忽略

    1. pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
    2. echo "
    3. [install]
    4. trusted-host = mirrors.aliyun.com" >> /root/.config/pip/pip.conf
  4. 安装工具包

    1. pip install psutil==5.9.4
    2. pip install pystack-debugger
    3. pip install tabulate==0.8.10
    4. pip install pycrypto==2.6.1
    5. pip install pycryptodome==3.17
    6. pip install PyYAML==6.0
    7. pip install isort==5.12.0
    8. pip install ordered-set==4.1.0
    9. pip install python-docx==0.8.11
    10. pip install rsa==4.9
    11. pip install pyasn1==0.5.0
    12. pip install psycopg2-binary==2.9.6

    提示

    可能存在部分平台上有些包需要安装不同的版本,请根据需求调整。

3. CLup Server端(clup)的安装

3.1 安装csumdb

CLup自身的数据也是保存在一个PostgreSQL数据库中的,这个库我们称之为csumdb。当前支持的平台参照CLup简介-3.2 开源版支持平台,没有支持的平台或者想要使用自己的PostgreSQL数据库,可以参照以下步骤准备csumdb。

3.1.1 安装PostgreSQL数据库软件

PostgreSQL数据库的安装文档网上资源有很多,也可以参照PostgreSQL官方文档进行安装,下面给出在Rocky8下面的安装步骤,其文档参照RHEL8下的安装文档注意: PostgreSQL 数据库的版本需要为12或者更高。

  1. 安装PostgreSQL的repo源

    1. sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  2. 禁用系统中预配置的 PostgreSQL 模块,防止安装预定义版本的PostgreSQL

    1. sudo dnf -qy module disable postgresql
  3. 执行安装

    1. sudo dnf -y install postgresql12.x86_64 postgresql12-server.x86_64 postgresql12-contrib.x86_64 postgresql12-libs.x86_64

3.1.2 csumdb的初始化

  1. 创建系统用户

    1. groupadd -g 571 csumdb
    2. useradd -u 571 -g 571 -d /home/csumdb -m -s /bin/bash csumdb
  2. 切换到此用户下

    1. su - csumdb
  3. 配置用户环境变量.bashrc,在文件顶部增加下面的内容

    1. # ====== Add by csumdb init env **do not modify** begin
    2. export PATH=/usr/pgsql-12/bin:$PATH
    3. export LD_LIBRARY_PATH=/usr/pgsql-12/lib:$LD_LIBRARY_PATH
    4. export PGDATA=~/pgdata
    5. export PGHOST=127.0.0.1
    6. export PGPORT=3500
    7. export PGDATABASE=openclup
    8. export PGUSER=csuapp
    9. # ====== Add by csumdb init env **do not modify** end
  4. 配置数据库用户密码

    1. echo "127.0.0.1:5432:openclup:csuapp:openclup" > ~/.pgpass && chmod 600 ~/.pgpass
  5. 初始化一个数据库实例

    1. initdb
  6. 在文件/home/csumdb/pgdata/pg_hba.conf末尾追加

    1. local all all peer
    2. host all all 0/0 md5
    3. local replication all peer
    4. host replication all 0/0 md5
  7. 在文件/home/csumdb/pgdata/postgresql.conf末尾追加

    1. listen_addresses = '*'
    2. shared_buffers = 32MB
    3. max_wal_size = 1GB
    4. min_wal_size = 800MB
    5. logging_collector = on
    6. log_filename = 'postgresql-%a.log'
    7. log_truncate_on_rotation = on
    8. log_timezone = 'PRC'
    9. track_io_timing = on
    10. track_functions = all
    11. datestyle = 'iso, mdy'
    12. timezone = 'PRC'
  8. 启动数据库

    1. pg_ctl start
  9. 登录template1数据库

    1. psql -h /tmp -Ucsumdb -d template1
  10. 创建用户及数据库

    1. CREATE USER csuapp superuser password 'csuMgr232';
    2. CREATE DATABASE openclup owner csuapp;
    3. ALTER ROLE csuapp login;
    4. ALTER ROLE csuapp replication;
  11. 设置用户权限

    1. \c openclup
    2. REVOKE CREATE ON SCHEMA public from public;
    3. ALTER SCHEMA public OWNER TO csuapp;

3.2 部署CLup Server端(clup)源码

  1. 安装依赖项

    1. dnf install -y tcl tcl-devel tk
  2. 下载源码(需要root用户,将源码放到/opt目录下),克隆仓库:

    1. cd /opt
    2. git clone https://gitee.com/csudata/clup.git
  3. 复制配置文件

    1. cd /opt/clup/conf
    2. cp example_clup.conf clup.conf
  4. 修改配置文件/opt/clup/conf/clup.conf,注意替换对应字段的值

    1. #格式为 key = value
    2. # ++++++++++++++++++++++++++++++++ 网络 ++++++++++++++++++++++++++++++++
    3. # 网络地址(即IP地址与掩码做and位运算后的值),本cluster软件将运行在此网络中,如果主机有多个IP地址,则使用这个网络内的IP地址做为通信的IP
    4. network=10.197.160.0
    5. # 设置用于检查是否是自己变成了孤岛的检查IP,可以为逗号分隔的多个ip,如果这些IP能ping通,说明不是自己不是孤岛,注意最多设置三个IP,多余的被忽略
    6. probe_island_ip=10.197.160.4
    7. # ++++++++++++++++++++++++++++++++ RPC连接 ++++++++++++++++++++++++++++++++
    8. #agent与服务器之间通信的密码
    9. internal_rpc_pass = clup_pass_pwd
    10. # 如果是集群模式,要求所有的CLup的server_rpc_port都相等
    11. server_rpc_port = 4242
    12. agent_rpc_port = 4243
    13. # ++++++++++++++++++++++++++++++++ WEB页面 ++++++++++++++++++++++++++++++++
    14. # 当把http_auth设置为0时,用admin用户登录,输入任何密码都可以登录,当忘记密码时的就可以使用解决方法
    15. http_auth = 1
    16. # session过期时间,单位s,超过这个时间需要重新登录
    17. session_expired_secs = 600
    18. # 前端管理界面web监听端口
    19. http_port = 8090
    20. http_user = admin
    21. http_pass = openclup
    22. # ++++++++++++++++++++++++++++++++ clup数据库连接 ++++++++++++++++++++++++++++++++
    23. # 数据库连接配置
    24. db_host = 127.0.0.1
    25. db_port = 3500
    26. db_user = csuapp
    27. db_pass = csuMgr232
    28. db_name = openclup
    29. # 当配置了强制reset机器的命令时,执行完此命令之后,是否检查命令的返回值,如果设置为1,则不管命令执行成功还是失败,都认为成功继续进行HA切换。
    30. # 如果设置为0,则如果reset命令执行失败,则HA切换失败
    31. ignore_reset_cmd_return_code = 0
    32. # psql_cmd的路径:
    33. psql_cmd=/usr/pgsql-12/bin/psql
  5. 启动服务

    1. [root@clup01 opt]# source /opt/csu_pyenv/bin/activate
    2. (csu_pyenv) [root@openCLup01 opt]# python /opt/clup/lib/clup_server.py start
    3. INFO:root:========== CLup starting ==========
    4. 2024-08-20 17:41:28,734 INFO ========== CLup starting ==========

    提示

    如果服务无法正常启动,请查看日志/opt/clup/logs/clupserver.log获取错误信息。

  6. 然后我们在浏览器输入 http://IP:8090 (注意替换IP为安装clup的主机IP地址),打开WEB界面:
    img

    • 用户名为:admin
    • 密码为:openclup

    输入后就可以登陆CLup的管理界面了。WEB界面中可以管理的数据库当前都是空的,还需要在数据库主机中部署clup-agent后,才能进一步的操作。

4. CLup Agent端(clup-agent)的安装

在需要部署数据库的主机上安装clup-agent。

  1. 安装依赖项:

    1. dnf install -y psmisc tcl tcl-devel tk

    提示

    需要跟clup Server端一样的方法配置好Python3.9的环境,这里就不赘述了。

  2. 下载clup-agent源码,克隆仓库:

    1. cd /opt
    2. git clone https://gitee.com/csudata/clup-agent.git
  3. 设置配置文件:

    1. cd /opt/clup-agent/conf
    2. cp example-clup-agent.conf clup-agent.conf
  4. 修改配置文件/opt/clup-agent/conf/clup-agent.conf,通常只需替换mgr_networkserver_address

    1. # key = value
    2. # If the machine has multiple IPs, it is necessary to specify which network's IP address to use
    3. #mgr_network = 192.168.56.0
    4. mgr_network = 10.197.160.0
    5. #Specify the address of the CLup server
    6. #server_address = 192.168.56.80:4242
    7. server_address = 10.197.166.35:4242
    8. #agent与服务器之间通信的密码
    9. internal_rpc_pass = clup_pass_pwd
    10. # Under normal circumstances, the clup agent can only be started after the CLup server is started.
    11. # But sometimes we need to start the clup-agent separately when the CLup server is not started,
    12. # and in this case, we can set standalone to 1
    13. # standalone = 0
    14. agent_rpc_port = 4243
  5. 启动服务

    1. [root@clup02 opt]# source /opt/csu_pyenv/bin/activate
    2. (csu_pyenv) [root@openCLup02 opt]# python /opt/clup-agent/lib/clup_agent.py start
    3. 2024-08-20 17:54:47,696 INFO Clup-Agent v5.0.0 Copyright (c) 2019 HangZhou CSTech.Ltd. All rights reserved.

5. 安装PostgreSQL数据库软件

可以使用PostgreSQL官方提供的方法安装PostgreSQL软件。但这里为了方便大家快速的入门,这里提供了一个快速安装的PostgreSQL数据库的方法。
下载安装包:

  1. wget https://gitee.com/csudata/csupg/releases/download/csupg_el7/csupg-14.9.el7.x86_64.bin

安装,数据库软件的目录会生成在/usr下:

  1. bash csupg-14.9.el7.x86_64.bin

上面给出的示例是el7下的PostgreSQL14.9的版本,我们还提供了PG10~PG14的版本和el8的版本,请移步此处查看下载:csupg 发行版 - Gitee.com

目录
img