使用离线安装包搭建和卸载gitlab服务器,使用gitlab提交,下载文件
1 下载Gitlab服务器软件包
下载地址:https://packages.gitlab.com/gitlab/gitlab-ce
选择自己需要的版本下载即可,我是用的是centos 7,所以我下载的是gitlab-ce-15.3.2-ce.0.el7.x86_64.rpm
点击右上方download下载,或者复制下方的wget下载
我这里选择的是wget下载方式,不需要单独在上传一次。建议用download方式先下载下来,MD5校验一下,和页面上的MD5值对比,保证文件的完整性
[root@k8s-node2 ~]# wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-15.3.2-ce.0.el7.x86_64.rpm/download.rpm
--2022-08-31 10:30:25-- https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-15.3.2-ce.0.el7.x86_64.rpm/download.rpm
Resolving packages.gitlab.com (packages.gitlab.com)... 104.18.27.123, 104.18.26.123, 2606:4700::6812:1a7b, ...
Connecting to packages.gitlab.com (packages.gitlab.com)|104.18.27.123|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://d20rj4el6vkp4c.cloudfront.net/7/8/el/7/package_files/88759.rpm?t=1661913359_2efbf97e9189648ad90f368be3b5c24df5d51e21 [following]
--2022-08-31 10:30:25-- https://d20rj4el6vkp4c.cloudfront.net/7/8/el/7/package_files/88759.rpm?t=1661913359_2efbf97e9189648ad90f368be3b5c24df5d51e21
Resolving d20rj4el6vkp4c.cloudfront.net (d20rj4el6vkp4c.cloudfront.net)... 65.9.58.119, 65.9.58.38, 65.9.58.228, ...
Connecting to d20rj4el6vkp4c.cloudfront.net (d20rj4el6vkp4c.cloudfront.net)|65.9.58.119|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1101655026 (1.0G) [application/x-rpm]
Saving to: ‘gitlab-ce-15.3.2-ce.0.el7.x86_64.rpm’
100%[========================================================================================================================>] 1,101,655,026 977KB/s in 16m 8s
2022-08-31 10:46:35 (1.09 MB/s) - ‘gitlab-ce-15.3.2-ce.0.el7.x86_64.rpm’ saved [1101655026/1101655026]
2 安装Gitlab
下载网页也有对应install命令,复制直接在服务器运行即可
yum install gitlab-ce-15.3.2-ce.0.el7.x86_64.rpm -y
[root@k8s-node2 ~]# yum install gitlab-ce-15.3.2-ce.0.el7.x86_64.rpm -y
Loaded plugins: fastestmirror
Examining gitlab-ce-15.3.2-ce.0.el7.x86_64.rpm: gitlab-ce-15.3.2-ce.0.el7.x86_64
Marking gitlab-ce-15.3.2-ce.0.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package gitlab-ce.x86_64 0:15.3.2-ce.0.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================================
Installing:
gitlab-ce x86_64 15.3.2-ce.0.el7 /gitlab-ce-15.3.2-ce.0.el7.x86_64 2.3 G
Transaction Summary
====================================================================================================================================================================
Install 1 Package
Total size: 2.3 G
Installed size: 2.3 G
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : gitlab-ce-15.3.2-ce.0.el7.x86_64 1/1
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=15-3
Verifying : gitlab-ce-15.3.2-ce.0.el7.x86_64 1/1
Installed:
gitlab-ce.x86_64 0:15.3.2-ce.0.el7
Complete!
3 配置Gitlab
默认使用的是80端口,如果需要修改端口还需要修改配置文件vim /var/opt/gitlab/nginx/conf/gitlab-http.conf,把80监听端口改掉
vim /etc/gitlab/gitlab.rb
把external_url 'http://gitlab.example.com' 修改成节点地址或者域名
[root@k8s-node2 ~]# cat /etc/gitlab/gitlab.rb | grep -v ^# | grep -v ^$
external_url 'http://192.168.198.147'
4 重新配置gitlab
[root@k8s-node2 ~]# gitlab-ctl reconfigure
Running handlers:
[2022-08-31T11:19:23+08:00] INFO: Running report handlers
Running handlers complete
[2022-08-31T11:19:23+08:00] INFO: Report handlers complete
Infra Phase complete, 571/1532 resources updated in 03 minutes 47 seconds
Notes:
Default admin account has been configured with following details:
Username: root
Password: You didn't opt-in to print initial root password to STDOUT.
Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.
NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
gitlab Reconfigured!
5 访问gitlab
访问地址:http://192.168.198.147
默认账户名是root,密码存放在配置文件 /etc/gitlab/initial_root_password
登录后可自行修改密码
6 gitlab的卸载
#停止gitlab
[root@k8s-node2 gitlab]# gitlab-ctl stop
ok: down: alertmanager: 0s, normally up
ok: down: gitaly: 0s, normally up
ok: down: gitlab-exporter: 0s, normally up
ok: down: gitlab-kas: 0s, normally up
ok: down: gitlab-workhorse: 1s, normally up
ok: down: logrotate: 0s, normally up
ok: down: nginx: 1s, normally up
ok: down: node-exporter: 0s, normally up
ok: down: postgres-exporter: 0s, normally up
ok: down: postgresql: 0s, normally up
ok: down: prometheus: 0s, normally up
ok: down: puma: 0s, normally up
ok: down: redis: 1s, normally up
ok: down: redis-exporter: 0s, normally up
ok: down: sidekiq: 0s, normally up
#查询安装的包是gitlab-ce
[root@k8s-node2 gitlab]# rpm -qa | grep git
linux-firmware-20200421-79.git78c0348.el7.noarch
git-1.8.3.1-23.el7_8.x86_64
gitlab-ce-15.3.2-ce.0.el7.x86_64
crontabs-1.11-6.20121102git.el7.noarch
#卸载gitlab-ce
[root@k8s-node2 gitlab]# rpm -e gitlab-ce
[root@k8s-node2 gitlab]#
#查询gitlab进程,把runsvdir -P /opt/gitlab/service log关掉,这个是守护进程
[root@k8s-node2 gitlab]# ps -ef|grep gitlab
root 1575 1 0 09:17 ? 00:00:00 runsvdir -P /opt/gitlab/service log: ...........................................................................................................................................................................................................................................................................................................................................................................................................
root 1631 1575 0 09:17 ? 00:00:00 runsv gitlab-kas
root 1634 1575 0 09:17 ? 00:00:00 runsv gitlab-workhorse
root 1637 1575 0 09:17 ? 00:00:00 runsv gitlab-exporter
root 1639 1634 0 09:17 ? 00:00:00 svlogd /var/log/gitlab/gitlab-workhorse
root 1641 1637 0 09:17 ? 00:00:00 svlogd -tt /var/log/gitlab/gitlab-exporter
root 1644 1638 0 09:17 ? 00:00:00 svlogd -tt /var/log/gitlab/redis-exporter
root 1646 1635 0 09:17 ? 00:00:00 svlogd -tt /var/log/gitlab/nginx
root 1649 1636 0 09:17 ? 00:00:00 svlogd -tt /var/log/gitlab/node-exporter
root 1651 1647 0 09:17 ? 00:00:00 svlogd -tt /var/log/gitlab/alertmanager
root 1653 1633 0 09:17 ? 00:00:00 svlogd /var/log/gitlab/sidekiq
root 1654 1632 0 09:17 ? 00:00:00 svlogd -tt /var/log/gitlab/puma
root 1657 1643 0 09:17 ? 00:00:00 svlogd -tt /var/log/gitlab/prometheus
root 1662 1626 0 09:17 ? 00:00:00 svlogd -tt /var/log/gitlab/logrotate
root 1664 1627 0 09:17 ? 00:00:00 svlogd -tt /var/log/gitlab/redis
root 1674 1628 0 09:17 ? 00:00:00 svlogd /var/log/gitlab/gitaly
root 1676 1630 0 09:17 ? 00:00:00 svlogd -tt /var/log/gitlab/postgresql
root 1679 1631 0 09:17 ? 00:00:00 svlogd -tt /var/log/gitlab/gitlab-kas
root 1681 1648 0 09:17 ? 00:00:00 svlogd -tt /var/log/gitlab/postgres-exporter
root 28101 22630 0 10:07 pts/0 00:00:00 grep --color=auto gitlab
#关掉守护进程runsvdir -P /opt/gitlab/service log
[root@k8s-node2 gitlab]# kill -9 1575
[root@k8s-node2 gitlab]#
#再次查询进程
[root@k8s-node2 gitlab]# ps -ef|grep gitlab
root 30101 22630 0 10:12 pts/0 00:00:00 grep --color=auto gitlab
[root@k8s-node2 gitlab]#
#对应配置文件删除
[root@k8s-node2 gitlab]# find / -name gitlab | xargs rm -rf
[root@k8s-node2 gitlab]#
#再次查询安装包,已卸载完成
[root@k8s-node2 gitlab]# rpm -qa | grep git
linux-firmware-20200421-79.git78c0348.el7.noarch
git-1.8.3.1-23.el7_8.x86_64
crontabs-1.11-6.20121102git.el7.noarch
7、 gitlab的配置ssh密钥
生成密钥命令:
[root@k8s-node2 .ssh]# ssh-keygen -t rsa
[root@k8s-node2 ~]# cd .ssh
[root@k8s-node2 .ssh]# ll
total 8
-rw------- 1 root root 1679 Oct 19 15:53 id_rsa
-rw-r--r-- 1 root root 396 Oct 19 15:53 id_rsa.pub
复制公钥内容,id_rsa.pub配置上gitlab
8、创建项目,推送数据
项目名称,分组,私有或者公用等信息,创建即可
在clone下面可以看到仓库地址
#服务器上创建一个目录,用来提交、拉取数据
[root@k8s-node2 local]# mkdir xmgc
[root@k8s-node2 local]# cd xmgc/
[root@k8s-node2 xmgc]# ll
total 0
#克隆仓库,也可以用git init
[root@k8s-node2 xmgc]# git clone git@192.168.198.147:root/xmgc.git
Cloning into 'xmgc'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 11 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (11/11), 160.68 MiB | 26.50 MiB/s, done.
#克隆后看到仓库数据已经拉取下来
[root@k8s-node2 xmgc]# ll
total 0
drwxr-xr-x 3 root root 35 Oct 20 09:15 xmgc
# 切到仓库目录下
[root@k8s-node2 xmgc]# cd xmgc/
[root@k8s-node2 xmgc]# ll -a
total 8
drwxr-xr-x 3 root root 35 Oct 20 09:15 .
drwxr-xr-x 3 root root 18 Oct 20 09:14 ..
drwxr-xr-x 8 root root 163 Oct 20 09:15 .git
-rw-r--r-- 1 root root 6183 Oct 20 09:15 README.md
#查询分支
[root@k8s-node2 xmgc]# git branch
* main
[root@k8s-node2 xmgc]# git branch -a
* main
remotes/origin/HEAD -> origin/main
remotes/origin/main
remotes/origin/test
# 创建本地分支one
[root@k8s-node2 xmgc]# git branch one
[root@k8s-node2 xmgc]# git branch -a
* main
one
remotes/origin/HEAD -> origin/main
remotes/origin/main
remotes/origin/test
#切换到one分支
[root@k8s-node2 xmgc]# git checkout one
Switched to branch 'one'
# 将one分支push到gitlab上,这样就能在gitlab中显示分支了
[root@k8s-node2 xmgc]# git push origin one
Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for one, visit:
remote: http://192.168.198.147/root/xmgc/-/merge_requests/new?merge_request%5Bsource_branch%5D=one
remote:
To git@192.168.198.147:root/xmgc.git
* [new branch] one -> one
#创建文件测试
[root@k8s-node2 xmgc]# touch one.txt
[root@k8s-node2 xmgc]#
#添加标志
[root@k8s-node2 xmgc]# git add .
[root@k8s-node2 xmgc]#
#提交
[root@k8s-node2 xmgc]# git commit -m "1 push"
[one b33bdfa] 1 push
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 one.txt
[root@k8s-node2 xmgc]#
#推送
[root@k8s-node2 xmgc]# git push
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 270 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 1 (delta 0)
remote:
remote: To create a merge request for one, visit:
remote: http://192.168.198.147/root/xmgc/-/merge_requests/new?merge_request%5Bsource_branch%5D=one
remote:
To git@192.168.198.147:root/xmgc.git
c41d3d0..b33bdfa one -> one
[root@k8s-node2 xmgc]#
可以看到推送上来的one.txt文件
如果提交报错:
[root@k8s-node2 xmls]# git push
To git@192.168.198.147:root/xmls.git
! [rejected] xmzw -> xmzw (non-fast-forward)
error: failed to push some refs to 'git@192.168.198.147:root/xmls.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
需要拉取最新代码下来,才能提交
[root@k8s-node2 xmls]# git pull --rebase origin xmzw
[root@k8s-node2 xmls]# git push
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 669 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote:
remote: To create a merge request for xmzw, visit:
remote: http://192.168.198.147/root/xmls/-/merge_requests/new?merge_request%5Bsource_branch%5D=xmzw
remote:
To git@192.168.198.147:root/xmls.git
0c2ea6e..7353e51 xmzw -> xmzw
常用命令:
1、git branch -a --先查看下本地和远程分别有哪些分支
2、git branch dev --创建一个名称为dev的分支
3、git checkout dev --切换到本地的dev分支
4、git add . -- 将代码暂存到暂存区(点前面有空格)
5、git commit -m "代码提交" --提交代码到本地分支
6、git push origin dev --将dev分支push到gitlab上,这样就能在gitlab中显示分支了
7、git pull origin dev --将gitlab上的代码,拉到本地
8、git merge test --需在dev分支下执行这段;可将test中的代码合并到dev中
二、删除
1、git push origin --delete dev --删除gitlab上的dev分支
2、git remote rm origin --删除指定的远程连接
3、git remote add origin --添加远程连接给i他