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

快速安装

1. 部署的架构

CLup程序分两个模块:

部署的架构图:
部署的架构图

开源版暂时仅支持el7和el8系统。

2. 机器的规划

部署CLup我们使用4台虚拟机,操作系统使用CentOS7.6,其中一台机器部署clup-server,其它3台机器上跑数据库并安装部署clup-agent程序。

主机名 IP 作用 数据目录
clup0 10.197.166.35 部署clup-server N/A
clup1 10.197.166.36 数据库机器,部署clup-agent /data/pgdata
clup2 10.197.166.37 数据库机器,部署clup-agent /data/pgdata
clup3 10.197.166.38 数据库机器,部署clup-agent /data/pgdata

注意:对于企业版未注册时会有CPU的核数限制(Agent端合计20核心,开源版无此限制),可以选择使用2核心虚拟机9台或者4核心虚拟机5台,这样就不会超过试用版的CPU核数限制。如果测试需要更多核心、解锁更多功能,可以电话0571-87603386,申请一个试用的license。

3. 安装clup-server

3.1 企业版的安装方法

我们使用一键安装脚本进行安装。如果想了解更详细的安装方法,请阅读后续章节《 安装详解 》 中的内容。

目前一键安装脚本仅支持el7和el8系统,clup0主机上运行下面脚本即可一键安装

  1. wget -qO /tmp/clup.sh https://get.csudata.com/csuinst/clup.sh && bash /tmp/clup.sh clup install

然后我们在浏览器输入 http://10.197.166.35:8090 ,打开WEB界面:

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

3.2 开源版的安装方法

3.2.1 安装Python

CLup要求python3.9及以上的版本。由于在CentOS7.X下面,没有python3.9,我们已经编译好了python3.9的版本供大家下载:

  1. # 下载软件包,需要放到/opt目录下
  2. cd /opt
  3. wget https://gitee.com/csudata/csupy3.9.16/releases/download/1.0/csupy3.9.16.el7.tar.xz
  4. # 解压软件包
  5. tar xf csupy3.9.16.el7.tar.xz
  6. # 添加lib包的路径到环境变量
  7. echo "export LD_LIBRARY_PATH=/opt/csupy3.9.16/lib:\$LD_LIBRARY_PATH" >> ~/.bashrc
  8. # 添加bin路径到PATH环境变量
  9. echo "export PATH=/opt/csupy3.9.16/bin:\$PATH" >> ~/.bashrc
  10. # 加载环境
  11. source ~/.bashrc

如果是使用自己的Python3.9的环境,需要安装的python依赖包如下:

  1. echo "certifi==2022.12.7
  2. cffi==1.15.1
  3. charset-normalizer==3.1.0
  4. click==5.1
  5. cryptography==40.0.2
  6. idna==3.4
  7. isort==5.12.0
  8. lxml==4.9.1
  9. ordered-set==4.1.0
  10. packaging==23.1
  11. psutil==5.9.4
  12. psycopg2-binary==2.8.6
  13. pyasn1==0.4.8
  14. pycparser==2.21
  15. pycrypto==2.6.1
  16. pycryptodome==3.19.0
  17. pyspnego==0.8.0
  18. pystack-debugger==0.10.0
  19. PyYAML==6.0
  20. requests==2.28.2
  21. requests-ntlm==1.2.0
  22. rsa==4.9
  23. six==1.16.0
  24. tabulate==0.8.10
  25. urllib3==1.26.15
  26. xmltodict==0.13.0
  27. zstandard==0.21.0" > requirements.txt

建议使用国内的pip源,下载会比较快点,这里给出配置阿里的pip源的示例:

建文件“~/.pip/pip.conf”(如果目录.pip不存在需要创建),添加如下内容:

  1. [global]
  2. index-url = http://mirrors.aliyun.com/pypi/simple/
  3. [install]
  4. trusted-host=mirrors.aliyun.com

快速安装依赖包:

  1. # 注意先加载自己的Python环境
  2. pip3 install -r requirements.txt

如果安装pycrypto时报错,请先安装编译环境依赖yum install -y gcc-c++ cmake,或参照相关的python文档。

