代碼審查服務gerrit搭建+httpd反向代理

一、安裝依賴:

安裝java8依賴

[root@localhost ~]# yum install java-1.8.0-openjdk* -y

安裝git依賴

[root@localhost ~]# yum install git

二、安裝httpd反向代理

[root@localhost ~]# yum install httpd

三、搭建gerrit

1.創建gerrit用戶

[root@localhost ~]# adduser gerrit

2.切換到gerrit用戶中

[root@localhost ~]# su gerrit

3.下載安裝包

在該鏈接下載到本地。https://gerrit-releases.storage.googleapis.com/index.html 

博主下的gerrit版本是2.13.4版本的。利用xftp上傳gerrit安裝包gerrit-2.13.4.war到/home/gerrit目錄下

 

4.切換回root用戶,輸入密碼

[gerrit@localhost ~]# su root

5.進入到/home/gerrit目錄下

[root@localhost ~]# cd /home/gerrit

6.查看是否有gerrit-2.13.4.war安裝包

[root@localhost ~]# ls

7.有安裝包的話,進行安裝,安裝過程會讓你選擇,只是在讓你選擇Authentication method方式時輸入http。其他的默認回車就好 。安裝命令如下

[root@localhost gerrit]# java -jar gerrit-2.13.4.war init -d /home/gerrit/gerrit_site

當下載過程中,出現這句話的時候說明再下載東西,彆着急,等一會,時間會長些

Downloading http://www.bouncycastle.org/download/bcpkix-jdk15on-151.jar ...

會下載如下兩個文件,大概不到3M,有時候下載會中斷或者失敗,可以查看/home/gerrit/gerrit_site/lib目錄下的兩個文件,如果文件大小接近3M,那說明下載成功,如果差距很大,那就刪除gerrit_site文件,重新安裝。博主安裝整個流程不下5次,知道這裏有時候失敗次數會較多,不要放棄,重啓虛擬機再試,總有一次會成功的。

 

8.關閉防火牆或者給防火牆開啓指定8080端口號,我爲了省事直接關閉了防火牆

[root@localhost etc]# systemctl stop firewalld

9.打開自己瀏覽器輸入虛擬機的ip地址後面跟:8080端口號,出現這個界面表示前面gerrit搭建的步驟是成功的

10.進入/etc/httpd/conf.d路徑下

[root@localhost etc]# cd /etc/httpd/conf.d

11.創建配置文件gerrit.conf,httpd根據這個文件進行路由跳轉,反向代理

[root@localhost conf.d]# touch gerrit.conf

12.修改配置文件

[root@localhost conf.d]# vi gerrit.conf

配置文件內容如下。將xxx改成自己的ip地址

ServerName xxx.xxx.xxx.xxx
<VirtualHost *:80>
    ProxyRequests Off
    ProxyVia Off
    ProxyPreserveHost On
    AllowEncodedSlashes On
 
    <Proxy *>
          Order deny,allow
          Allow from all
    </Proxy>
 
    <Location /login/>
        AuthType Basic
        AuthName "Gerrit Code Review"
        Require valid-user
        AuthBasicProvider file
        AuthUserFile /etc/httpd/conf.d/gerritpw
    </Location>
    ProxyPass / http://xxx.xxx.xxx.xxx:8080/ 
</VirtualHost>

14.創建配置文件,用戶根據這個文件中的用戶密碼限制登陸

[root@localhost conf.d]# touch gerritpw

15.在該路徑下輸入命令,創建登錄用戶

[root@localhost conf.d]# htpasswd -b /etc/httpd/conf.d/gerritpw admin 123456

16.重啓httpd

[root@localhost conf.d]# systemctl restart httpd

17.打開自己瀏覽器輸入虛擬機的ip地址,直接回車。出現503錯誤,這是正常現象

18.輸入下面命令

[root@localhost conf.d]# /usr/sbin/setsebool httpd_can_network_connect 1

最後刷新頁面,輸入賬號admin密碼123456即可成功,第一次進入顯示無頁面,在輸入ip地址刷新下頁面就成功了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章