GitLab 是一个用于仓库管理系统的开源项目。
1.安装配置gitlab依赖项
SMT服务、http 和ssh服务端口防火墙开放,测试时最好把防火墙关闭
安装相关依赖,并设置开机自启动
# yum install -y curl policycoreutils openssh-server openssh-clients postfix
2.添加GitLab仓库,并安装到服务器
yum方式安装
# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
# yum install gitlab-ce -y
也可以直接下载gitlab-ce-xxxx.rpm后本地安装(推荐)
下载地址:https://packages.gitlab.com/gitlab/gitlab-ce
# yum localinstall -y gitlab-ce-xxx.rpm
3.配置并启动github服务,如果配置文件发生更改需要重新执行此命令:
gitlab-ctl reconfigure
* template[/var/opt/gitlab/postgres-exporter/queries.yaml] action create (up to date)
Recipe:
* service[grafana] action nothing (skipped due to action :nothing)
Recipe: gitlab::grafana_disable
* runit_service[grafana] action disable
* ruby_block[disable grafana] action run (skipped due to only_if)
(up to date)
Recipe: gitlab::deprecate-skip-auto-migrations
* file[/etc/gitlab/skip-auto-reconfigure] action create (skipped due to only_if)
* ruby_block[skip-auto-migrations deprecation] action run (skipped due to only_if)
Recipe:
* service[unicorn] action restart
- restart service service[unicorn]
Running handlers:
Running handlers complete
Chef Client finished, 10/640 resources updated in 27 seconds
gitlab Reconfigured!
查看状态
# gitlab-ctl status
查看nginx日志:
==> /var/log/gitlab/nginx/gitlab_error.log <==
==> /var/log/gitlab/nginx/access.log <==
==> /var/log/gitlab/nginx/gitlab_access.log <==
192.168.56.1 - - [30/Apr/2019:11:46:15 +0800] "GET /liuzhousheng/web-django HTTP/1.1" 200 16066 "http://192.168.56.3/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36"
192.168.56.1 - - [30/Apr/2019:11:46:16 +0800] "GET /assets/favicon-7901bd695fb93edb07975966062049829afb56cf11511236e61bcf425070e36e.png HTTP/1.1" 200 1611 "http://192.168.56.3/liuzhousheng/web-django" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36"
192.168.56.1 - - [30/Apr/2019:11:46:18 +0800] "GET /liuzhousheng/web-django/commits/master/signatures HTTP/1.1" 200 17 "http://192.168.56.3/liuzhousheng/web-django" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36"
192.168.56.1 - - [30/Apr/2019:11:46:19 +0800] "GET /liuzhousheng/web-django/blob/master/README.md?format=json&viewer=rich HTTP/1.1" 304 0 "http://192.168.56.3/liuzhousheng/web-django" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36"
192.168.56.1 - - [30/Apr/2019:11:46:20 +0800] "GET /liuzhousheng/web-django/refs/master/logs_tree/?format=js HTTP/1.1" 304 0 "http://192.168.56.3/liuzhousheng/web-django" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36"
4.访问web界面
如打开以后是502的界面,需要检查80和8080端口是否被占用,另外增加内存,然后重新执行3步骤,首次登录得修改密码
4.1关闭登录页面的注册功能,否则可能导致信息泄露,使用admin 登录
最后点下方的save
退出登录,验证是否还有注册的功能:
4.2添加用户,一个用户可以说就是一个开发人员,配置好用户名,邮箱后
重新选择创建的用户点击Edit设置密码
4.3使用新账户登录,首次登录要设置密码,创建组,组里面可以有多个项目分支,可以将开发添加到组里面进行设置权限,不同的组就是公司不同的开发项目或者业务模块,不同的组添加不同的开发即可实现对开发设置权限的管理
4.4创建项目:
将用户添加到组:
Admin area–组名:
为项目创建一个web页面:
Project–组名/项目名–add a README—
测试客户端更新名提交代码,安装git客户端:
# yum install git -y
5.使用git更新及提交代码:
5.1 克隆代码:
# mkdir /data/apps
cd /data/apps/
①http方式克隆
# git clone http://192.168.56.3/liuzhousheng/web-django.git
正克隆到 'web-django'...
Username for 'http://192.168.56.3': liuzhousheng
Password for 'http://[email protected]':
remote: Enumerating objects: 27, done.
remote: Counting objects: 100% (27/27), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 27 (delta 2), reused 27 (delta 2)
Unpacking objects: 100% (27/27), done.
[root@localhost apps]# ll
总用量 0
drwxr-xr-x. 3 root root 50 4月 30 12:21 web-django
②通过ssh-key方式克隆
将客户端user_00用户的公钥拷贝到gitlab服务器的web端项目ssh-key中
[user_00@localhost ~]$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDHSkr5zTWobDcIUM6mFKDqFK6jO0CBlzD5qaOazO6WeKrJIlHtIaFZW4yAezWp9Cc8ZT0FCUaXHaOk39RKxIJGAuyi8kOpYM07/3NisRhukpu2HTTQKhAM3UpyQAjd+2w+Sw6Dl99YNeq0QVGn+2BGDCjaip4A6jNVpG601q3ztMr/ujtTXT0ulZcoy4xgtULpN66/Fu3YKUO1KuK6a6gxfdGyB9VIbrzS/ftdtsLvBD0TPisLbxN//ydwtvtJ1c1hqJtwob97F5v1Hu7rMEBjTVk3WwJ65eE0cey/L/0oPSePQHXJJI9geSwcHZdkWu1Di035SVa7E402ia6FgJYJ [email protected]
克隆代码
[user_00@localhost apps]$ git clone [email protected]:liuzhousheng/web-django.git
Cloning into 'web-django'...
remote: Enumerating objects: 27, done.
remote: Counting objects: 100% (27/27), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 27 (delta 2), reused 27 (delta 2)
Receiving objects: 100% (27/27), done.
Resolving deltas: 100% (2/2), done.
[user_00@localhost apps]$ tree ./
./
└── web-django
├── README.md
└── test.py
5.2添加分支,非组的属主是不能直接将代码提交到master分支的,需要建一个另外的分支,代码提交之后测试无误后再进行合并:
$ cd /data/apps/web-django
$ git branch dev #本地创建一个分支
$ git checkout dev #切换本地分支
$ git push origin dev #将本地分支发布到github
$ vim index.html #更新一下代码
my first web project
# git add index.html #提交更改到本地版本库
# git commit -m "second commit" #提交到git仓库
# git push -u origin dev #提交到一个分支
提交成功信息如下:
如果提交代码报错,提示没有权限提交,请检查提交的用户是否有对组的提交权限:
二:git常用命令汇总:
命令 git config --global user.name "name" #配置git使用用户
# git config --global user.email "mail" #配置git使用邮箱
# git config --global color.ui true #配置颜色
# git config --list #查看当前配置
# git init #初始为git工作目录
# git status #查看git状态
# git reflog #查看未来历史更新点
# git reset --hard 4bf5b29 #找到历史还原点的SHA-1值,就可以还原(值不写全,系统会自动匹配)
# git checkout -- file #恢复暂存区至上一版本
# git add [file1] [file2] ... #添加指定文件至暂存区
# git add [dir] #添加指定目录至暂存区,包括子目录(递归添加)
# git add . #添加当前目录所有文件至暂存区
# git rm [file1] [file2] ... #删除工作区文件,并将这次删除放入暂存区
# git rm –cached [file] #停止追踪指定文件,但该文件会保留在工作区
# git mv [file-old] [file-new] #重命名文件,修改后放入暂存区
配置gitlab为http方式:
将http://web01/liuzhousheng/web-django.git
改为http://192.168.56.3/liuzhousheng/web-django.git
步骤:
# vim /etc/gitlab/gitlab.rb
external_url 'http://web01'
改为
external_url 'http://192.168.56.3'
重新配置服务生效
# gitlab-ctl reconfigure
新建项目和历史项目都会变成IP了http://192.168.56.3