2

opengauss脚本浅析(1)—— simpleinstall -m6米乐安卓版下载

原创 夏克 2022-05-23
2186

在编译完成opengauss或者已download了opengauss的bin后,想要做简易安装,官方给的使用方法是使用simpleinstall。本文主要介绍simpleinstall的脚本的功能,来了解一下简易安装内部实现原理。

postgres初始化数据库

了解opengauss安装之前简单说一下postgres的安装过程,postgres没有提供安装脚本,但是初始化数据库集簇的命令很简单:

initdb -d $pgdata

会在指定的pgdata目录下创建数据库,可以参考之前的一篇文章 。

opengauss脚本安装

image.png

opengauss简易安装是使用simpleinstall下面的install.sh脚本。

step1获取命令行参数(get_param)

先看一下需要那些参数

function usage() { echo " usage: sh $0 -w password arguments: -w login password -p datanode port, default 5432 --multinode if specify, will install master_slave cluster. default install single node. -h, --help show this help, then exit " }

主要有3个参数:

-w 设置超级用户的源码,这个是必选项,如不设置后续初始化流程无法完成,这也是和postgres的一个区别,postgres不强制要求超级用户密码。且使用-w(大写)设置密码,设置形式是交互的。-w(小写)是opengauss引入的新参数;

-p 设置服务端口,非必选,默认是5432;

–multinode 初始化数据库提供两种形式,及单节点和主备两种;

-w 和 -w的区别

image.png

两个参数的功能是一样的,但是-w是postgres保留的功能,是交互是的,需要手动数据密码;-w 是自动的方式将密码通过命令行传入程序,我猜opengauss是为了兼容原有的用法,所以新加了-w的参数,且出于安全性考虑,是必须设置的。

step2 检查参数(check_param)

主要检查一下几项:

  1. -w参数必须填写,且不能为空
  2. 密码必须大于8个字符
  3. 不能使用root用户安装
  4. 如不设置-p,怎使用默认端口5432,否则使用-p的设置
  5. 如果设置了–multinode,则备节点的端口为主节点端口 200

step3 检查安装环境(check_install_env)

  1. 检查目录是否存在,如果是单节点模式,检查data下是否存在single_node目录,是否为空目录,如果是主备检查 master 和 slave是否存在,是否为空;
  2. 检查端口是否被占用;
  3. 检查unix sock是否有权限,是否被占用

step4 检查操作系统参数(check_os)

  1. 检查系统共享内存和页大小

image.png

  1. x86下还要检查rdtscp,应该是和指令顺序有关

这块有留个坑吧,不是很了解,后续有机会在填上。

step5 修改应用目录的属组和权限(change_gausshome_owner)

  1. 修改属组:chown omm:dbgrp $app
  2. 修改权限:chmod 700 $app

step6 设置omm用户的环境变量

设置的环境变量包括:path、gausshome、ld_library_path、gs_cluster_name、ulimit -n 1000000

image.png

上图是omm用户的.bashrc的内容

step7-1 初始化数据库(single_install)

  1. 初始化数据库集簇,参考 基本流程没有太大区别;

第二个坑,后续会对比一下initdb过程postgres和opengauss的有哪些差别。

gs_initdb -w $password -d $app/data/single_node --nodename "sgnode" --locale="en_us.utf-8"
  1. 修改配置文件postgres.conf中的端口
sed -i "/^#port =/c\port = $port" $app/data/single_node/postgresql.conf
  1. 启动数据库
gs_ctl start -d $app/data/single_node -z single_node

step7-2 初始化数据库(master_standby_install)

init_db

function init_db() { info "[init primary datanode.]" gs_initdb -d $app/data/master --nodename=datanode1 -e utf-8 --locale=en_us.utf-8 -u $user -w $password info "[init slave datanode.]" gs_initdb -d $app/data/slave --nodename=datanode2 -e utf-8 --locale=en_us.utf-8 -u $user -w $password }

分别对主备两个库进行初始化。

config_db

