0-瀚高企业版 6.0.4 安装(CentOS7)

系统版本:CentOS7

1、下载地址

请注意:HGDB V5 linux 平台不支持安装 hgdbAdmin 组件。请在 windows 系统安装单独的 hgdbAdmin 工具对数据库进行图形化管理。

2、上传目录

把下载的 1b73693f2c91fd7f38acbc7d3882cf6c.rpm 上传到 centos 的 opt 目录

瀚高数据库的目录使用了自定义的 /opt 目录。**/opt目录是 unix 系统一直推荐使用的应用安装目录。**

3、安装

1
2
3
4
5
6
7
[root@localhost opt]# rpm -ivh 1b73693f2c91fd7f38acbc7d3882cf6c.rpm 
Preparing... ################################# [100%]
Updating / installing...
1:hgdb-enterprise-6.0.4-1.el7.cento################################# [100%]
无遗留数据文件
Created symlink from /etc/systemd/system/multi-user.target.wants/hgdb-enterprise-6.0.4.service to /usr/lib/systemd/system/hgdb-enterprise-6.0.4.service.
Created symlink from /etc/systemd/system/graphical.target.wants/hgdb-enterprise-6.0.4.service to /usr/lib/systemd/system/hgdb-enterprise-6.0.4.service.

以上安装成功后,自动完成以下操作:

  1. 自动创建 highgo 用户,该用户默认没有密码。安装文件的属主均为 highgo 。
  2. 自动创建默认路径,并生成环境配置文件(包括默认服务端口号5866):
    • 默认路径:/opt/HighGo6.0.4-cluster
    • 环境配置文件:/opt/HighGo6.0.4-cluster/etc/highgodb.env,其内容如下:
      1
      2
      3
      4
      5
      6
      export HG_BASE=/opt/HighGo6.0.4-cluster
      export HGDB_HOME=/opt/HighGo6.0.4-cluster
      export PGPORT=5866
      export PGDATABASE=highgo
      export PGDATA=$HGDB_HOME/data
      export PATH=$HGDB_HOME/bin:$PATH
  3. 生成service文件:/usr/lib/systemd/system/hgdb-enterprise-6.0.4.service

服务设置,也可以不设置。

1
2
[root@localhost opt]# systemctl enable hgdb-enterprise-6.0.4    # 设置开机启动
[root@localhost opt]# systemctl restart hgdb-enterprise-6.0.4 # 重启服务

4、设置环境变量

添加 环境变量 到 /root/.bash_profile。内容如下

1
2
3
4
5
6
7
8
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/opt/HighGo6.0.4-cluster/bin
export HG_BASE=/opt/HighGo6.0.4-cluster
export HGDB_HOME=/opt/HighGo6.0.4-cluster
export PGPORT=5866
export PGDATABASE=highgo
export PGDATA=$HGDB_HOME/data
export LD_LIBRARY_PATH=/usr/lib64:/opt/HighGo6.0.4-cluster/lib:$LD_LIBRARY_PATH
export PATH

使其生效:source /home/.bash_profile

5、初始化数据库

初始化数据库需要使用非 root 用户,否则会报错:

1
2
3
4
[root@localhost package]# initdb 
initdb: error: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.

切换到 highgo 用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[highgo@localhost opt]$ initdb 
could not change directory to "/opt": Permission denied
The files belonging to this database system will be owned by user "highgo".
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".

Data page checksums are disabled.
Data encryption is disabled.

Enter new superuser password: # 输入复杂的密码完成(密码需要是大写小写数字和符号的组合。。。。。如密码aaa123@)
Enter it again:

fixing permissions on existing directory /opt/HighGo6.0.4-cluster/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... America/Los_Angeles
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "md5" 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 initdb.

Success. You can now start the database server using:

pg_ctl -D /opt/HighGo6.0.4-cluster/data -l logfile start

6、启动

  • 启动(使用 highgo 用户):pg_ctl -D /opt/HighGo6.0.2-cluster/data start

  • 查看数据库装填 pg_ctl status

  • 登录数据库进行编辑:psql -U highgo -d postgres

    提示:psql: error: could not connect to server: FATAL: database "postgres" does not exist

    然后新加一个database(这条命令将以用户 “highgo” 创建一个新的 “postgres” 数据库。如果你无法连接到任何数据库,你可能需要首先以 “template1” 连接)
    /opt/HighGo6.0.2-cluster/bin/psql -U highgo -d template1 -c "CREATE DATABASE postgres;"
    重新进入

7、配置访问

如果想让用户能远程访问,需要修改两个地方:

编辑 /opt/HighGo6.0.4-cluster/data/postgresql.conf 文件

1
2
3
4
5
6
7
8
[highgo@localhost /]$ vi /opt/HighGo6.0.4-cluster/data/postgresql.conf

# 找到下面位置:Connection Settings
# - Connection Settings -

listen_addresses = '*' # what IP address(es) to listen on; # 新增这行,修改能够访问该数据库的外部ip地址以及访问控制权限
#listen_addresses = 'localhost' # what IP address(es) to listen on;
# comma-separated list of addresses;

编辑 /opt/HighGo6.0.4-cluster/data/pg_hba.conf 文件

1
2
3
4
# 在IPV4的 local connections 添加一行
\# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5 # 添加这行

编辑完之后重启

1
[highgo@localhost /]$ pg_ctl restart

0-瀚高企业版 6.0.4 安装(CentOS7)
https://flepeng.github.io/041-国产-HGDB-瀚高数据库-11-安装和配置-0-瀚高企业版-6-0-4-安装(CentOS7)/
作者
Lepeng
发布于
2024年3月8日
许可协议