【我和openGauss的故事】openGauss预安装gs_preinstall代码学习

老老老JR老北
发布于 2023-9-4 11:56
浏览
0收藏

1、在安装openGauss的时候,尤其是非centos、openEuler系统时,经常会遇到一些问题,通过调试跟踪代码可以大概了解下预安装的大概过程,后期再次碰到问题时,也能大概定位到原因。以下是跟踪代码的一些收获:

a.如通过跟踪代码会发现最终的大部分命令都会走到pssh、pscp这两个工具上。这两个工具能执行的前提是互信要建好。

b.如预安装主要是安装和升级集群的时候会使用。了解了预安装后,会发现升级的时候可以不使用root也能进行升级,这在一些不能轻易获取root的环境上是比较有用的。

2、通过跟踪om代码,也能深入对python的学习。

以下是学习openGauss安装过程中的一些琐碎记录。希望对大家有帮助。

可使用vscode进行调试,方法可参考:​使用vscode远程开发&调试openGauss的om代码​。

代码调试配置

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: 当前文件",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": ["-G", "dbgrp", "-U", "omm", "--non-interactive", "-X","/home/omm/single.xml"],
            "justMyCode": true
        }
    ]
}

代码包位置

[root@pghost2 openGauss]# pwd
/opt/software/openGauss
[root@pghost2 openGauss]# ls -l
total 205520
drwxr-xr-x  2 root root      4096 Mar 31 22:26 bin
drwx------ 15 root root      4096 Mar 27 08:02 lib
drwxr-xr-x  9 root root      4096 Mar 31 22:22 libcgroup
-r--------  1 root root       108 Jan 10 22:55 openGauss-3.0.3-openEuler-64bit-cm.sha256
-r--------  1 root root   6423500 Jan 10 22:55 openGauss-3.0.3-openEuler-64bit-cm.tar.gz
-r--------  1 root root        65 Jan 10 22:54 openGauss-3.0.3-openEuler-64bit-om.sha256
-r--------  1 root root  11023820 Jan 10 22:54 openGauss-3.0.3-openEuler-64bit-om.tar.gz
-r--------  1 root root        65 Jan 10 22:55 openGauss-3.0.3-openEuler-64bit.sha256
-r--------  1 root root  87198694 Jan 10 22:55 openGauss-3.0.3-openEuler-64bit.tar.bz2
-r--------  1 root root 105311880 Mar 31 22:15 openGauss-Package-bak_46134f73.tar.gz
drwx------ 11 root root      4096 Mar 31 22:17 script
-r--------  1 root root        65 Jan 10 22:53 upgrade_sql.sha256
-r--------  1 root root    449824 Jan 10 22:53 upgrade_sql.tar.gz
-r--------  1 root root        32 Jan 10 22:53 version.cfg

xml配置

<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
  <CLUSTER>
    <PARAM name="clusterName" value="gauss_omm"/>
    <PARAM name="gaussdbAppPath" value="/app/opengauss/app/2.0.1"/>
    <PARAM name="gaussdbLogPath" value="/app/opengauss/gaussdb_log" />
    <PARAM name="tmpMppdbPath" value="/app/opengauss/tmp"/>
    <PARAM name="gaussdbToolPath" value="/app/opengauss/tool"/>
    <PARAM name="corePath" value="/app/opengauss/corefile"/>
    <PARAM name="backIp1s" value="192.168.56.20,192.168.56.30"/>
    <PARAM name="nodeNames" value="pghost2,pghost3"/>
    <PARAM name="clusterType" value="single-inst"/>
  </CLUSTER>
  <DEVICELIST>
    <DEVICE sn="pghost2">
      <PARAM name="name" value="pghost2"/>
      <PARAM name="backIp1" value="192.168.56.20"/>
      <PARAM name="sshIp1" value="192.168.56.20"/>
      <PARAM name="azName" value="F"/>
      <PARAM name="azPriority" value="1"/>
      <!-- dn -->
      <PARAM name="dataNum" value="1"/>
      <PARAM name="dataPortBase" value="15800"/>
      <PARAM name="dataNode1" value="/app/ogdata/data/dn1,pghost3,/app/ogdata/data/dn1"/>
    </DEVICE>
    <DEVICE sn="pghost3">
      <PARAM name="name" value="pghost3"/>
      <PARAM name="backIp1" value="192.168.56.30"/>
      <PARAM name="sshIp1" value="192.168.56.30"/>
      <PARAM name="azName" value="F"/>
      <PARAM name="azPriority" value="1"/>
    </DEVICE>
  </DEVICELIST>