function config_db() { info "[config datanode.]" local -a ip_arr local -i index=0 for line in $(/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:") do ip_arr[index]=$line let index=$index 1 done sed -i "/^#listen_addresses/c\listen_addresses = 'localhost,${ip_arr[0]}'" $app/data/master/postgresql.conf sed -i "/^#listen_addresses/c\listen_addresses = 'localhost,${ip_arr[0]}'" $app/data/slave/postgresql.conf sed -i "/^#port/c\port = $port" $app/data/master/postgresql.conf sed -i "/^#port/c\port = $slave_port" $app/data/slave/postgresql.conf sed -i "/^#replconninfo1/c\replconninfo1 = 'localhost=${ip_arr[0]} localport=$(($port 1)) localheartbeatport=$(($port 5)) localservice=$(($port 4)) remotehost=${ip_arr[0]} remoteport=$(($slave_port 1)) remoteheartbeatport=$(($slave_port 5)) remoteservice=$(($slave_port 4))'" $app/data/master/postgresql.conf sed -i "/^#replconninfo1/c\replconninfo1 = 'localhost=${ip_arr[0]} localport=$(($slave_port 1)) localheartbeatport=$(($slave_port 5)) localservice=$(($slave_port 4)) remotehost=${ip_arr[0]} remoteport=$(($port 1)) remoteheartbeatport=$(($port 5)) remoteservice=$(($port 4))'" $app/data/slave/postgresql.conf echo "remote_read_mode = non_authentication" | tee -a $app/data/master/postgresql.conf $app/data/slave/postgresql.conf echo "host all all ${ip_arr[0]}/32 trust" | tee -a $app/data/master/pg_hba.conf $app/data/slave/pg_hba.conf }

主要修改主备的服务提供端口、主备通信端口 和 客户端登录权限等,涉及配置文件postgres.conf和pg_hba.conf。

start_db

-b, --mode=mode the mode of building the datanode or coordinator.mode can be "full", "incremental", "auto", "standby_full", "copy_secure_files", "copy_upgrade_file", "cross_cluster_full", "cross_cluster_incremental", "cross_cluster_standby_full" -m the database start as the appointed mode -d, --pgdata=datadir location of the database storage area

step8 导入范例sql(import_sql)

read -p "would you like to create a demo database (yes/no)? " input

接收输入,是否要建立范例数据库

导入两个sql文件中的内容

function fn_load_demodb() { cd $shell_path gsql -d postgres -p $port -f school.sql gsql -d postgres -p $port -f finance.sql }

以上步骤执行成功后,即完成了数据库集簇的初始化和启动过程。如果大家在启动本地安装过程中遇到问题,可以对照以上步骤进行排查。

[omm@host-10-208-88-234 simpleinstall]$ sh install.sh -w xk.xmx190035 [step 1]: check parameter [step 2]: check install env and os setting [step 3]: change_gausshome_owner [step 4]: set environment variables /home/omm/.bashrc: line 13: ulimit: open files: cannot modify limit: operation not permitted [step 6]: init datanode the files belonging to this database system will be owned by user "omm". this user must also own the server process. the database cluster will be initialized with locale "en_us.utf-8". the default database encoding has accordingly been set to "utf8". the default text search configuration will be set to "english". creating directory /home/omm/git/opengauss-server/data/single_node ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 32mb creating configuration files ... ok begin init undo subsystem meta. [init undo] init undo subsystem meta successfully. creating template1 database in /home/omm/git/opengauss-server/data/single_node/base/1 ... the core dump path is an invalid directory 2022-05-23 12:30:32.064 [unknown] [unknown] localhost 281459036192784 0[0:0#0] [backend] warning: macaddr is 64022/1056020634, sysidentifier is 4195761905/2560264540, randomnum is 246122844 ok initializing pg_authid ... ok setting password ... ok initializing dependencies ... ok loading pl/pgsql server-side language ... ok creating system views ... ok creating performance views ... ok loading system objects' descriptions ... ok creating collations ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok initialize global configure for bucketmap length ... ok creating information schema ... ok loading foreign-data wrapper for distfs access ... ok loading foreign-data wrapper for hdfs access ... ok loading foreign-data wrapper for log access ... ok loading hstore extension ... ok loading foreign-data wrapper for mot access ... ok loading security plugin ... ok update system tables ... ok creating snapshots catalog ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok freezing database template0 ... ok freezing database template1 ... ok freezing database postgres ... ok warning: enabling "trust" authentication for local connections you can change this by editing pg_hba.conf or using the option -a, or --auth-local and --auth-host, the next time you run gs_initdb. success. you can now start the database server of single node using: gaussdb -d /home/omm/git/opengauss-server/data/single_node --single_node or gs_ctl start -d /home/omm/git/opengauss-server/data/single_node -z single_node -l logfile [step 7]: start datanode [2022-05-23 12:30:51.410][991625][][gs_ctl]: gs_ctl started,datadir is /home/omm/git/opengauss-server/data/single_node [2022-05-23 12:30:51.446][991625][][gs_ctl]: waiting for server to start... .0 log: [alarm module]can not read gauss_warning_type env. 0 log: [alarm module]host name: host-10-208-88-234 0 log: [alarm module]host ip: 10.208.88.234 0 log: [alarm module]cluster name: dbcluster 0 log: [alarm module]get real path of alarmitem.conf failed! 0 warning: failed to open feature control file, please check whether it exists: filename=gaussdb.version, errno=2, errmessage=no such file or directory. 0 warning: failed to parse feature control file: gaussdb.version. 0 warning: failed to load the product control file, so gaussdb cannot distinguish product version. the core dump path is an invalid directory 2022-05-23 12:30:51.581 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: when starting as multi_standby mode, we couldn't support data replicaton. gaussdb.state does not exist, and skipt setting since it is optional.2022-05-23 12:30:51.587 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: [alarm module]can not read gauss_warning_type env. 2022-05-23 12:30:51.587 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: [alarm module]host name: host-10-208-88-234 2022-05-23 12:30:51.636 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: [alarm module]host ip: 10.208.88.234 2022-05-23 12:30:51.636 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: [alarm module]cluster name: dbcluster 2022-05-23 12:30:51.636 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: [alarm module]get real path of alarmitem.conf failed! 2022-05-23 12:30:51.641 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: loaded library "security_plugin" 2022-05-23 12:30:51.642 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] warning: could not create any ha tcp/ip sockets 2022-05-23 12:30:51.642 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] warning: could not create any ha tcp/ip sockets 2022-05-23 12:30:51.645 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] warning: no explicit ip is configured for listen_addresses guc. 2022-05-23 12:30:51.645 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: initnuma numanodenum: 1 numa_distribute_mode: none inheritthreadpool: 0. 2022-05-23 12:30:51.645 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: reserved memory for backend threads is: 220 mb 2022-05-23 12:30:51.645 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: reserved memory for wal buffers is: 128 mb 2022-05-23 12:30:51.645 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: set max backend reserve memory is: 348 mb, max dynamic memory is: 11027 mb 2022-05-23 12:30:51.645 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: shared memory 400 mbytes, memory context 11375 mbytes, max process memory 12288 mbytes 2022-05-23 12:30:51.681 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [cache] log: set data cache size(402653184) 2022-05-23 12:30:51.726 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [cache] log: set metadata cache size(134217728) 2022-05-23 12:30:51.741 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [segment_page] log: segment-page constants: df_map_size: 8156, df_map_bit_cnt: 65248, df_map_group_extents: 4175872, ipblock_size: 8168, extents_per_ipblock: 1021, ipblock_group_size: 4090, bmt_header_level0_total_pages: 8323072, bktmapentrynumberperblock: 2038, bktmapblocknumber: 25, bktbitmaxmapcnt: 512 2022-05-23 12:30:51.755 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: gaussdb: fsync file "/home/omm/git/opengauss-server/data/single_node/gaussdb.state.temp" success 2022-05-23 12:30:51.755 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: create gaussdb state file success: db state(starting_state), server mode(normal), connection index(1) 2022-05-23 12:30:51.834 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: max_safe_fds = 976, usable_fds = 1000, already_open = 14 the core dump path is an invalid directory 2022-05-23 12:30:51.839 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: user configure file is not found, it will be created. 2022-05-23 12:30:51.842 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: the configure file /home/omm/git/opengauss-server/etc/gscgroup_omm.cfg doesn't exist or the size of configure file has changed. please create it by root user! 2022-05-23 12:30:51.842 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [backend] log: failed to parse cgroup config file. 2022-05-23 12:30:51.862 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [executor] warning: failed to obtain environment value $gausslog! 2022-05-23 12:30:51.862 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [executor] detail: n/a 2022-05-23 12:30:51.862 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [executor] cause: incorrect environment value. 2022-05-23 12:30:51.862 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [executor] action: please refer to backend log for more details. 2022-05-23 12:30:51.863 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [executor] warning: failed to obtain environment value $gausslog! 2022-05-23 12:30:51.863 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [executor] detail: n/a 2022-05-23 12:30:51.863 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [executor] cause: incorrect environment value. 2022-05-23 12:30:51.863 [unknown] [unknown] localhost 281460165246992 0[0:0#0] 0 [executor] action: please refer to backend log for more details. [2022-05-23 12:30:52.460][991625][][gs_ctl]: done [2022-05-23 12:30:52.460][991625][][gs_ctl]: server started (/home/omm/git/opengauss-server/data/single_node) import sql file would you like to create a demo database (yes/no)? yes load demodb [school,finance] success. [complete successfully]: you can start or stop the database server using: gs_ctl start|stop|restart -d $gausshome/data/single_node -z single_node

上面留下两个坑,待后续填上。

没填上的坑 挖坑的时间
x86下的rdtscp 2022-05-23
initdb过程postgres和opengauss的有哪些差别 2022-05-23
最后修改时间:2022-05-23 14:27:50
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
1人已赞赏
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论

网站地图