前言
环境:centos7.9 前面介绍了公网上的远程仓库GitHub,这次我们来介绍内网远程仓库gitlab,gitlab比较合适内网环境的企业,同时也可以提高安全性,毕竟GitHub是外网,gitlab是内网。本篇我们就俩介绍gitlab。
什么是gitlab
GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的Web服务。
安装gitlab软件,搭建gitlab服务器
gitlab软件的rpm包可以在清华的镜像源中找到,如:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.7.0-ce.0.el7.x86_64.rpm,下载对应的版即可,这里我下载gitlab-ce社区版,centos7版本。
[root@gitlab ~]
warning: gitlab-ce-14.7.0-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing...
Updating / installing...
1:gitlab-ce-14.7.0-ce.0.el7
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=14-7
[root@gitlab ~]
[root@gitlab ~]
external_url 'http://192.168.118.130'
[root@gitlab ~]
查看gitlab状态
[root@gitlab conf]
run: alertmanager: (pid 5135) 354s; run: log: (pid 4811) 426s
run: gitaly: (pid 5159) 354s; run: log: (pid 4263) 539s
run: gitlab-exporter: (pid 5097) 357s; run: log: (pid 4713) 444s
run: gitlab-workhorse: (pid 5074) 359s; run: log: (pid 4630) 462s
run: grafana: (pid 5168) 354s; run: log: (pid 5020) 379s
run: logrotate: (pid 4187) 552s; run: log: (pid 4199) 549s
run: nginx: (pid 4646) 457s; run: log: (pid 4659) 454s
run: node-exporter: (pid 5086) 358s; run: log: (pid 4696) 448s
run: postgres-exporter: (pid 5153) 354s; run: log: (pid 4902) 420s
run: postgresql: (pid 4390) 533s; run: log: (pid 4405) 530s
run: prometheus: (pid 5106) 356s; run: log: (pid 4754) 432s
run: puma: (pid 4564) 477s; run: log: (pid 4580) 473s
run: redis: (pid 4218) 546s; run: log: (pid 4235) 543s
run: redis-exporter: (pid 5099) 357s; run: log: (pid 4730) 438s
run: sidekiq: (pid 4590) 470s; run: log: (pid 4604) 467s
[root@gitlab conf]
[root@gitlab conf]
PID TTY STAT TIME COMMAND
4646 ? Ss 0:00 nginx: master process /opt/gitlab/embedded/sbin/nginx -p /var/opt/gitlab/nginx
[root@gitlab conf]
server {
listen *:80;
server_name 192.168.118.130;
client_max_body_size 0;
add_header Strict-Transport-Security "max-age=63072000";
proxy_hide_header Referrer-Policy;
add_header Referrer-Policy strict-origin-when-cross-origin;
access_log /var/log/gitlab/nginx/gitlab_access.log gitlab_access;
error_log /var/log/gitlab/nginx/gitlab_error.log error;
if ($http_host = "") {
set $http_host_with_default "192.168.118.130";
}
if ($http_host != "") {
set $http_host_with_default $http_host;
}
[root@gitlab conf]
启动、重启、停止gitlab
安装好gitlab之后会产生gitlab-ctl命令,使用该命令来管理gitlab服务
[root@gitlab ~]
[root@gitlab ~]
[root@gitlab ~]
[root@gitlab ~]
[root@gitlab ~]
[root@gitlab ~]
web页面访问gitlab
上一步我们发现gitlab自带了一个nginx,访问端口是80,下面我们在浏览器访问gitlab。
创建一个项目
本地上传提交代码
这里先讲一下git remote命令,该命令为添加一个远程仓库,语法格式为:
git remote add [shortname] [url]
[root@git Dosier_Project]
git push -u my_gitlab_repository dev
[root@git Dosier_Project]
[root@git Dosier_Project]
[root@git Dosier_Project]
[root@git Dosier_Project]
gitlab_Dossier_Project http://192.168.118.130/root/dossier_project.git (fetch)
gitlab_Dossier_Project http://192.168.118.130/root/dossier_project.git (push)
[root@git Dosier_Project]
Username for 'http://192.168.118.130': root
Password for 'http://root@192.168.118.130':
Counting objects: 13, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (13/13), 969 bytes | 0 bytes/s, done.
Total 13 (delta 2), reused 0 (delta 0)
remote:
remote: To create a merge request for dev, visit:
remote: http://192.168.118.130/root/dossier_project/-/merge_requests/new?merge_request%5Bsource_branch%5D=dev
remote:
To http://192.168.118.130/root/dossier_project.git
+ fc78a64...00444bd main -> dev (forced update)
[root@git Dosier_Project]
提交之后我们web网页查看dev分支,发现已经有文件了,如下图所示,说明已经提交成功了。
克隆下载
如果下载克隆下载项目代码,可以直接使用git clone命令来克隆,如下:
[root@git ~]
|