</ROOT>

预安装过程记录

设置​​LD_LIBRARY_PATH​

[root@pghost2 ~]# echo $LD_LIBRARY_PATH
/app/opengauss/tool/lib:/app/opengauss/tool/script/gspylib/clib:/opt/software/openGauss/script/gspylib/clib:

export LD_LIBRARY_PATH=""

解析命令行参数

# 本次调试参数如下:
 /opt/software/openGauss/script/gs_preinstall -G dbgrp -U omm --non-interactive -X /home/omm/single.xml

是否安装了​​expect​

cmd = "echo exit|expect"
(status, _) = subprocess.getstatusoutput(cmd)
单节点不需要安装该包,非单节点主节点要安装该包。

初始化全局变量

获取​​xml​​​中的​​gaussdbToolPath​​。

解压​​version.cfg​​文件

cd /opt/software/openGauss/script/../ && tar -xpf `head -1 version.cfg`*.tar.bz2 ./version.cfg ./bin/encrypt && mv ./bin/encrypt ./script/gspylib/clib && rm -rf ./bin

change_lib_path

'/opt/software/openGauss/script/../lib'

正式开始预安装

生成​​Package-bak​​包

cd '/opt/software/openGauss' && /bin/tar -zvcf 'openGauss-Package-bak_46134f73.tar.gz' lib/libpython* --exclude=lib/lib*.so* --exclude=script/*.log --exclude=*.log script version.cfg lib --ignore-failed-read upgrade_sql.sha256 upgrade_sql.tar.gz upgrade_sql.sha256 upgrade_sql.tar.gz

# 带cm包
cd '/opt/software/openGauss' && /bin/tar -zvcf 'openGauss-Package-bak_46134f73.tar.gz' lib/libpython* --exclude=lib/lib*.so* --exclude=script/*.log --exclude=*.log script version.cfg lib --ignore-failed-read upgrade_sql.sha256 upgrade_sql.tar.gz upgrade_sql.sha256 upgrade_sql.tar.gz openGauss-3.0.3-openEuler-64bit.tar.bz2 openGauss-3.0.3-openEuler-64bit.sha256 openGauss-3.0.3-openEuler-64bit-cm.tar.gz && /bin/chmod 600 openGauss-Package-bak_46134f73.tar.gz && cd '-'

更改tool目录权限为 750 omm 用户

将 openGauss-Package-bak_46134f73.tar.gz 发送到 /app/opengauss/tool/ 下

在/app/opengauss/tool/下解压openGauss-Package-bak_46134f73.tar.gz包

配置节点间root互信

分发​​Package-bak​​包

这里又重新打了一次包
cd '/app/opengauss/tool' && /bin/tar -zvcf 'openGauss-Package-bak_46134f73.tar.gz' lib/libpython* --exclude=lib/lib*.so* --exclude=script/*.log --exclude=*.log script version.cfg lib --ignore-failed-read upgrade_sql.sha256 upgrade_sql.tar.gz upgrade_sql.sha256 upgrade_sql.tar.gz openGauss-3.0.3-openEuler-64bit.tar.bz2 openGauss-3.0.3-openEuler-64bit.sha256 openGauss-3.0.3-openEuler-64bit-cm.tar.gz && /bin/chmod 600 openGauss-Package-bak_46134f73.tar.gz
  1. 在其余节点新建 /app/opengauss/tool 目录 ,并传送 Package-bak 包。
  2. 将主节点 /opt/software/openGauss 下的复制到其余节点相同目录下 。
  3. 将集群配置文件 single.xml 从主节点分发到其余节点相同目录下。
  4. 执行 python3 ‘/opt/software/openGauss/script/local/PreInstallUtility.py’ -t check_config -u omm -X /home/omm/single.xml

# launch.json
"args": ["-t", "check_config", "-u", "omm", "-X", "/home/omm/single.xml"],

# 从 xml 文件中获取 '/app/opengauss/app/2.0.1' ,'/app/opengauss/tmp' , 检查各种组件 etcd,cm,dn等信息

创建​​omm​​​用户、​​dbgrp​​组,并建立互信

配置​​sshd​​服务

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t prepare_user_sshd_service -u omm -g dbgrp -X /home/omm/single.xml -l /app/opengauss/gaussdb_log/omm/om/gs_local.log

# args
"args": ["-t", "prepare_user_sshd_service", "-u", "omm", "-g", "dbgrp", "-X", "/home/omm/single.xml", "-l", "/app/opengauss/gaussdb_log/omm/om/gs_local.log"]
/etc/ssh/sshd_config
MaxStartups
grep -E '^[ ]*MaxStartups[ ]*1000$' /etc/ssh/sshd_config
grep -E '^[ ]*ClientAliveInterval[ ]*0$' /etc/ssh/sshd_config
cat /etc/ssh/sshd_config | grep '\\<AllowUsers\\>'
cat /etc/ssh/sshd_config | grep '\\<AllowGroups\\>'

检查环境变量

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t check_envfile -u omm -l /app/opengauss/gaussdb_log/omm/om/gs_local.log

source '/etc/profile'

更改目录权限

chown -R omm:dbgrp '/app/opengauss/tool'

​top file​​ 配置

(if [ -f '/etc/topDirPath.dat' ];then cat '/etc/topDirPath.dat' | awk -F = '{print $1}' | xargs chown -R -h omm:dbgrp; rm -rf '/etc/topDirPath.dat';fi)

更改主节点 /opt/software/openGauss 下文件权限

[root@pghost2 openGauss]# ll
total 201M
drwx------ 15 omm dbgrp 4.0K Mar 27 08:02 lib
drwxr-xr-x  9 omm dbgrp 4.0K Mar 31 22:22 libcgroup
-r--------  1 omm dbgrp  108 Jan 10 22:55 openGauss-3.0.3-openEuler-64bit-cm.sha256
-r--------  1 omm dbgrp 6.2M Jan 10 22:55 openGauss-3.0.3-openEuler-64bit-cm.tar.gz
-r--------  1 omm dbgrp   65 Jan 10 22:54 openGauss-3.0.3-openEuler-64bit-om.sha256
-r--------  1 omm dbgrp  11M Jan 10 22:54 openGauss-3.0.3-openEuler-64bit-om.tar.gz
-r--------  1 omm dbgrp   65 Jan 10 22:55 openGauss-3.0.3-openEuler-64bit.sha256
-r--------  1 omm dbgrp  84M Jan 10 22:55 openGauss-3.0.3-openEuler-64bit.tar.bz2
-rw-------  1 omm dbgrp 101M Apr  1 21:18 openGauss-Package-bak_46134f73.tar.gz
drwx------ 11 omm dbgrp 4.0K Mar 31 22:17 script
-r--------  1 omm dbgrp   65 Jan 10 22:53 upgrade_sql.sha256
-r--------  1 omm dbgrp 440K Jan 10 22:53 upgrade_sql.tar.gz
-rw-------  1 omm dbgrp   32 Jan 10 22:53 version.cfg

更改 ​​gauss log​​ 文件权限

/app/opengauss/gaussdb_log/omm
# 验证更改是否成功
su - omm -c 'cd '/app/opengauss/gaussdb_log/omm''
su - omm -c 'cd '/app/opengauss/gaussdb_log/omm/om''

​set tool env on all hosts​

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t set_tool_env -u omm -l /app/opengauss/gaussdb_log/omm/om/gs_local.log -X '/home/omm/single.xml' -Q /app/opengauss/tool

/bin/sed -i '/^\\s*export\\s*LD_LIBRARY_PATH=\\$GPHOME\\/script\\/gspylib\\/clib:\\$LD_LIBRARY_PATH$/d' /etc/profile
/bin/sed -i '/^\\s*export\\s*LD_LIBRARY_PATH=\\$GPHOME\\/lib:\\$LD_LIBRARY_PATH$/d' /etc/profile
/bin/sed -i '/^\\s*export\\s*PATH=\\$GPHOME\\/pssh-2.3.1\\/bin:\\$GPHOME\\/script:\\$PATH$/d' /etc/profile
/bin/sed -i '/^\\s*export\\s*PATH=\\$GPHOME\\/script\\/gspylib\\/pssh\\/bin:\\$GPHOME\\/script:\\$PATH$/d' /etc/profile
/bin/sed -i '/^\\s*export\\s*PATH=\\/root\\/gauss_om\\/omm\\/script:\\$PATH$/d' /etc/profile
/bin/sed -i '/^\\s*export\\s*PYTHONPATH=\\$GPHOME\\/lib/d' /etc/profile
# 在 /etc/profile 中加入如下内容
export GPHOME=/app/opengauss/tool
export PATH=$GPHOME/script/gspylib/pssh/bin:$GPHOME/script:$PATH
export LD_LIBRARY_PATH=$GPHOME/script/gspylib/clib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$GPHOME/lib:$LD_LIBRARY_PATH
export PYTHONPATH=$GPHOME/lib

​prepare cluster tool package path​

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t prepare_path -u omm -g dbgrp -P /app/opengauss/tool -l /app/opengauss/gaussdb_log/omm/om/gs_local.log

检查 ​​/etc/host​

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t check_hostname_mapping -u omm -X '/home/omm/single.xml' -l '/app/opengauss/gaussdb_log/omm/om/gs_local.log'

检查 ​​software​

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t check_os_software -u omm -l /app/opengauss/gaussdb_log/omm/om/gs_local.log

检查 ​​osversion​

创建目录

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t create_cluster_paths -u omm -g dbgrp -X '/home/omm/single.xml' -l '/app/opengauss/gaussdb_log/omm/om/gs_local.log'
# /app/opengauss/app /app/opengauss/tmp /app/ogdata/data/dn1

设置​​os​​参数

python3 '/opt/software/openGauss/script/gs_checkos' -h pghost2,pghost3 -i B -l '/app/opengauss/gaussdb_log/omm/om/gs_local.log' -X '/home/omm/single.xml'

配置 ​​CRON service​

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t prepare_user_cron_service -u omm -l /app/opengauss/gaussdb_log/omm/om/gs_local.log

设置环境变量

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t set_user_env -u omm  -l /app/opengauss/gaussdb_log/omm/om/gs_local.log

??? /home/omm/.bashrc 中加入如下内容
export GPHOME=/app/opengauss/tool
export PATH=$GPHOME/script/gspylib/pssh/bin:$GPHOME/script:$PATH
export LD_LIBRARY_PATH=$GPHOME/script/gspylib/clib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$GPHOME/lib:$LD_LIBRARY_PATH
export PYTHONPATH=$GPHOME/lib

设置 ​​set_library​

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t set_library -u omm -l /app/opengauss/gaussdb_log/omm/om/gs_local.log

设置 ​​core path​

ulimit -c unlimited; ulimit -c unlimited -S
echo 1 > /proc/sys/kernel/core_uses_pid && echo '/app/opengauss/corefile/core-%e-%p-%t' > /proc/sys/kernel/core_pattern && if [ ! -d '/app/opengauss/corefile' ]; then mkdir /app/opengauss/corefile -p -m 750;fi && chown omm:dbgrp /app/opengauss/corefile -R -h

设置 ​​pssh​

cp /opt/software/openGauss/script/impl/preinstall/OLAP/../../../gspylib/pssh/bin/pssh /opt/software/openGauss/script/impl/preinstall/OLAP/../../../gspylib/pssh/bin/pscp /opt/software/openGauss/script/impl/preinstall/OLAP/../../../gspylib/pssh/bin/TaskPool.py /usr/bin/ && chmod 755 /usr/bin/pssh && chmod 755 /usr/bin/pscp && chmod 755 /usr/bin/TaskPool.py

设置 ​​cgroup​

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t set_cgroup -u omm -X '/home/omm/single.xml' -l '/app/opengauss/gaussdb_log/omm/om/gs_local.log' -Q /app/opengauss/tool

​Set ARM Optimization​

python3 -c 'import platform;print(platform.machine())

​fix server package Owner​

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t fix_server_package_owner -u omm -g dbgrp -X /home/omm/single.xml -Q /app/opengauss/tool -l /app/opengauss/gaussdb_log/omm/om/gs_local.log

rm -f /opt/software/openGauss/script/gs_*

设置 ​​user cron​

设置成功标记

python3 '/opt/software/openGauss/script/local/PreInstallUtility.py' -t set_finish_flag -u omm -l '/app/opengauss/gaussdb_log/omm/om/gs_local.log' -X '/home/omm/single.xml' -Q /app/opengauss/tool





文章转载自公众号:openGauss

分类
标签
已于2023-9-4 11:56:22修改
收藏
回复
举报
回复
    相关推荐