1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        CICD:CentOS 下 GitLab 安裝

        共 11856字,需瀏覽 24分鐘

         ·

        2021-04-07 02:15

        GitLab 是一個(gè)利用 Ruby on Rails 開(kāi)發(fā)的開(kāi)源應(yīng)用程序,實(shí)現(xiàn)一個(gè)自托管的Git項(xiàng)目倉(cāng)庫(kù),可通過(guò) Web 界面進(jìn)行訪(fǎng)問(wèn)公開(kāi)的或者私有的項(xiàng)目。GitLab 擁有與 Github 類(lèi)似的功能,能夠?yàn)g覽源代碼,管理缺陷和注釋??梢怨芾韴F(tuán)隊(duì)對(duì)倉(cāng)庫(kù)的訪(fǎng)問(wèn),它非常易于瀏覽提交過(guò)的版本并提供一個(gè)文件歷史庫(kù)。它還提供一個(gè)代碼片段收集功能可以輕松實(shí)現(xiàn)代碼復(fù)用,便于日后有需要的時(shí)候進(jìn)行查找。


        0x01:yum 方式安裝

        • 基礎(chǔ)依賴(lài)庫(kù)安裝

        yum -y install curl policycoreutils openssh-server openssh-clients postfix
        • 啟動(dòng)ssh服務(wù) & 設(shè)置為開(kāi)機(jī)啟動(dòng)

        systemctl enable sshd && systemctl start sshd
        • 設(shè)置 postfix 開(kāi)機(jī)自啟,并啟動(dòng),postfix 支持 GitLab 發(fā)信功能

        systemctl enable postfix && systemctl start postfix
        • 開(kāi)放 ssh 和 http服務(wù),然后重新加載防火墻列表

        firewall-cmd --add-service=ssh --permanent
        firewall-cmd --add-service=http --permanent
        firewall-cmd --reload

        如果關(guān)閉防火墻就不需要進(jìn)行以上配置

        •  安裝 gitlab-ce

        curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

        yum install -y gitlab-ce

        GitLab 分為 gitlab-ce 社區(qū)版與 gitlab-ee 企業(yè)收費(fèi)版兩個(gè)版本,這里安裝社區(qū)版。由于網(wǎng)絡(luò)問(wèn)題,國(guó)內(nèi)用戶(hù),建議使用清華大學(xué)的鏡像源進(jìn)行安裝。

        添加 yum 源

        vim /etc/yum.repos.d/gitlab-ce.repo

        再打開(kāi)的 /etc/yum.repos.d/gitlab-ce.repo 文件中添加以下內(nèi)容

        #在編輯器中輸入如下內(nèi)容保存
        [gitlab-ce]
        name=gitlab-ce
        baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
        repo_gpgcheck=0
        gpgcheck=0
        enabled=1
        gpgkey=https://packages.gitlab.com/gpg.key

        建立元數(shù)據(jù)緩存,并再次安裝 GitLab

        yum makecache
        yum -y install gitlab-ce

        安裝成功出現(xiàn)以下信息

                                                                                                                                                                   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=13-10

          驗(yàn)證中      : gitlab-ce-13.10.2-ce.0.el7.x86_64                                                                                                                                                              1/1 

        已安裝:
          gitlab-ce.x86_64 0:13.10.2-ce.0.el7                                                                                                                                                                              

        完畢!
        • 修改 GitLab 配置

        vi /etc/gitlab/gitlab.rb
        • 修改 GitLab 訪(fǎng)問(wèn)地址和端口,默認(rèn)為80,改為8082

        external_url 'http://192.168.56.9:8082'
        nginx['listen_port'] = 8082
        • 重新加載配置及啟動(dòng) GitLab 

        gitlab-ctl reconfigure
        gitlab-ctl restart
        • 把 8082 端口添加到防火墻

        firewall-cmd --zone=public --add-port=8082/tcp --permanent
        firewall-cmd --reload

        啟動(dòng)成功后,使用以下命令查看 GitLab 的啟動(dòng)狀態(tài)

        gitlab-ctl status


        看到以上輸出說(shuō)明啟動(dòng)成功

        • 訪(fǎng)問(wèn) http://192.168.56.9:8082

        隨后進(jìn)入修改管理員 root 密碼的頁(yè)面,修改密碼后,然后登錄即可。



        0x02:docker 方式安裝

        • Docker 安裝服務(wù)實(shí)在是太方便,通過(guò) docker 來(lái)安裝 Gitlab,運(yùn)行如下命令查看 Gitlab 的鏡像文件

        docker search gitlab

        看到鏡像有很多,第四個(gè)鏡像是中文版的,英語(yǔ)不好可以安裝中文版的。其實(shí),中文版也就是安裝了一個(gè)語(yǔ)言包而已,有興趣可以自己安裝第一個(gè),然后再手動(dòng)配置中文包。

        • 獲取 GitLab 鏡像

        docker pull gitlab/gitlab-ce

        下載完畢后,先不急著運(yùn)行 GitLab,為了避免容器運(yùn)行時(shí)數(shù)據(jù)丟失,需要使用Docker volume(容器卷)方式來(lái)將數(shù)據(jù)映射到本地,這里創(chuàng)建 /usr/gitlab 目錄來(lái)存放相應(yīng)的數(shù)據(jù),具體對(duì)應(yīng)關(guān)系如下:

        • 啟動(dòng)服務(wù)

        docker run  -d \
            --publish 8443:443 --publish 8090:80 --publish 8022:22 \
            --name gitlab \
            --volume /usr/gitlab/config:/etc/gitlab \
            --volume /usr/gitlab/logs:/var/log/gitlab \
            --volume /usr/gitlab/data:/var/opt/gitlab \
            gitlab/gitlab-ce  

        -d 在后臺(tái)啟動(dòng)

        -publish 8443:443 把容器中應(yīng)用的端口443映射為外部的8443端口

        -publish 8090:80 把容器中應(yīng)用的端口80映射為外部的8090端口

        --name 容器啟動(dòng)之后的名字

        -volume 把容器中的配置,日志,數(shù)據(jù)映射到容器外部

        通過(guò) --name 配置了 GitLab 的名字之后,后續(xù)可以通過(guò)這個(gè) name 對(duì)容器進(jìn)行相關(guān)的啟動(dòng)和停止操作

        • 查看啟動(dòng)情況

        # 添加-a 參數(shù),把啟動(dòng)的,沒(méi)有啟動(dòng)的都列出來(lái)
        docker ps -a

        • 配置Gitlab

        配置時(shí),需要進(jìn)入容器當(dāng)中配置,如果直接修改映射到容器外部的配置文件,總會(huì)出現(xiàn)一些奇怪的問(wèn)題,為了避免出現(xiàn)問(wèn)題所以直接修改容器里的配置文件。

        進(jìn)入容器

        docker exec -it gitlab bash

        修改 /etc/gitlab/gitlab.rb 文件

        vi /etc/gitlab/gitlab.rb

        修改 IP 和端口

        該部分內(nèi)容的修改是為了解決,在 GitLab 創(chuàng)建項(xiàng)目時(shí),項(xiàng)目訪(fǎng)問(wèn)地址是容器id 的問(wèn)題

        # 可以使用/ 來(lái)查找關(guān)鍵字,找到指定的內(nèi)容,然后通過(guò)n來(lái)下一個(gè)查找
        # 在gitlab創(chuàng)建項(xiàng)目時(shí)候http地址的host(不用添加端口)
        external_url 'http://192.168.56.9:80'

        # 在gitlab創(chuàng)建項(xiàng)目時(shí)候ssh地址的host
        gitlab_rails[
        'gitlab_ssh_host'] = '192.168.56.9'(不用添加端口)

        # docker run 的時(shí)候我們把22端口映射為外部的8022了,這里修改下
        gitlab_rails[
        'gitlab_shell_ssh_port'] = 8022

        另外,對(duì)應(yīng) ssh 的 22 端口的映射問(wèn)題,第一種方案就是在 docker 啟動(dòng) gitlab-ce 把 ssh 的 22 端口映射成另外的端口,然后修改 gitlab_shell_ssh_port 配置項(xiàng)為映射時(shí)的端口;另一種方案就是修改 ssh 的默認(rèn)端口。修改 ssh 默認(rèn)端口 22 的操作方案如下:

        通常 gitlab 會(huì)與 gi t配置使用,而 git 會(huì)采用 ssh 協(xié)議來(lái)操作 git 倉(cāng)庫(kù),而 gitlab-ce 連接宿主機(jī)時(shí)也使用 ssh,如果不修改默認(rèn) sshd 端口,git 使用默認(rèn)配置就會(huì)出現(xiàn)問(wèn)題,這里將主機(jī)的 sshd 端口從 22 端口改為其他端口,比如 2280。

        1. 編輯 sshd_config 配置文件

        vi /etc/ssh/sshd_config

        將 #Port 22 注釋去掉,將數(shù)字 22 更改為 2280。

        2. 重啟sshd服務(wù)

        systemctl restart sshd

        3. 配置firewall,使 2280 端口可以對(duì)外提供服務(wù),否則無(wú)法使用 ssh 進(jìn)行遠(yuǎn)程登錄了。

        semanage port -a -t ssh_port_t -p tcp 2280
        firewall-cmd --permanent --add-port=2280/tcp
        firewall-cmd --reload 

        簡(jiǎn)單來(lái)說(shuō)一種就是修改 GitLab 容器相應(yīng)的端口;另外一種就是修改宿主機(jī) sshd 端端口。但生產(chǎn)環(huán)境通常會(huì)不啟用 22 端口,避免被人惡意暴力嘗試

        在 gitlab.rb 文件的最后添加如下配置 [ 也可以不添加 ]

        # 是否啟用
        gitlab_rails['smtp_enable'] = true
        # SMTP服務(wù)的地址
        gitlab_rails['smtp_address'] = "smtp.qq.com"
        # 端口
        gitlab_rails['smtp_port'] = 465
        # 你的QQ郵箱(發(fā)送賬號(hào))
        gitlab_rails['smtp_user_name'] = "[email protected]"
        # 授權(quán)碼
        gitlab_rails['smtp_password'] = "kx1x@123dd"
        # 域名
        gitlab_rails['smtp_domain'] = "smtp.qq.com"
        # 登錄驗(yàn)證
        gitlab_rails['smtp_authentication'] = "login"

        # 使用了465端口,就需要配置下面三項(xiàng)
        gitlab_rails['smtp_enable_starttls_auto'] = true
        gitlab_rails['smtp_tls'] = true
        gitlab_rails['smtp_openssl_verify_mode'] = 'none'

        # 你的QQ郵箱(發(fā)送賬號(hào))
        gitlab_rails['gitlab_email_from'] = '[email protected]'

        重新加載 GitLab 配置

        gitlab-ctl reconfigure

        修改 gitlab.yml 文件

        cd /opt/gitlab/embedded/service/gitlab-rails/config
        #修改port 為8090
        vim gitlab.yml

        重啟 GitLab 服務(wù)

        gitlab-ctl restart

        GitLab 容器啟動(dòng)后,訪(fǎng)問(wèn) http://92.168.56.9:8090 就可以進(jìn)入 GitLab 訪(fǎng)問(wèn)頁(yè)面,第一步要做的就是給 root 用戶(hù)設(shè)置密碼;設(shè)置完后,通過(guò) root + 設(shè)置的密碼就可以登錄。為了方便管理,經(jīng)常創(chuàng)建不同的組,然后通過(guò)不同的組來(lái)管理組下的成員。


        一些常用命令

        gitlab-ctl reconfigure    # 重載配置
        gitlab-ctl check-config    # 檢查配置并啟動(dòng)
        gitlab-ctl diff-config    # 將用戶(hù)配置與包可用配置進(jìn)行比較
        gitlab-ctl status    # 查看所有啟動(dòng)組件的進(jìn)程和狀態(tài)
        gitlab-ctl service-list    # 查看所有服務(wù)
        gitlab-ctl stop    # 停止GitLab服務(wù)
        gitlab-ctl start    # 啟動(dòng)GitLab服務(wù) 
        gitlab-ctl restart    # 重啟GitLab服務(wù) 
        gitlab-ctl once    # 如果GitLab服務(wù)已停止則啟動(dòng)服務(wù),如果GitLab服務(wù)已啟動(dòng)則重啟GitLab服務(wù)

        喜歡,在看



        瀏覽 28
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            麻豆传媒操逼 | 三上悠亚被男上司在线播放 | 大香蕉69 | 拍戏被cao翻了h傅年 | 午夜理论片高潮来了一次又一次 | 动漫美女打扑克网站 | 寡妇高潮免费视频一区二区三区 | 老头将舌头伸进了我的私密部位 | 亚洲中文字幕图 | 免费黄色长视频 |