【服务器】使用Gitlab搭建私有git服务器
AI摘要:
本文指导用户如何在 CentOS 7 上安装 GitLab,包括从清华大学开源软件镜像站下载指定版本的 GitLab,通过 rpm 命令安装,配置 external_url 为本地地址 http://127.0.0.1:9090,以及执行初始配置。完成安装后,管理员账户为 root,初始密码位于 /etc/gitlab/initial_root_password 文件中,该密码在初次配置24小时后自动删除。安装后,用户还可以修改界面语言以优化使用体验。文章还提到了使用 frp 和反向代理来实现外网访问的方法。
安装必要依赖
略
安装Gitlab
- 前往镜像仓库选择合适版本,通过wget下载到服务器:
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.9.3-ce.0.el7.x86_64.rpm
安装
rpm -Uvh gitlab-ce-16.9.3-ce.0.el7.x86_64.rpm
安装结束显示:It looks like GitLab has not been configured yet; skipping the upgrade script. *. *. *** *** ***** ***** .****** ******* ******** ******** ,,,,,,,,,***********,,,,,,,,, ,,,,,,,,,,,*********,,,,,,,,,,, .,,,,,,,,,,,*******,,,,,,,,,,,, ,,,,,,,,,*****,,,,,,,,,. ,,,,,,,****,,,,,, .,,,***,,,, ,*,. _______ __ __ __ / ____(_) /_/ / ____ _/ /_ / / __/ / __/ / / __ `/ __ \ / /_/ / / /_/ /___/ /_/ / /_/ / \____/_/\__/_____/\__,_/_.___/ Thank you for installing GitLab! GitLab was unable to detect a valid hostname for your instance. Please configure a URL for your GitLab instance by setting `external_url` configuration in /etc/gitlab/gitlab.rb file. Then, you can start your GitLab instance by running the following command: sudo gitlab-ctl reconfigure For a comprehensive list of configuration options please see the Omnibus GitLab readme https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md Help us improve the installation experience, let us know how we did with a 1 minute survey: https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=16-9
- 编辑配置文件:
vi /etc/gitlab/gitlab.rb
,修改external_url
为对应路径,这里设置http://127.0.0.1:9090
sudo gitlab-ctl reconfigure
执行设置,大约需要三分钟- 管理员用户名为root,密码存储在
/etc/gitlab/initial_root_password
,初次配置24小时后自动删除 - 登录后可在preferences中修改语言,保存后刷新即可生效
- 使用frp+反向代理实现外网访问,反向代理设置配置文件设置端口对应frp穿透端口即可
添加用户并设置ssh key
- 在管理中心可添加用户并设置密码
- 打开终端,生成ssh密钥:`ssh-keygen -t rsa -b 4096 -C "email@example.com"
`
参数含义:
-t 指定密钥类型,默认使用rsa,可以不写
-C 表示comment,设置注释文字
-b 指定密钥长度。对于RSA密钥,最小要求768位,默认是2048位。DSA密钥必须恰好是1024位(FIPS 186-2 标准的要求)。
-f 指定密钥文件存储文件名。
以上代码省略了 -f 参数,因此,运行上面那条命令后会让你输入一个文件名,用于保存刚才生成的 SSH key 代码
如果不输入文件名,直接按回车,则使用默认文件路径存放ssh key,之后就会生成 id_rsa 和 id_rsa.pub 两个秘钥文件。
接着又会提示你输入两次密码(该密码是你访问gitlab的时候要输入的密码,不是gitlab的密码),当然,你也可以不输入密码,直接按回车。那么在访问gitlab的时候就不需要输入密码.
- 登录用户后,在编辑个人资料中进入ssh密钥设置,复制 id_rsa.pub 文件的内容,填入密钥,可选密钥有效时间。
添加本地项目
- 创建空白项目,取消选择使用自述文件初始化仓库
打开已有项目,按照以下指引推送:
推送现有文件夹 cd existing_folder git remote add origin https://example.com/user/example.git git branch -M main git push -uf origin main
- 后续推送:
git push
本站所有原创文章版权所有,禁止转载,欢迎转发文章链接,参考请标明出处并连接到本站相应页面。所有注明的转载内容版权归原作者所有,如不慎侵权请原作者联系本站删除。