问题描述
我正在尝试从其他应用访问gitlab omnibus的postgres安装,以便可以在其中共享数据。如何找到登录信息,例如用户名/密码?
解决方法
应该没有密码。
如果您在安装了GitLab Omnibus的计算机上具有sudo
访问权限,则可以使用以下方法确认这一点:
sudo grep gitlab-psql /etc/shadow
,它应该在密码字段中显示“ !
”,例如:
gitlab-psql:!!:16960::::::
面对一个类似的目标(访问GitLab的数据库以便得出一些使用情况,随着时间的推移打开/关闭的问题计数等),这就是我所做的(假设具有sudo
能力):>
sudo su -l gitlab-psql
mkdir -p ~/.ssh
chmod 0700 ~/.ssh
cat >> ~/.ssh/authorized_keys << "EOF"
<your ssh public key here>
EOF
chmod 0600 ~/.ssh/authorized_keys
完成此操作后,首先请检查您是否可以ssh
以gitlab-psql
的身份使用该密钥,当然是从远程主机ssh gitlab-psql@my-gitlab-host
或本地:ssh gitlab-psql@localhost
。
此后,您应该能够通过ssh
从其他应用程序访问数据库。例如,这是一种直接从Python笔记本(在EC2中其他主机上运行)并使用Pandas查询数据库的方法:
def gitlab_query(query):
cmdargs = [
'ssh','gitlab-psql@my-gitlab-host',f"""/opt/gitlab/embedded/bin/psql -h /var/opt/gitlab/postgresql/ gitlabhq_production -A -F $'\t' -c "{query}" """,]
proc = subprocess.Popen(cmdargs,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
try:
outs,errs = proc.communicate(timeout=15)
except subprocess.TimeoutExpired:
proc.kill()
outs,errs = proc.communicate()
errors = errs.decode('utf-8')
if errors:
raise ValueError(errors)
result = outs.decode('utf-8')
result = result[:result.rfind('\n',-1)]
return result
# simple example
# NOTE: as is,this is incomplete,because many issues are closed by other
# actions (e.g. commits or merges) and in those cases,there is no
# closed_at date. See further below for better queries. (not included in
# this SO answer as this is getting beyond the scope of the question).
q = """
select
b.name,a.title,a.created_at,a.closed_at
from issues a inner join projects b on (a.project_id = b.id)
where closed_at > '2018-01-09' and b.name='myproject'
order by 1,4 limit 10
"""
pd.read_csv(io.StringIO(gitlab_query(q)),sep='\t',parse_dates=['created_at','closed_at'])
,
如果您已按照 here 所述安装了 gitlab-praefect 节点,并且您使用的是 AWS EC2 和 AWS postgres,并且想要检查这两者是否可以通信。
/opt/gitlab/embedded/bin/psql -U YourExistingUsername -d template1 -h RDS-POSTGRES-ENDPOINT