将gitlab中的postgresql数据库开通远程访问

postgresql数据库是gitlab的一个配置数据库,记录gitlab的一些配置信息。

我们访问gitlab中的postgresql数据有本地命令行访问和远程可视化软件访问2种方式。

(一)本地命令访问postgresql

参考:https://www.cnblogs.com/sfnz/p/7131287.html?utm_source=itdadao&utm_medium=referral

su - gitlab-psql //登陆用户


psql -h /var/opt/gitlab/postgresql -d gitlabhq_production //连接到gitlabhq_production库


\l //查看数据库


\dt //查看多表


\d users //查看单表,如users表


SELECT name,username,otp_required_for_login,two_factor_grace_period, require_two_factor_authentication_from_group FROM users;
//查看users表中用户的关键信息,取4个字段


退出psql使用\q,接着按下回车就行了。

(二)远程可视化软件访问【此方法并不推荐,因为访问gitlab中的postgresql数据库并不需要密码,存在风险。工作时,请用完就把相关配置文件复原,阻断远程访问】【非常重要!!!!】

使用Navicat访问postgresql数据库,就可以图形界面操作了。

但是,在连接之前需要到postgresql数据库所在Linux系统中去配置一下,使其提供远程访问的服务。

1、修改gitlab.rb

vim /etc/gitlab/gitlab.rb

配置为:

postgresql['enable'] = true
postgresql['listen_address'] = '0.0.0.0'
postgresql['port'] = 5432
postgresql['data_dir'] = "/var/opt/gitlab/postgresql/data"

2、使得gitlab.rb的修改生效

gitlab-ctl  reconfigure 

等待报错。没办法,上述修改,必然引发报错。

3、修改pg_hba.conf

vim   /var/opt/gitlab/postgresql/data/pg_hba.conf

修改为:

host   all    all    0.0.0.0/0    trust

注意:从此,不能再执行gitlab-ctl  reconfigure 命令了,因为如果再执行gitlab-ctl  reconfigure ,那么pg_hba.conf的修改就会被还原。

4、使得pg_hba.conf生效

生效前,先查看端口5432

netstat -antp |grep :5432

发现端口5432还没有启动

执行restart,使得配置生效(端口5432生效)。

gitlab-ctl   restart

注意:从此,不能再执行gitlab-ctl  reconfigure 命令了,因为如果在执行,pg_hba.conf的修改就会被还原。

 

再查看端口,发现5432存在了。

netstat -antp |grep :5432

5、访问前telnet测试和端口5432的连通性

telnet  gitlab所在机器的ip地址   5432

如果不报错,就算连通了。

6、Navicat连接postgresql数据库

 连接测试

 【此方法并不推荐,因为访问gitlab中的postgresql数据库并不需要密码,存在风险。工作时,请用完就把相关配置文件复原,阻断远程访问】【非常重要!!!!】

猜你喜欢

转载自www.cnblogs.com/andy9468/p/10609682.html