3.2.2 server端安装csumdb

CLup自身的数据也是保存在一个PostgreSQL数据库的,这个库我们称之为csumdb。可以在Server端安装一套PostgreSQL数据库。如果是企业版本的CLup,前面的一键安装脚本会自动安装好一个我们内置的csumdb数据库。
这里我们使用yum源安装。

1.安装PostgreSQL的repo源

  1. yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

2.安装epel源,这里使用阿里的镜像站

  1. curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

3.安装PostgreSQL数据库,这里安装的版本是PostgreSQL12

  1. yum -y install postgresql12.x86_64 postgresql12-contrib.x86_64 postgresql12-libs.x86_64 postgresql12-server.x86_64

4.创建系统用户

  1. groupadd -g 571 csumdb
  2. useradd -u 571 -g 571 -d /home/csumdb -m -s /bin/bash csumdb

5.配置用户环境变量

  1. su - csumdb
  2. vi .bashrc
  3. # .bashrc
  4. # ====== Add by csumdb init env **do not modify** begin
  5. export PATH=/usr/pgsql-12/bin:$PATH
  6. export LD_LIBRARY_PATH=/usr/pgsql-12/lib:$LD_LIBRARY_PATH
  7. export PGDATA=~/pgdata
  8. export PGHOST=127.0.0.1
  9. export PGPORT=5432
  10. export PGDATABASE=openclup
  11. export PGUSER=csuapp
  12. # ====== Add by csumdb init env **do not modify** end
  13. # 加载环境变量
  14. source ~/.bashrc

6.配置数据库用户密码

  1. echo "127.0.0.1:5432:openclup:csuapp:openclup" > .pgpass && chmod 600 ~/.pgpass

3.2.3 数据库初始化

1.初始化一个数据库实例

  1. initdb

2.修改用户认证配置文件pgdata/pg_hba.conf

  1. echo "
  2. local all all peer
  3. host all all 0/0 md5
  4. local replication all peer
  5. host replication all 0/0 md5
  6. " >> ~/pgdata/pg_hba.conf

3.修改数据库配置文件pgdata/postgresql.conf

  1. echo "
  2. listen_addresses = '*'
  3. port = 5432
  4. logging_collector = on
  5. log_filename = 'postgresql-%a.log' # log file name pattern,
  6. log_truncate_on_rotation = on
  7. log_timezone = 'PRC'
  8. track_io_timing = on
  9. track_functions = all
  10. datestyle = 'iso, mdy'
  11. timezone = 'PRC'
  12. unix_socket_directories = '.'
  13. lc_messages = 'en_US.UTF-8' # locale for system error message
  14. lc_monetary = 'en_US.UTF-8' # locale for monetary formatting
  15. lc_numeric = 'en_US.UTF-8' # locale for number formatting
  16. lc_time = 'en_US.UTF-8' # locale for time formatting
  17. " >> ~/pgdata/postgresql.conf

4.启动cusmdb

  1. pg_ctl start -D ~/pgdata

5.启动csumdb后进入template1数据库

  1. psql -d template1 -Ucsumdb

6.修改数据库属性

  1. CREATE USER csuapp password 'openclup';
  2. CREATE DATABASE openclup owner csuapp;
  3. ALTER ROLE csuapp LOGIN;

7.配置用户权限

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

3.2.4 部署OpenCLup源码

1.安装依赖项

  1. yum install -y tcl tcl-devel tk

2.下载源码(需要将源码放到/opt目录下),克隆仓库:

  1. # root
  2. cd /opt
  3. git clone https://gitee.com/csudata/clup.git

3.设置配置文件:

  1. cd /opt/clup/conf
  2. mv example_clup.conf clup.conf

