centos7搭建gitlab伺服器
簡單研究docker下gitlab伺服器的安裝過程。其實是為了後面研究jenkins自動部署。
其安裝也可以用docker安裝或者是直接宿主機中安裝,參考:https://about.gitlab.com/install
0.簡介
GitLab 是一個用於倉庫管理系統的開源專案,使用Git作為程式碼管理工具,並在此基礎上搭建起來的web服務。可以認為GitLab是免費版的Github,主要功能都差不多。
1. gitlab安裝
1.安裝相關依賴
sudo yum install -y curl policycoreutils-python openssh-server sudo systemctl enable sshdsudo systemctl start sshd sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo systemctl reload firewalld
2.安裝Postfix以傳送通知郵件
sudo yum install postfix sudo systemctl enable postfix sudo systemctl start postfix
3. 下載rpm包
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
4. 下載後上傳到linux伺服器
rpm -ivh ./gitlab-ce-10.0.0-ce.0.el6.x86_64.rpm
如下:
[root@localhost gitlab]# rpm -ivh ./gitlab-ce-10.0.0-ce.0.el6.x86_64.rpm warning: ./gitlab-ce-10.0.0-ce.0.el6.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY Preparing... ################################# [100%] Updating / installing... 1:gitlab-ce-10.0.0-ce.0.el6 ################################# [100%] 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
5. 修改IP和埠
修改/etc/gitlab/gitlab.rb
vi /etc/gitlab/gitlab.rb
修改IP和埠,注意這個配置在原來存在,需要用 / external_url 查詢後修改:
external_url 'http://192.168.1.128:8080'
6. 重新載入配置後重啟
gitlab-ctl reconfigure
gitlab-ctl restart
補充:我啟動後報錯得到如下資訊:
檢視日誌資訊:
(1) 檢視狀態
[root@localhost ~]# gitlab-ctl status run: gitaly: (pid 8876) 425s; run: log: (pid 713) 922s run: gitlab-monitor: (pid 8881) 425s; run: log: (pid 683) 924s run: gitlab-workhorse: (pid 8884) 424s; run: log: (pid 676) 924s run: logrotate: (pid 8895) 423s; run: log: (pid 670) 924s run: nginx: (pid 10608) 15s; run: log: (pid 669) 924s run: node-exporter: (pid 8903) 423s; run: log: (pid 681) 924s run: postgres-exporter: (pid 8910) 422s; run: log: (pid 711) 922s run: postgresql: (pid 8918) 421s; run: log: (pid 701) 923s run: prometheus: (pid 10620) 14s; run: log: (pid 674) 924s run: redis: (pid 8931) 420s; run: log: (pid 700) 923s run: redis-exporter: (pid 8934) 420s; run: log: (pid 702) 923s run: sidekiq: (pid 10596) 15s; run: log: (pid 704) 923s run: unicorn: (pid 10575) 17s; run: log: (pid 667) 925s
(2) 檢視埠:
[root@localhost ~]# netstat -nao|grep 8080 tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN off (0.00/0/0) tcp 0 0 127.0.0.1:8080 127.0.0.1:58594 TIME_WAIT timewait (35.76/0/0) tcp 0 0 127.0.0.1:8080 127.0.0.1:58608 TIME_WAIT timewait (42.49/0/0) tcp 0 0 127.0.0.1:8080 127.0.0.1:58570 TIME_WAIT timewait (23.64/0/0) tcp 0 0 127.0.0.1:8080 127.0.0.1:58630 TIME_WAIT timewait (57.46/0/0)
(3)檢視日誌:
==> /var/log/gitlab/nginx/current <== 2020-09-13_14:07:03.59922 2020/09/13 10:07:02 [emerg] 12265#0: bind() to 0.0.0.0:8080 failed (98: Address already in use) 2020-09-13_14:07:04.10335 2020/09/13 10:07:02 [emerg] 12265#0: bind() to 0.0.0.0:8080 failed (98: Address already in use) 2020-09-13_14:07:04.61290 2020/09/13 10:07:02 [emerg] 12265#0: bind() to 0.0.0.0:8080 failed (98: Address already in use) 2020-09-13_14:07:05.12143 2020/09/13 10:07:02 [emerg] 12265#0: still could not bind()
發現埠被佔用
(4) 解決辦法:
停止服務:
gitlab-ctl stop
修改埠:
vi /etc/gitlab/gitlab.rb
下面埠修改為8888
unicorn['port'] = 8888
(5)我在中間還報錯:
2020-09-13_14:14:06.12114 2020/09/13 10:14:06 redis: dialing "unix", "/var/opt/gitlab/redis/redis.socket" 2020-09-13_14:14:06.12122 2020/09/13 10:14:06 error: keywatcher: dial unix /var/opt/gitlab/redis/redis.socket: connect: no such file or directory 2020-09-13_14:16:47.33884 time="2020-09-13T10:16:47-04:00" level=info msg="Error running query on database: pg_vacuum_analyze dial unix /var/opt/gitlab/postgresql/.s.PGSQL.5432: connect: no such file or directory\n" source="postgres_exporter.go:919" 2020-09-13_14:16:47.33891 time="2020-09-13T10:16:47-04:00" level=info msg="Error running query on database: pg_replication dial unix /var/opt/gitlab/postgresql/.s.PGSQL.5432: connect: no such file or directory\n" source="postgres_exporter.go:919"
解決:賦予許可權:
sudo chmod 755 /var/opt/gitlab/postgresql sudo chmod 755 /var/opt/gitlab/redis sudo chmod 755 /var/opt/gitlab/
(6) 重新載入以及重啟
(7) free檢視記憶體:
[root@localhost postgresql]# free total used free shared buff/cache available Mem: 2895200 1086972 1200244 56200 607984 1567808 Swap: 2097148 0 2097148 [root@localhost postgresql]# free total used free shared buff/cache available Mem: 2895200 1914688 371976 56420 608536 739832
發現記憶體在一直減少,應該是gitlab初始化沒完成。
(8)等待記憶體穩定後訪問:
2.gitlab簡單使用
1. 第一次訪問需要設定密碼
我將密碼簡單的設為: qwe123123
2. 登陸
預設賬號是root,密碼是上面設定的qwe123123
3.這裡我們簡單的建立一個專案,並且將本地的專案推送到gitlab(簡單的操作下)
(1) New->new project (有點類似於github)
(2) windows客戶端拉取程式碼修改之後推送到gitlab
liqiang@root MINGW64 /g $ git clone http://192.168.1.128:8080/root/ssmTemplate.git Cloning into 'ssmTemplate'... remote: Counting objects: 31, done. remote: Total 31 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (31/31), done. liqiang@root MINGW64 /g $ cd ssmTemplate/ liqiang@root MINGW64 /g/ssmTemplate (master) $ ls mvnw* mvnw.cmd pom.xml README.md src/ liqiang@root MINGW64 /g/ssmTemplate (master) $ echo 'xx' >> 1.txt liqiang@root MINGW64 /g/ssmTemplate (master) $ git add . warning: LF will be replaced by CRLF in 1.txt. The file will have its original line endings in your working directory. g liqiang@root MINGW64 /g/ssmTemplate (master) $ git commit -am "xx" [master 737c9a7] xx 1 file changed, 1 insertion(+) create mode 100644 1.txt g liqiang@root MINGW64 /g/ssmTemplate (master) $ git push origin master Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 269 bytes | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) To http://192.168.1.128:8080/root/ssmTemplate.git b5f9057..737c9a7 master -> master
(3)gitlab伺服器檢視提交記錄:
(4) gitlab伺服器檢視檔案儲存位置:
預設的倉庫儲存路徑在 /var/opt/gitlab/git-data目錄下,倉庫儲存在子目錄repositories裡面,可以通過修改/etc/gitlab/gitlab.rb檔案中git_data_dirs引數來自定義父目錄
[root@localhost postgresql]# tree /var/opt/gitlab/git-data /var/opt/gitlab/git-data └── repositories └── root └── ssmTemplate.git ├── config ├── description ├── HEAD ├── hooks -> /opt/gitlab/embedded/service/gitlab-shell/hooks ├── hooks.old.1600008315 │ ├── applypatch-msg.sample │ ├── commit-msg.sample │ ├── post-update.sample
........
補充:gitlab相關命令
啟動服務:gitlab -ctl start 檢視狀態:gitlab -ctl status 停掉服務:gitlab -ctl stop 重啟服務:gitlab -ctl restart 讓配置生效:gitlab -ctl reconfigure
補充:防火牆相關命令
[root@localhost ~]# firewall-cmd --state running [root@localhost ~]# systemctl stop firewalld.service [root@localhost ~]# firewall-cmd --state not running [root@localhost ~]# systemctl disable firewalld.service Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [root@localhost ~]# systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1) Sep 13 09:42:46 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewa.... Sep 13 09:42:59 localhost.localdomain systemd[1]: Started firewalld - dynamic firewal.... Sep 13 09:48:46 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewa.... Sep 13 09:48:51 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewal.... Hint: Some lines were ellipsized, use -l to show in full.