時間:2023-07-19 23:36:02 | 來源:網(wǎng)站運營
時間:2023-07-19 23:36:02 來源:網(wǎng)站運營
在局域網(wǎng)搭建一個帶 web 操作頁面的 git 版本服務器 - Gitlab:以下內(nèi)容為本人的著作,如需要轉(zhuǎn)載,請聲明原文鏈接 微信公眾號「ENG八戒」https://mp.weixin.qq.com/s/Br0ETd_aNffEZoTAba03Bw目標:
為了快速上線一個馬上用到的版本服務器,這里不打算對 gitlab 的使用做詳細說明,僅針對安裝配置和上線做初步的介紹。
后期計劃:
可能有些使用場景也需要用到一些特殊的服務,比如郵箱、固定域名訪問地址、外網(wǎng)訪問等,所以后期也會有這方面的介紹,敬請關(guān)注。
基礎(chǔ)環(huán)境:
Ubuntu 18.04.1 amd64
良好的網(wǎng)絡(luò)
apt-get
來安裝軟件,由于肉身在墻內(nèi)(相信大部分讀者也一樣吧?),所以切換安裝源到墻內(nèi)對于安裝過程會有幫助,起碼時間上會快一丟丟。為了以后如果有需要還原默認的安裝源配置,這里特地備份一下 apt-get
的安裝源配置文件sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
然后打開它sudo gedit /etc/apt/sources.list
我覺得阿里云的資源訪問速度比較快,所以這里準備把安裝源切到阿里云,這里有個 Ubuntu 的資源貼出來給大家耍耍,用瀏覽器打開下邊的地址https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b114ndGlW
這里邊列出了好幾個配置參考,對應于各個 Ubuntu LTS 版本(比如16.04、18.04、20.04等),太貼心了。以示敬意,不多說,直接拷貝對應的配置內(nèi)容然后粘貼到上邊打開的 sources.list
文檔中并且保存。sudo apt-get update
為了下面的操作,需要先安裝一個工具 curlsudo apt-get install curl
安裝 gitlab 時還有很多的依賴這里沒有展開來講,不過幸好官方其實提供了一個現(xiàn)成腳本用來配置倉庫,用下面的指令就可以執(zhí)行curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
上面執(zhí)行過程有可能會失敗,提示Installing /etc/apt/sources.list.d/gitlab_gitlab-ce.list...curl: (7) Failed to connect to packages.gitlab.com port 443: Connection refused
這是連接不穩(wěn)定導致的,多執(zhí)行幾次指令或許就順利通過了。下邊是我的執(zhí)行結(jié)果,表示倉庫已經(jīng)設(shè)置成功,萬事俱備就等著一鍵安裝了Detected operating system as Ubuntu/bionic.Checking for curl...Detected curl...Checking for gpg...Detected gpg...Running apt-get update... done.Installing apt-transport-https... done.Installing /etc/apt/sources.list.d/gitlab_gitlab-ce.list...done.Importing packagecloud gpg key... gpg: WARNING: unsafe ownership on homedir '/home/if/.gnupg'done.Running apt-get update... done.The repository is setup! You can now install packages.
sudo apt-get install gitlab-ce
好遺憾,又提示 connect 失敗了Could not connect to packages.gitlab.com:443...E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
在上邊的安裝失敗提示信息最后還建議在安裝命令參數(shù)里添加個選項 --fix-missing
,然后重試sudo apt-get install gitlab-ce --fix-missing
不幸的是,我這邊還是安裝失敗了,如果你的網(wǎng)絡(luò)足夠好或許就成功了呢,要看安裝成功的信息可以翻到 手動安裝
末尾,安裝成功可以直接跳到 啟動 gitlab 服務
一節(jié)。https://packages.gitlab.com/gitlab/gitlab-ce
我這里下載的是當前最新的包gitlab-ce_14.10.2-ce.0_amd64.deb
找個目錄存一下再到目錄里執(zhí)行sudo dpkg -i gitlab-ce_14.10.2-ce.0_amd64.deb
這個安裝包大小差不多 1G,稍等了一會,終于安裝完成!欣賞一下壯舉Selecting previously unselected package gitlab-ce.(Reading database ... 130072 files and directories currently installed.)Preparing to unpack gitlab-ce_14.10.2-ce.0_amd64.deb ...Unpacking gitlab-ce (14.10.2-ce.0) ...Setting up gitlab-ce (14.10.2-ce.0) ...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 reconfigureFor a comprehensive list of configuration options please see the Omnibus GitLab readmehttps://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.mdHelp 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-10
/etc/gitlab/gitlab.rb
。用文檔圖形編輯工具 gedit
打開這個文件sudo gedit /etc/gitlab/gitlab.rb
在上面打開的文件中,找到變量 external_url
,把主機的 IP 地址填進去并保存。主機的 IP 可以用指令 ifconfig
找到。一般還會在 IP 后邊添加個端口號防止和默認的端口沖突,我這里選了 8080external_url 'http://IP:8080/'
填在 external_url
后邊的內(nèi)容就是 gitlab 的登錄地址了。找到的這個 IP 一般都是網(wǎng)內(nèi)動態(tài)地址,所以上面的這個登錄地址只在網(wǎng)內(nèi)有效。如果有需求在網(wǎng)外訪問,考慮到安全性等因素,需要 VPN 支持,這里不展開。另外,畢竟是動態(tài)地址,如果需要使用固定的域名地址訪問,需要 DNS 服務器支持,還是不展開了。sudo gitlab-ctl reconfigure
重新啟動所有 gitlab 相關(guān)服務會花點時間。sudo gitlab-ctl start
~$ sudo cat initial_root_password# WARNING: This value is valid only in the following conditions# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).# 2. Password hasn't been changed manually, either via UI or via command line.## If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.Password: 93fm3-ae-f3jijq2oqh3iuhUFUEIBEFAFE434J5-PP04K30=# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
從文件內(nèi)容來看,這個密碼會在24小時后被自動刪除,所以需要把這 root 賬戶的密碼另存或者重設(shè)一個好記點的。sudo gitlab-rails console
找到管理員賬戶,存入自定義變量 userirb(main):001:0> user = User.find_by_username 'root'=> #<User id:1 @root>
設(shè)置密碼,太簡單的密碼在后邊保存的時候會導致操作失敗irb(main):002:0> user.password = 'xxx'=> "xxx"
設(shè)置確認密碼irb(main):003:0> user.password_confirmation = 'xxx'=> "xxx"
保存irb(main):004:0> user.save!=> true
退出控制臺irb(main):005:0> exit
關(guān)鍵詞:版本,服務,操作
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。