4.修改配置文件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. # 前端管理界面web监听端口
  17. http_port = 8080
  18. http_user = admin
  19. http_pass = openclup
  20. # ++++++++++++++++++++++++++++++++ clup数据库连接 ++++++++++++++++++++++++++++++++
  21. # 数据库连接配置
  22. db_host = 127.0.0.1
  23. db_port = 5432
  24. db_user = csuapp
  25. db_pass = openclup
  26. db_name = openclup
  27. # 当配置了强制reset机器的命令时,执行完此命令之后,是否检查命令的返回值,如果设置为1,则不管命令执行成功还是失败,都认为成功继续进行HA切换。
  28. # 如果设置为0,则如果reset命令执行失败,则HA切换失败
  29. ignore_reset_cmd_return_code = 0
  30. # psql_cmd的路径:
  31. psql_cmd=/usr/pgsql-12/bin/psql

5.启动服务,这里使用的是中启乘数编译好的Python3.9的环境:

  1. # 加载环境
  2. [root@clup0 opt]# source /opt/csu_pyenv/bin/activate
  3. # 启动服务
  4. (csu_pyenv) [root@clup0 opt]# python /opt/clup/lib/clup_server.py start
  5. INFO:root:========== CLup starting ==========
  6. 2023-10-09 14:58:02,195 INFO ========== CLup starting ==========
  7. # 停止服务: python /opt/clup/lib/clup_server.py stop

6.然后我们在浏览器输入 http://10.197.166.35:8080 ,打开WEB界面:

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

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

4. 安装clup-agent

4.1 企业版的安装方法

在需要部署数据库的主机上安装clup-agent。在本示例是在10.197.166.36、10.197.166.37、10.197.166.38机器上安装clup-agent。

使用以下命令一键安装clup-agent,目前仅支持el7和el8系统。

  1. wget -qO /tmp/clup.sh https://get.csudata.com/csuinst/clup.sh && bash /tmp/clup.sh clup-agent install

输入clup服务端的IP地址10.197.166.35然后回车继续:

  1. Enter Clup Server IP Addr: 10.197.166.35
  2. Clup Server ip is 10.197.166.35!
  3. ==== register systemd service ...
  4. 2022-10-08 11:11:47,287 INFO clup-agent v4.4.8 Copyright (c) 2018-2022 CSUDATA.COM All rights reserved.
  5. already register systemd service!
  6. ==== register systemd service ok.
  7. ==== Installation is complete.

4.2 开源版的安装方法

在需要部署数据库的主机上安装clup-agent。在本示例是在10.197.166.36、10.197.166.37、10.197.166.38机器上部署clup-agent。

1.安装依赖项:

  1. yum install -y psmisc.x86_64 tcl tcl-devel tk

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

  1. cd /opt
  2. git clone https://gitee.com/csudata/clup-agent.git

3.设置配置文件:

  1. cd /opt/clup-agent/conf
  2. mv example-clup-agent.conf clup-agent.conf

4.修改配置文件clup-agent.conf

  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 = 10.197.160.0
  4. #Specify the address of the CLup server,CLup serve端的IP和端口,替换IP即可
  5. server_address = 10.197.166.35:4242
  6. # agent与服务器之间通信的密码,保持默认即可
  7. internal_rpc_pass = clup_pass_pwd
  8. # Under normal circumstances, the clup agent can only be started after the CLup server is started.
  9. # But sometimes we need to start the clup-agent separately when the CLup server is not started,
  10. # and in this case, we can set standalone to 1
  11. # standalone = 0
  12. # rpc 端口,保持默认即可
  13. agent_rpc_port = 4243

5.启动服务,注意需要先安装好Python3.9的环境,参照3.2.1 安装Python

  1. # 加载环境
  2. [root@clup1 ~]# source /opt/csu_pyenv/bin/activate
  3. # 启动服务
  4. (csu_pyenv) [root@clup1 ~]# python /opt/clup-agent/lib/clup_agent.py start
  5. 2023-10-09 15:08:08,046 INFO Clup-Agent v5.0.0 Copyright (c) 2019 HangZhou CSTech.Ltd. All rights reserved.
  6. # 停止服务: python /opt/clup/lib/clup_agent.py stop

5. 安装PostgreSQL数据库

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

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

安装:

  1. bash csupg-14.9.el7.x86_64.bin
  2. # 数据库软件的目录会生成在/usr下

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

目录
img