如何将HGDB安全版(RPM包形式)安装在非root用户下

环境

系统平台:中标麒麟(海光)7
版本:4.3.4.6

文档用途

本文以自建系统用户highgo为例,介绍如何将HGDB安装于非root用户下。

详细信息

1、创建highgo用户及用户组

[root@localhost opt]# groupadd -g 5866 highgo                        
[root@localhost opt]# useradd -u 5866 -g highgo highgo            
[root@localhost opt]# passwd highgo                                          
Changing password for user highgo.

2、在root用户下安装HGDB

[root@localhost opt]# rpm -ivh hgdb4.3.4.6-see-nkyl7-hygon-64-20190808.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:highgodb-4.3.4.6-1.el7           ################################# [100%]
2020-02-12 11:13:21.174 CST [39010] LOG:  data encryption performed by pgcrypto
Note: Forwarding request to 'systemctl enable hgdb-se4.3.4.6.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/hgdb-se4.3.4.6.service to /usr/lib/systemd/system/hgdb-se4.3.4.6.service.
Created symlink from /etc/systemd/system/graphical.target.wants/hgdb-se4.3.4.6.service to /usr/lib/systemd/system/hgdb-se4.3.4.6.service.
[root@localhost opt]#

3、关闭数据库服务,修改数据库目录属主

[root@localhost opt]# source ~/.bash_profile
[root@localhost opt]# pg_ctl stop -D /opt/HighGoDB-4.3.4.6/data
waiting for server to shut down.... done
server stopped
[root@localhost opt]# ll
total 172432
-rw-r--r--.  1 root root 176566496 Feb 12 11:09 hgdb4.3.4.6-see-nkyl7-hygon-64-20190808.rpm
drwxr-xr-x. 10 root root       108 Feb 12 11:13 HighGoDB-4.3.4.6
drwxr-xr-x.  2 root root         6 Aug  4  2017 rh
[root@localhost opt]# chown -R highgo:highgo HighGoDB-4.3.4.6/
[root@localhost opt]# ll
total 172432
-rw-r--r--.  1 root   root   176566496 Feb 12 11:09 hgdb4.3.4.6-see-nkyl7-hygon-64-20190808.rpm
drwxr-xr-x. 10 highgo highgo       108 Feb 12 11:13 HighGoDB-4.3.4.6
drwxr-xr-x.  2 root   root           6 Aug  4  2017 rh
[root@localhost opt]#

4、修改highgo用户下的环境变量配置文件

[root@localhost opt]# su - highgo
[highgo@localhost ~]$ vi .bashrc

增加以下内容:

export PATH
export LD_LIBRARY_PATH=/opt/HighGoDB-4.3.4.6/lib:$LD_LIBRARY_PATH
export PATH=$PATH:/opt/HighGoDB-4.3.4.6/bin
export PGHOME=/opt/HighGoDB-4.3.4.6/
export   PGUSER=highgo
export   PGPORT=5866
export PGDATA=$PGHOME/data
export   PATH=$PGHOME/bin:$PATH:$HOME/bin
export   LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH

5、使配置文件生效,在highgo用户下启动数据库

[highgo@localhost ~]$ source .bashrc
[highgo@localhost ~]$ pg_ctl start
waiting for server to start....2020-02-12 11:31:22.697 CST [39141] LOG:  data encryption performed by pgcrypto
2020-02-12 11:31:22.714 CST [39141] LOG:  listening on IPv6 address "::1", port 5866
2020-02-12 11:31:22.714 CST [39141] LOG:  listening on IPv4 address "127.0.0.1", port 5866
2020-02-12 11:31:22.724 CST [39141] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5866"
2020-02-12 11:31:22.818 CST [39141] LOG:  This is a trial edition, validate until 2020-03-13 11:13:18, database will not be able to start up after that time,please apply an official license by that time.
2020-02-12 11:31:22.820 CST [39141] LOG:  redirecting log output to logging collector process
2020-02-12 11:31:22.820 CST [39141] HINT:  Future log output will appear in directory "log".
 done
server started
[highgo@localhost ~]$

6、数据库自启动

数据库在安装后已经开启开机自启服务,由于数据库启动用户已经改变,需要对自启动服务文件进行修改,必须在root用户下修改。

[root@localhost ~]$ vi /usr/lib/systemd/system/hgdb-se4.3.4.6.service
[Unit]
Description=hgdb-se4.3.4.6
After=syslog.target
After=network.target
[Service]
Type=forking
User=highgo
OOMScoreAdjust=-1000
ExecStart=/opt/HighGoDB-4.3.4.6/bin/pg_ctl start -D /opt/HighGoDB-4.3.4.6/data
ExecStop=/opt/HighGoDB-4.3.4.6/etc/hgdb-se4.3.4.6 stop
ExecReload=/opt/HighGoDB-4.3.4.6/etc/hgdb-se4.3.4.6 reload
TimeoutSec=300
[Install]
WantedBy=multi-user.target graphical.target

7、状态检测

保存后重启系统,查看系统后台进程,可以看到highgo用户下已经有数据源库进程,服务启动正常

[root@localhost ~]# reboot

[root@localhost ~]# ps -ef|grep postgres
highgo     1182      1  1 11:39 ?        00:00:00 /opt/HighGoDB-4.3.4.6/bin/postgres -D /opt/HighGoDB-4.3.4.6/data
highgo     1231   1182  0 11:39 ?        00:00:00 postgres: logger process  
highgo     1238   1182  0 11:39 ?        00:00:00 postgres: checkpointer process  
highgo     1240   1182  0 11:39 ?        00:00:00 postgres: writer process  
highgo     1241   1182  0 11:39 ?        00:00:00 postgres: wal writer process  
highgo     1242   1182  0 11:39 ?        00:00:00 postgres: autovacuum launcher process  
highgo     1244   1182  0 11:39 ?        00:00:00 postgres: stats collector process  
highgo     1246   1182  0 11:39 ?        00:00:00 postgres: bgworker: logical replication launcher  
root       1679   1627  0 11:40 pts/0    00:00:00 grep --color=auto postgres
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值