DevOps工具链(一)——如何访问gitlab默认使用的postgresql

本文介绍了如何查看GitLab的数据库配置文件database.yml,并通过命令行工具cat展示其内容。此外,还展示了如何通过查看passwd文件来了解GitLab中创建的用户情况,包括git、gitlab-psql等用户。最后,提供了登录这些用户的详细步骤及如何连接到GitLab的生产数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 查看配置文件

cat /var/opt/gitlab/gitlab-rails/etc/database.yml

# This file is managed by gitlab-ctl. Manual changes will be
# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
# and run `sudo gitlab-ctl reconfigure`.

production:
  adapter: postgresql
  encoding: unicode
  collation: 
  database: gitlabhq_production
  pool: 10
  username: "gitlab"
  password: 
  host: "/var/opt/gitlab/postgresql"
  port: 5432
  socket: 
  sslmode: 
  sslrootcert: 
  sslca: 
  load_balancing: {"hosts":[]}
  prepared_statements: false
  statements_limit: 1000
  fdw: 

2. 查看用户

cat /etc/passwd
git:x:995:992::/var/opt/gitlab:/bin/sh
gitlab-psql:x:993:990::/var/opt/gitlab/postgresql:/bin/sh
gitlab-prometheus:x:992:989::/var/opt/gitlab/prometheus:/bin/sh

3. 登录

su - gitlab-psql  //登录用户
Last login: Sun Apr  8 21:57:52 CST 2018 on pts/0
-sh-4.2$ 

//之后输入
-sh-4.2$ psql -h /var/opt/gitlab/postgresql -d gitlabhq_production   //连接到gitlabhq_production库

psql (9.6.8)
Type "help" for help.

gitlabhq_production=# //这时可以输入postgresql的命令了

gitlabhq_production=# \l    //列出数据库
                                             List of databases
        Name         |    Owner    | Encoding |   Collate   |    Ctype    |        Access privileges        
---------------------+-------------+----------+-------------+-------------+---------------------------------
 gitlabhq_production | gitlab      | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres            | gitlab-psql | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0           | gitlab-psql | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/"gitlab-psql"               +
                     |             |          |             |             | "gitlab-psql"=CTc/"gitlab-psql"
 template1           | gitlab-psql | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/"gitlab-psql"               +
                     |             |          |             |             | "gitlab-psql"=CTc/"gitlab-psql"
(4 rows)

4. 登录其他用户

同理,可以使用 su - 用户名 的方式登录安装一些软件时自动创建的用户,如git用户,或jenkins用户

[root@localhost .ssh]# su - git
Last login: Sun Apr  8 22:00:25 CST 2018 on pts/0
-sh-4.2$   //现在就是以git用户的身份运行的,可以查看属于git用户和组的目录和文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值