开源版本的安装
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
python3 --version
2.1 安装Python3
Python3的安装方法网上有很多参考文档,这里不再赘述,需要注意的一点是如果是自行编译安装,需要开启ssl模块,方法如下:
修改Python源码目录下的Modules/Setup
,把已注释掉的几行取消注释:
# Socket module helper for socket(2)
_socket socketmodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
然后再进行编译安装操作。
2.2 创建Python虚拟环境
创建Python的虚拟环境
/opt/Your_Python3_Path/bin/python3 -m venv /opt/csu_pyenv
加载虚拟环境
source /opt/csu_pyenv/bin/activate
配置国内的pip镜像源(此处使用的是阿里的pip源),已配置则忽略
pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
echo "
[install]
trusted-host = mirrors.aliyun.com" >> /root/.config/pip/pip.conf
安装工具包
pip install psutil==5.9.4
pip install pystack-debugger
pip install tabulate==0.8.10
pip install pycrypto==2.6.1
pip install pycryptodome==3.17
pip install PyYAML==6.0
pip install isort==5.12.0
pip install ordered-set==4.1.0
pip install python-docx==0.8.11
pip install rsa==4.9
pip install pyasn1==0.5.0
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或者更高。
安装PostgreSQL的repo源
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
禁用系统中预配置的 PostgreSQL 模块,防止安装预定义版本的PostgreSQL
sudo dnf -qy module disable postgresql
执行安装
sudo dnf -y install postgresql12.x86_64 postgresql12-server.x86_64 postgresql12-contrib.x86_64 postgresql12-libs.x86_64
3.1.2 csumdb的初始化
创建系统用户
groupadd -g 571 csumdb
useradd -u 571 -g 571 -d /home/csumdb -m -s /bin/bash csumdb
切换到此用户下
su - csumdb
配置用户环境变量
.bashrc
,在文件顶部增加下面的内容# ====== Add by csumdb init env **do not modify** begin
export PATH=/usr/pgsql-12/bin:$PATH
export LD_LIBRARY_PATH=/usr/pgsql-12/lib:$LD_LIBRARY_PATH
export PGDATA=~/pgdata
export PGHOST=127.0.0.1
export PGPORT=3500
export PGDATABASE=openclup
export PGUSER=csuapp
# ====== Add by csumdb init env **do not modify** end
配置数据库用户密码
echo "127.0.0.1:5432:openclup:csuapp:openclup" > ~/.pgpass && chmod 600 ~/.pgpass
初始化一个数据库实例
initdb
在文件
/home/csumdb/pgdata/pg_hba.conf
末尾追加local all all peer
host all all 0/0 md5
local replication all peer
host replication all 0/0 md5
在文件
/home/csumdb/pgdata/postgresql.conf
末尾追加listen_addresses = '*'
shared_buffers = 32MB
max_wal_size = 1GB
min_wal_size = 800MB
logging_collector = on
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
log_timezone = 'PRC'
track_io_timing = on
track_functions = all
datestyle = 'iso, mdy'
timezone = 'PRC'
启动数据库
pg_ctl start
登录
template1
数据库psql -h /tmp -Ucsumdb -d template1
创建用户及数据库
CREATE USER csuapp superuser password 'csuMgr232';
CREATE DATABASE openclup owner csuapp;
ALTER ROLE csuapp login;
ALTER ROLE csuapp replication;
设置用户权限
\c openclup
REVOKE CREATE ON SCHEMA public from public;
ALTER SCHEMA public OWNER TO csuapp;
3.2 部署CLup Server端(clup)源码
安装依赖项
dnf install -y tcl tcl-devel tk
下载源码(需要root用户,将源码放到
/opt
目录下),克隆仓库:cd /opt
git clone https://gitee.com/csudata/clup.git
复制配置文件
cd /opt/clup/conf
cp example_clup.conf clup.conf
修改配置文件
/opt/clup/conf/clup.conf
,注意替换对应字段的值#格式为 key = value
# ++++++++++++++++++++++++++++++++ 网络 ++++++++++++++++++++++++++++++++
# 网络地址(即IP地址与掩码做and位运算后的值),本cluster软件将运行在此网络中,如果主机有多个IP地址,则使用这个网络内的IP地址做为通信的IP
network=10.197.160.0
# 设置用于检查是否是自己变成了孤岛的检查IP,可以为逗号分隔的多个ip,如果这些IP能ping通,说明不是自己不是孤岛,注意最多设置三个IP,多余的被忽略
probe_island_ip=10.197.160.4
# ++++++++++++++++++++++++++++++++ RPC连接 ++++++++++++++++++++++++++++++++
#agent与服务器之间通信的密码
internal_rpc_pass = clup_pass_pwd
# 如果是集群模式,要求所有的CLup的server_rpc_port都相等
server_rpc_port = 4242
agent_rpc_port = 4243
# ++++++++++++++++++++++++++++++++ WEB页面 ++++++++++++++++++++++++++++++++
# 当把http_auth设置为0时,用admin用户登录,输入任何密码都可以登录,当忘记密码时的就可以使用解决方法
http_auth = 1
# session过期时间,单位s,超过这个时间需要重新登录
session_expired_secs = 600
# 前端管理界面web监听端口
http_port = 8090
http_user = admin
http_pass = openclup
# ++++++++++++++++++++++++++++++++ clup数据库连接 ++++++++++++++++++++++++++++++++
# 数据库连接配置
db_host = 127.0.0.1
db_port = 3500
db_user = csuapp
db_pass = csuMgr232
db_name = openclup
# 当配置了强制reset机器的命令时,执行完此命令之后,是否检查命令的返回值,如果设置为1,则不管命令执行成功还是失败,都认为成功继续进行HA切换。
# 如果设置为0,则如果reset命令执行失败,则HA切换失败
ignore_reset_cmd_return_code = 0
# psql_cmd的路径:
psql_cmd=/usr/pgsql-12/bin/psql
启动服务
[root@clup01 opt]# source /opt/csu_pyenv/bin/activate
(csu_pyenv) [root@openCLup01 opt]# python /opt/clup/lib/clup_server.py start
INFO:root:========== CLup starting ==========
2024-08-20 17:41:28,734 INFO ========== CLup starting ==========
提示
如果服务无法正常启动,请查看日志
/opt/clup/logs/clupserver.log
获取错误信息。然后我们在浏览器输入 http://IP:8090 (注意替换IP为安装clup的主机IP地址),打开WEB界面:
- 用户名为:admin
- 密码为:openclup
输入后就可以登陆CLup的管理界面了。WEB界面中可以管理的数据库当前都是空的,还需要在数据库主机中部署clup-agent后,才能进一步的操作。
4. CLup Agent端(clup-agent)的安装
在需要部署数据库的主机上安装clup-agent。
安装依赖项:
dnf install -y psmisc tcl tcl-devel tk
提示
需要跟clup Server端一样的方法配置好Python3.9的环境,这里就不赘述了。
下载clup-agent源码,克隆仓库:
cd /opt
git clone https://gitee.com/csudata/clup-agent.git
设置配置文件:
cd /opt/clup-agent/conf
cp example-clup-agent.conf clup-agent.conf
修改配置文件
/opt/clup-agent/conf/clup-agent.conf
,通常只需替换mgr_network
和server_address
:# key = value
# If the machine has multiple IPs, it is necessary to specify which network's IP address to use
#mgr_network = 192.168.56.0
mgr_network = 10.197.160.0
#Specify the address of the CLup server
#server_address = 192.168.56.80:4242
server_address = 10.197.166.35:4242
#agent与服务器之间通信的密码
internal_rpc_pass = clup_pass_pwd
# Under normal circumstances, the clup agent can only be started after the CLup server is started.
# But sometimes we need to start the clup-agent separately when the CLup server is not started,
# and in this case, we can set standalone to 1
# standalone = 0
agent_rpc_port = 4243
启动服务
[root@clup02 opt]# source /opt/csu_pyenv/bin/activate
(csu_pyenv) [root@openCLup02 opt]# python /opt/clup-agent/lib/clup_agent.py start
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数据库的方法。
下载安装包:
wget https://gitee.com/csudata/csupg/releases/download/csupg_el7/csupg-14.9.el7.x86_64.bin
安装,数据库软件的目录会生成在/usr下:
bash csupg-14.9.el7.x86_64.bin
上面给出的示例是el7下的PostgreSQL14.9的版本,我们还提供了PG10~PG14的版本和el8的版本,请移步此处查看下载:csupg 发行版 - Gitee.com