CentOS7 builds the gerrit code review service method

  • 2020-10-31 22:04:35
  • OfStack

Step 1: Create a dedicated account and working directory

adduser gerrit; passwd gerrit; Create a dedicated gerrit working directory: mkdir /home/gerrit

Step 2: Configure the Java environment

1) download from the website JDK: http: / / download oracle. com/otn - pub/java/jdk - nb / 8 u161-8.2 / jdk - 8 u161 - nb - 8 _2 - linux - x64. sh

2) Add execution permissions chmod a+x ES38en-8u161-ES40en-8_2-ES41en-ES42en64.sh, and then run the script installation

3) Set the environment variable, edit /etc/profile or ~/.bashrc file to add the following configuration at the end of the file


export JAVA_HOME=/usr/local/jdk1.8.0_161
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$CLASSPATH

4) Test the Java environment and input java-ES54en at the terminal to check whether the version information is displayed normally. If it is displayed, the installation is successful

Step 3: Download and install gerrit

1) download from the website gerrit: http: / / code google. com p/gerrit/stored in/home/gerrit directory

2) Installation of gerrit: ES72en-ES73en ES74en-ES75en-2.5.2.ES76en ES77en-ES78en review_site, enter 1, default installation

3) Modify the gerrit configuration file, which explains as follows:


[gerrit]
    basePath = git   // Specified by gerrit All managed git Inventory position, i.e review_site_project/git/
    canonicalWebUrl = http://192.168.0.20:8081/  // The specified web access gerrit The website of // Fill in your own ip And port number 
[database]
    type = h2     // The specified gerrit The default database type can be selected mysql , install and create gerrit account 
    database = db/ReviewDB   
[auth]
    type = HTTP  // Specify browser login gerrit When the authentication method 
[sendemail]
    enable = true
    smtpServer = smtp.126.com
    smtpServerPort = 25
    smtpUser = xxx@126.com
    smtpPass = xxx
    sslVerify = false
    from = CodeReview<xxx@126.com>
[container]
    user = gerritserver            // The specified gerrit The identity of the user on the machine corresponds to the user created above 1 to 
    javaHome = /usr/lib/jvm/jdk7/jre      // The system itself 
[sshd]
    listenAddress = *:29418     // The specified sshd The port number on which the service listens 
[httpd]
    listenUrl = http://*:8081/project      // The specified http Address of the agent 
[cache]
    directory = cache   // The cache location 

4) start gerrit service: review_site/bin/gerrit sh start | stop | restart

If the following error occurs: ** ERROR: GERRIT_SITE not set

It may be modified as follows :vim ES106en.ES107en

Add the following line after the GERRIT_SITE variable is assigned to change the value of the variable.

GERRIT_SITE=/home/gerrit/review_site

5) startup: ln - snf home/gerrit review_site/bin/gerrit sh/etc/init d/gerrit sh

Step 4: Configure the reverse proxy service (Nginx)

1) Install the Nginx reverse proxy server

Install gcc: yum install gcc-ES143en ++

Install PCRE: yum ES148en-ES149en pcre ES151en-ES152en

Install zlib: yum ES157en-ES158en zlib ES160en-ES161en

Install openssl: yum ES166en-ES167en openssl ES169en-ES170en

Download nginx: https: / / nginx org/en/download html

Nginx: tar-ES184en nginx-1.13.7.tar.gz; cd nginx - 1.13.7; ./configure; make; make install

Startup: vi/etc/rc local 1 line at the end of file/usr/local/nginx/sbin/nginx

2) configuration nginx: vim/usr/local/nginx/conf/nginx conf


server {
    listen    80;
    server_name localhost;
    #charset koi8-r;
    #access_log logs/host.access.log main;
    location / {
      #root  html;
      #index index.html index.htm;
   auth_basic       "Welcome to Gerrit Code Review !";
      auth_basic_user_file  /home/gerrit/gerrit.passwd;
      proxy_pass       http://127.0.0.1:8081;
      proxy_set_header    X-Forwarded-For $remote_addr;
      proxy_set_header    Host $host;
    }


    #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;
    }

Start Nginx service: / usr/local/nginx/sbin/nginx

3) Set the account and password of the first gerrit user


touch ./review_site/etc/passwd
htpasswd -b ./review_site/etc/passwd gerrit gerrit

Step 5: Test, access: http://192.168.0.20, login with gerrit user


Related articles: