搭建Gerrit

1.建立gerrit用戶

[root@localhost highgo]# adduser gerrit -m
[root@localhost highgo]# passwd gerrit
Changing password for user gerrit.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost highgo]#

2.安裝gerrit

[gerrit@localhost ~]$ pwd
/home/gerrit
[gerrit@localhost ~]$ ll
total 47236
-rwxr--r--. 1 gerrit gerrit 48365806 Jan 24 21:49 gerrit-2.12.4.war
[gerrit@localhost ~]$ java -jar gerrit-2.12.4.war init -d ~/gerrit_site

3.安裝設置

Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2018-01-24 21:51:35,355] [main] INFO  com.google.gerrit.server.config.GerritServerConfigProvider : No /home/gerrit/gerrit_site/etc/gerrit.config; assuming defaults

*** Gerrit Code Review 2.12.4
*** 

Create '/home/gerrit/gerrit_site' [Y/n]? 

*** Git Repositories
*** 

Location of Git repositories   [git]: 

*** SQL Database
*** 

Database server type           [h2]: 

*** Index
*** 

Type                           [LUCENE/?]: 

*** User Authentication
*** 

Authentication method          [OPENID/?]: http
Get username from custom HTTP header [y/N]? 
SSO logout URL                 : 
Enable signed push support     [y/N]? 

*** Review Labels
*** 

Install Verified label         [y/N]? 

*** Email Delivery
*** 

SMTP server hostname           [localhost]: 
SMTP server port               [(default)]: 
SMTP encryption                [NONE/?]: 
SMTP username                  : 

*** Container Process
*** 

Run as                         [gerrit]: 
Java runtime                   [/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre]: 
Copy gerrit-2.12.4.war to /home/gerrit/gerrit_site/bin/gerrit.war [Y/n]? 
Copying gerrit-2.12.4.war to /home/gerrit/gerrit_site/bin/gerrit.war

*** SSH Daemon
*** 

Listen on address              [*]: 
Listen on port                 [29418]: 

Gerrit Code Review is not shipped with Bouncy Castle Crypto SSL v152
  If available, Gerrit can take advantage of features
  in the library, but will also function without it.
Download and install it now [Y/n]? 
Downloading http://repo2.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.52/bcpkix-jdk15on-1.52.jar ... OK
Checksum bcpkix-jdk15on-1.52.jar OK

Gerrit Code Review is not shipped with Bouncy Castle Crypto Provider v152
** This library is required by Bouncy Castle Crypto SSL v152. **
Download and install it now [Y/n]? 
Downloading http://repo2.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.52/bcprov-jdk15on-1.52.jar ... OK
Checksum bcprov-jdk15on-1.52.jar OK
Generating SSH host key ... rsa... dsa... done

*** HTTP Daemon
*** 

