1.配置网卡及ubuntu仓库源
1)配置网卡eth0,本地内网网卡无需指定网关和域名服务器
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.30/24]
2)配置网卡eth1,要保持以下两个字节的严格缩进,否则会导致网卡起不来
root@ubuntu1804:~# vim /etc/netplan/02-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eth1:
dhcp4: yes
addresses: [192.168.10.107/24]
gateway4: 192.168.10.1
nameservers:
addresses: [223.6.6.6]
3)配置阿里云仓库源
root@ubuntu1804:~# vim /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
4)更新仓库
root@ubuntu1804:~# apt update
root@ubuntu1804:~# apt update
Get:1 http://mirrors.aliyun.com/ubuntu bionic InRelease [242 kB]
Get:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease [88.7 kB]
Get:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease [242 kB]
……
2.安装gitlab包
1)下载gitlab-ce社区版包
root@ubuntu1804:~# ls /data/
gitlab-ce_11.11.5-ce.0_amd64.deb
2)安装gitlab,要确定gitlab包适合此版本ubuntu系统
root@ubuntu1804:/data# dpkg -i gitlab-ce_11.11.5-ce.0_amd64.deb
root@ubuntu1804:/data# dpkg -i gitlab-ce_11.11.5-ce.0_amd64.deb
Selecting previously unselected package gitlab-ce.
(Reading database ... 69294 files and directories currently installed.)
Preparing to unpack gitlab-ce_11.11.5-ce.0_amd64.deb ...
Unpacking gitlab-ce (11.11.5-ce.0) … #等待安装完成
3)此时无法识别主机,需修改git配置文件,指定主机
root@ubuntu1804:/data# vim /etc/gitlab/gitlab.rb
external_url 'http://192.168.1.30' #修改指定的ip主机
4)配置完进行gitlab初始化
root@ubuntu1804:/data# gitlab-ctl reconfigure
3.命令操作
1)进入数据库命令行
root@ubuntu1804:~# gitlab-psql
gitlabhq_production-# \db
List of tablespaces
Name | Owner | Location
------------+-------------+----------
pg_default | gitlab-psql |
pg_global | gitlab-psql |
(2 rows)
2)查看gitlab的运行状态
root@ubuntu1804:~# gitlab-ctl status
run: alertmanager: (pid 4704) 1841s; run: log: (pid 4373) 1867s
run: gitaly: (pid 4475) 1844s; run: log: (pid 3483) 2026s
run: gitlab-monitor: (pid 4553) 1843s; run: log: (pid 4169) 1887s
run: gitlab-workhorse: (pid 4512) 1844s; run: log: (pid 4027) 1910s
run: logrotate: (pid 4073) 1900s; run: log: (pid 4089) 1899s
run: nginx: (pid 4040) 1906s; run: log: (pid 4060) 1905s
run: node-exporter: (pid 4537) 1843s; run: log: (pid 4146) 1892s
run: postgres-exporter: (pid 4727) 1840s; run: log: (pid 4409) 1863s
run: postgresql: (pid 3659) 2012s; run: log: (pid 3689) 2011s
run: prometheus: (pid 4578) 1842s; run: log: (pid 4245) 1875s
run: redis: (pid 3417) 2034s; run: log: (pid 3442) 2031s
run: redis-exporter: (pid 4561) 1842s; run: log: (pid 4202) 1881s
run: sidekiq: (pid 3967) 1920s; run: log: (pid 3983) 1916s
run: unicorn: (pid 3908) 1926s; run: log: (pid 3957) 1923s
3)gitlab服务命令行的启动、停止、重启
gitlab-ctl start/stop/restart gitlab
4)查看gitlab的nginx服务组件的日志
root@ubuntu1804:~# gitlab-ctl tail nginx
==> /var/log/gitlab/nginx/current <==
==> /var/log/gitlab/nginx/access.log <==
==> /var/log/gitlab/nginx/error.log <==
==> /var/log/gitlab/nginx/gitlab_error.log <==
==> /var/log/gitlab/nginx/gitlab_access.log <==
192.168.1.1 - - [21/Jul/2019:10:36:00 +0800] "GET / HTTP/1.1" 302 99 "" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3724.8 Safari/537.36"
……
4.浏览器访问gitlab
1)设置新的密码,默认登录的用户为root
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/d0470651142f0e3fdba4f668456be4d3.png)
2)登录后默认的界面
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/694b4d60454d2abbb50a12fe9cd5fbca.png)
3)点击setting,在点击sign-up可以设置是否允许创建新用户
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/5efc1aef8bda6fb98b8866f5270288d0.png)
4)去掉对勾,禁止创建新账户
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/7e95e4d9e1e9f2bba249f58d448706b4.png)
5)再点击保存修改生效
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/a318ca9681d9dca1f4b52946102d3c50.png)
6)此时登出账号时,就没有注册用户的选项,只能用已有的账户登录
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/eb0586a347b4ca9ebce23c6b85ed8321.png)
7)创建一个新用户时会受到邮件通知
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/c1e99c45cd5cddea6942e45e30071cfd.png)
8)创建不同的项目、组、账户,将特定用户放到特定的组,实现特定用户对某些项目有查看权限
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/d6ff7f22b5f02990c8c20a1ca094d2e0.png)
9)返回到项目列表,并进入一个项目
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/28fee44ad67926967d49799a27983cc1.png)
10)点击New file
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/a4cc12e22ce317fb49f15ebfff450764.png)
11)输入一个索引测试页面,再点击提交
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/b20567d877b37d070ee213ec8c6aea9b.png)
12)查看项目的clone地址
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/59ccb1b1b114d434ae06c3969201b817.png)
13)客户端clone
root@ubuntu1804:/data/src# git clone http://192.168.1.30/root/web-page.git
Cloning into 'web-page'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
14)项目代码克隆成功
root@ubuntu1804:/data/src# ls
web-page
root@ubuntu1804:/data/src# cat web-page/index.html
<h>hello jie!</h1>
15)在客户端修改index.html
root@ubuntu1804:/data/src/web-page# cat index.html
<h>hello jie!</h1>
<h>hello kobe!</h1>
<h>hello curry!</h1>
<h>hello rose!</h1>
16)先添加到本地暂存区(提交代码到gitlab服务器时,命令都必须在克隆下来的文件夹环境中执行)
root@ubuntu1804:/data/src/web-page# git add index.html
17)在提到工作区
root@ubuntu1804:/data/src/web-page# git commit -m 'v6'
[master 1202723] v6
1 file changed, 4 insertions(+), 1 deletion(-)
18)然后在直接提交到gitlab仓库web端
root@ubuntu1804:/data/src/web-page# git push #其中git pull为获取代码到本地
Username for 'http://192.168.1.30': root #要求输入登录gitlab的web端的用户名
Password for 'http://root@192.168.1.30': #再输入登录gitlab的web端的用户密码
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 268 bytes | 268.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.1.30/root/web-page.git
ecc001d..1202723 master -> master #提交完成
19)在web端gitlab仓库查看,项目index.html内容被更改,说明成功提交
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/2d91ec92980152a22bc875eace6c9db1.png)
20)再次修改index.html文件,然后在上传v7版本的index.html到gitlab的服务端
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/abf7abf0225688686a0b64e9ef3b73e3.png)
5.gitlab的一些基本命令操作(以下命令操作命令都必须在克隆下来的文件夹环境中执行,否则无法执行令)
1)客户端查看当前版本号为v7
root@ubuntu1804:/data/src/web-page# git reset --hard HEAD
HEAD is now at 952e66b v7
2)查看v7版索引
root@ubuntu1804:/data/src/web-page# cat index.html
<h>hello jie!</h1>
<h>hello kobe!</h1>
<h>hello curry!</h1>
<h>hello rose!</h1>
<h>hello jordan!</h1>
<h>hello jordan!</h1>
<h>hello howard!</h1>
3)若想回滚到v6版本,则操作如下命令进行回滚
root@ubuntu1804:/data/src/web-page# git reset --hard HEAD^
HEAD is now at 9cb6bf6 v6
4)再查看v6版本索引文件
root@ubuntu1804:/data/src/web-page# cat index.html
<h>hello jie!</h1>
<h>hello kobe!</h1>
<h>hello curry!</h1>
<h>hello rose!</h1>
<h>hello jordan!</h1>
<h>hello jordan!</h1>
5)查看每次提交的目标代码id号,
root@ubuntu1804:/data/src/web-page# git reflog
9cb6bf6 (HEAD -> master) HEAD@{0}: reset: moving to HEAD^
952e66b (origin/master, origin/HEAD) HEAD@{1}: reset: moving to HEAD
952e66b (origin/master, origin/HEAD) HEAD@{2}: commit: v7
9cb6bf6 (HEAD -> master) HEAD@{3}: commit: v6
03e27be (tag: v1.4) HEAD@{4}: commit: v7
1202723 HEAD@{5}: commit: v6
ecc001d HEAD@{6}: clone: from http://192.168.1.30/root/web-page.git
6)也可指定目标代码id号,实现回滚
root@ubuntu1804:/data/src/web-page# git reset --hard 9cb6bf6
7)查看当前所属的分支,默认为master主分支
root@ubuntu1804:/data/src/web-page# git branch
* master
8)创建并切换到新分支
root@ubuntu1804:/data/src/web-page# git checkout -b operations
Switched to a new branch 'operations'
9)再次列出所有分支分支
root@ubuntu1804:/data/src/web-page# git branch
master
* operations
10)切换回到主分支
root@ubuntu1804:/data/src/web-page# git checkout master
Switched to branch 'master'
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
root@ubuntu1804:/data/src/web-page# git branch
* master
operations
6.数据备份
1)备份前先要暂停gitlab的两个数据服务,避免在备份时开发人员继续提交代码至gitlab中,导致数据不完整
root@ubuntu1804:~# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
root@ubuntu1804:~# gitlab-ctl stop nunicorn
2)手动创建备份
root@ubuntu1804:~# gitlab-rake gitlab:backup:create
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/1226f845ce4ac5d49f97904a55d95334.png)
3)gitlab默认备份数据名称及路径,为压缩文件
root@ubuntu1804:~# ll /var/opt/gitlab/backups/1563709800_2019_07_21_11.11.5_gitlab_backup.tar
-rw------- 1 git git 92160 Jul 21 19:50 /var/opt/gitlab/backups/1563709800_2019_07_21_11.11.5_gitlab_backup.tar
4)在gitlab的web端目前存在的项目、用户和组
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/9eeec9e92296e67216c90dd0c621ed29.png)
5)先删除掉几个项目、用户或组
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/b96d9c21324483cd6b5cd13af430bc0c.png)
7.客户端数据恢复
1)在恢复数据之前也要先关闭gitlab的两个数据服务
root@ubuntu1804:~# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
root@ubuntu1804:~# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
2)执行恢复备份数据命令
root@ubuntu1804:~# gitlab-rake gitlab:backup:restore /var/opt/gitlab/backups/1563709800_2019_07_21_11.11.5_gitlab_backup.tar
3)在开启gitlab的两个数据服务
oot@ubuntu1804:~# gitlab-ctl start sidekiq
ok: run: sidekiq: (pid 80094) 1s
root@ubuntu1804:~# gitlab-ctl start unicorn
ok: run: unicorn: (pid 80191) 0s
4)gitlab的web端访问测试,可以看到删除的项目、用户、组全部恢复
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/519d906c38551d990b9d38aaf2e09376.png)
![gitlab的部署、代码克隆和提交、数据备份等](https://i-blog.csdnimg.cn/blog_migrate/753174956cbf731cd32ec43f8d8debc7.png)