Behind reverse proxy           [y/N]? 
Use SSL (https://)             [y/N]? 
Listen on address              [*]: 
Listen on port                 [8080]: 8081
Canonical URL                  [http://localhost:8081/]: 

*** Plugins
*** 

Installing plugins.
Install plugin commit-message-length-validator version v2.12.4 [y/N]? 
Install plugin download-commands version v2.12.4 [y/N]? 
Install plugin replication version v2.12.4 [y/N]? 
Install plugin reviewnotes version v2.12.4 [y/N]? 
Install plugin singleusergroup version v2.12.4 [y/N]? 
Initializing plugins.
No plugins found with init steps.

Initialized /home/gerrit/gerrit_site
Executing /home/gerrit/gerrit_site/bin/gerrit.sh start
Starting Gerrit Code Review: OK
Waiting for server on localhost:8081 ... OK
Opening http://localhost:8081/#/admin/projects/ ...No protocol specified
FAILED
Open Gerrit with a JavaScript capable browser:
  http://localhost:8081/#/admin/projects/
[gerrit@localhost ~]$

4.yum安裝Nginx(未能成功運行,緣由不明,推薦源碼安裝)

[root@localhost highgo]# yum install -y nginx

配置文件位置:php

[root@localhost highgo]# cd /etc/nginx/
[root@localhost nginx]# ll
total 60
drwxr-xr-x. 2 root root    6 Oct 18 04:12 conf.d
drwxr-xr-x. 2 root root    6 Oct 18 04:12 default.d
-rw-r--r--. 1 root root 1077 Oct 18 04:09 fastcgi.conf
-rw-r--r--. 1 root root 1077 Oct 18 04:09 fastcgi.conf.default
-rw-r--r--. 1 root root 1007 Oct 18 04:09 fastcgi_params
-rw-r--r--. 1 root root 1007 Oct 18 04:09 fastcgi_params.default
-rw-r--r--. 1 root root 2837 Oct 18 04:09 koi-utf
-rw-r--r--. 1 root root 2223 Oct 18 04:09 koi-win
-rw-r--r--. 1 root root 3957 Oct 18 04:09 mime.types
-rw-r--r--. 1 root root 3957 Oct 18 04:09 mime.types.default
-rw-r--r--. 1 root root 2467 Oct 18 04:09 nginx.conf
-rw-r--r--. 1 root root 2656 Oct 18 04:09 nginx.conf.default
-rw-r--r--. 1 root root  636 Oct 18 04:09 scgi_params
-rw-r--r--. 1 root root  636 Oct 18 04:09 scgi_params.default
-rw-r--r--. 1 root root  664 Oct 18 04:09 uwsgi_params
-rw-r--r--. 1 root root  664 Oct 18 04:09 uwsgi_params.default
-rw-r--r--. 1 root root 3610 Oct 18 04:09 win-utf
[root@localhost nginx]#

修改方法與源碼安裝相同html

5. 源碼安裝Nginx

[highgo@localhost ~]$ tar zxvf nginx-1.13.8.tar.gz
[highgo@localhost ~]$ cd nginx-1.13.8
[highgo@localhost nginx-1.13.8]$ ./configure --prefix=/opt/nginx/
[highgo@localhost nginx-1.13.8]$ make
[highgo@localhost nginx-1.13.8]$ su
Password: 
[root@localhost nginx-1.13.8]# make install
[root@localhost nginx-1.13.8]# cd /opt/nginx/conf/
[root@localhost conf]# vi nginx.conf
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
	server {
	     listen *:81;
	     server_name _;
	     allow   all;
	     deny    all;

	     auth_basic "Welcomme to Gerrit Code Review Site!";
	     auth_basic_user_file /home/gerrit/gerrit.password;

	     location / {
		proxy_pass  http://127.0.0.1:8081;
		proxy_set_header X-Forwarded-For $remote_addr;
		proxy_set_header Host $host;
	     }
	   }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

添加部分java

server {
	     listen *:81;
	     server_name _;
	     allow   all;
	     deny    all;

	     auth_basic "Welcomme to Gerrit Code Review Site!";
	     auth_basic_user_file /home/gerrit/gerrit.password;

	     location / {
		proxy_pass  http://127.0.0.1:8081;
		proxy_set_header X-Forwarded-For $remote_addr;
		proxy_set_header Host $host;
	     }
	   }

6. 建立登陸認證文件

[gerrit@localhost ~]$ htpasswd -c /home/gerrit/gerrit.password admin
New password: 
Re-type new password: 
Adding password for user admin
[gerrit@localhost ~]$

htpasswd是apache的一個模塊,須要先安裝apache服務,經過如下任意一個安裝nginx

[root@localhost nginx]# yum install httpd-tools //單獨安裝部分工具
[root@localhost nginx]# yum install httpd //安裝完整的apache

設置權限git

[gerrit@localhost ~]$ cd /home/
[gerrit@localhost home]$ ll
total 8
drwx------.  5 gerrit gerrit  170 Jan 24 22:12 gerrit
drwx------. 10 git    git    4096 Jan 24 21:36 git
drwx------. 14 highgo highgo 4096 Jan 24 21:48 highgo
[gerrit@localhost home]$ chmod 755 gerrit/

如未設置權限會出現沒法訪問的問題:apache

2018/01/24 22:23:35 [error] 3702#0: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.81.1, server: _, request: "GET /favicon.ico HTTP/1.1", host: "192.168.81.163", referrer: "http://192.168.81.163/"
2018/01/24 22:23:44 [crit] 3702#0: *2 open() "/home/gerrit/gerrit.password" failed (13: Permission denied), client: 192.168.81.1, server: _, request: "GET / HTTP/1.1", host: "192.168.81.163:81"
2018/01/24 22:23:45 [crit] 3702#0: *3 open() "/home/gerrit/gerrit.password" failed (13: Permission denied), client: 192.168.81.1, server: _, request: "GET /favicon.ico HTTP/1.1", host: "192.168.81.163:81", referrer: "http://192.168.81.163:81/"

7. 配置gerrit.config

[gerrit@localhost etc]$ pwd
/home/gerrit/gerrit_site/etc
[gerrit@localhost etc]$ ll
total 28
-rw-rw-r--. 1 gerrit gerrit  452 Jan 24 21:53 gerrit.config
drwxrwxr-x. 2 gerrit gerrit 4096 Jan 24 21:53 mail
-rw-------. 1 gerrit gerrit   71 Jan 24 21:52 secure.config
-rw-------. 1 gerrit gerrit  672 Jan 24 21:52 ssh_host_dsa_key
-rw-r--r--. 1 gerrit gerrit  618 Jan 24 21:52 ssh_host_dsa_key.pub
-rw-------. 1 gerrit gerrit 1675 Jan 24 21:52 ssh_host_rsa_key
-rw-r--r--. 1 gerrit gerrit  410 Jan 24 21:52 ssh_host_rsa_key.pub
[gerrit@localhost etc]$ vi gerrit.config
[gerrit]
        basePath = git
        canonicalWebUrl = http://192.168.81.186:8081/
[database]
        type = h2
        database = /home/gerrit/gerrit_site/db/ReviewDB
[index]
        type = LUCENE
[auth]
        type = HTTP
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = localhost
[container]
        user = gerrit
        javaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = proxy-http://*:8081/
[cache]
        directory = cache

8. 重啓gerrit

[gerrit@localhost etc]$ /home/gerrit/gerrit_site/bin/gerrit.sh restart
Stopping Gerrit Code Review: OK
Starting Gerrit Code Review: OK

9. 啓動nginx

[root@localhost sbin]# /opt/nginx/sbin/nginx

10. 訪問

http://192.168.81.163:81 //根據實際狀況修改IP和端口
相關文章
相關標籤/搜索