Install the brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Nginx

/ / install nginx $brew install nginx / / view nginx version $brew - v / / view nginx service process $ps - ef | grep nginx open nginx service $nginx / / / / Stop nginx service $nginx-sStop // reload $nginx-s reload
Copy the code

Download the Gerrit

  • Gerrit historical version download address

Install the Gerrit

$java-jar gerrit-2.15.1.war init-d~/gerrit_site Using secure store: . Com. Google. Gerrit server. Securestore. * * * DefaultSecureStore gerrit Code Review 2.15.1 Git Repositories * * * * * * * * * Location of Git repositories [git]: *** SQL Database *** Database servertype[mysql]: h2 *** Index *** Type [lucene/?] : *** User Authentication *** Authentication method [http/?] : http Supported options are: openid openid_sso http http_ldap client_ssl_cert_ldap ldap ldap_bind custom_extension development_become_any_account Get  username from custom HTTP header [y/N]? SSOlogoutURL : Enable signed push support [y/N]? *** Review Labels *** Install Verified label [y/N]? Y *** Email Delivery *** SMTP server hostname [localhost]: SMTP server port [(default)]: SMTP encryption [none/?] : SMTP username : *** Container Process *** Run as [wangyanan]: Java runtime [/ Library/Java/JavaVirtualMachines jdk1.8.0 _161. JDK/Contents/Home/jre] : Upgrade /Users/wangyanan/gerrit_site/bin/gerrit.war [Y/n]? Copying Gerrit-2.15.1. war to /Users/wangyanan/gerrit_site/bin/gerrit.war *** SSH Daemon *** Listen on address [*]: Listen on port [29418]: *** HTTP Daemon *** Behind reverse proxy [y/N]? Use SSL (https://) [y/N]? Listen on address [*]: Listen on port [8080]: Canonical URL [http://localhost:8080/]: *** Cache *** *** Plugins *** Installing Plugins. Install plugin commit-message-length-validator version v2.15.1 [Y/n]? Commit -message-length-validator v2.15.1 is already installed, overwrite it [Y/n]? Updated commit-message-length-validator to v2.15.1 Install plugin download-commands version v2.15.1 [Y/n]? Download-commands V2.15.1 is already installed, overwrite it [Y/n]? Updated download-Commands to v2.15.1 Install Plugin hooks version v2.15.1 [Y/n]? Hooks v2.15.1 is already installed, overwrite it [Y/n]? Updated hooks to V2.15.1 Install Plugin replication version v2.15.1 [Y/n]? Replication V2.15.1 is already installed, overwrite it [Y/n]? Updated replication to v2.15.1 Install Plugin reviewNotes version v2.15.1 [Y/n]? Reviewnotes v2.15.1 is already installed, overwrite it [Y/n]? Updated reviewNotes to v2.15.1 Install Plugin singleUserGroup version v2.15.1 [Y/n]? Singleusergroup v2.15.1 is already installed, overwrite it [Y/n]? Updated singleusergroup to V2.15.1 Initializing plugins. *** Experimental features *** Enable any Experimental features [y/N]? Initialized /Users/wangyanan/gerrit_site Executing /Users/wangyanan/gerrit_site/bin/gerrit.sh start Starting Gerrit Code  Review: OK Waitingfor server on localhost:8080 ... OK
Opening http://localhost:8080/#/admin/projects/ ... OK
Copy the code

Configuration Gerrit

  • Modify the ~/gerrit_site/etc/gerrit.config configuration file
[gerrit] basePath = git canonicalWebUrl = http://127.0.0.1:8080/ //nginx proxy port......... [httpd] listenUrl = http://*:8080/Copy the code
  • Add ~/gerrit_site/etc/gerrit.password configuration file
// Add administrator account gerrit $htpasswd -c gerrit~/gerrit_site/etc/gerrit.password gerritCopy the code

Configure Nginx

  • Modify/usr/local/etc/nginx/nginx. Conf configuration file
http {
    include       mime.types;
    default_type  application/octet-stream;
    
    server {
        listen       7780;
        server_name  127.0.0.1;
        allow   all;
        deny    all;

        #charset koi8-r;

        #access_log logs/host.access.log main;

        location / {
            auth_basic "Welcomme to Gerrit Code Review Site!"; auth_basic_user_file ~/gerrit_site/etc/gerrit.password; // AuthUserFile path proxy_pass http://127.0.0.1:8080; // Do not add"/"Otherwise, "Code Review - Error The page you requested was not found...." is displayed Permission to view this page proxy_set_header x-Forwarded-for$remote_addr;
            proxy_set_header  Host $host;
        }
    }

    include servers/*;
}
Copy the code

Start Nginx and Gerrit

$ nginx -sReload $gerrit.sh restart // Note: If no environment variables are added, only sh can be accessed using an absolute path in configuration ~/. Bash_profile.Copy the code

Normally, visit http://127.0.0.1:7780/ and then enter the Gerrit administrator password in the pop-up dialog box to access the Gerrit service of http://127.0.0.1:8080/.

Configure the Gerrit mail system

  • Modify the ~/gerrit_site/etc/gerrit.config configuration file
[sendemail]
	smtpServer = smtp.163.com
	smtpServerPort = 465
	smtpEncryption = ssl
	sslVerify = falseSmtpUser = Sender email address from = Sender email addressCopy the code
  • Modify the ~/gerrit_site/etc/secure.config configuration file
[sendemail] smtpPass = Mailbox login passwordCopy the code

Gerrit connects to GitWeb (failed)

  1. Gitweb installation —-> git-gitWeb documentation
  2. Gerrit parameter configuration
$ git config --file ~/gerrit_site/etc/gerrit.config gitweb.cgi /var/www/gitweb/gitweb.cgi $ git config --file ~/gerrit_site/etc/gerrit.config --unset gitweb.url $ cat ~/gerrit_site/etc/gerrit.config [gerrit] basePath = git serverId = 375c686a-b8d3-4798-934f-01e5d532dae9 canonicalWebUrl = http://localhost:8080/ ... . [gitweb] cgi = /var/www/gitweb/gitweb.cgiCopy the code

Pay attention to

When creating the first user with htpasswd, the default user is the system administrator whose ID is 1000000. By default, only the system administrator has the Create permission (Create group and Project), and only the List permission for other users

When a user is created with htpasswd, no account is added to Gerrit. The account is added to the Gerrit database only when the user logs in to the Gerrit server via the Web.

Log Out of the admin account and log in again. (Sign Out is not supported in HTTP authentication mode. You need to Sign Out of the account first and close the browser before logging in to display the HTTP password verification dialog box.

Setting up the Linux Environment

—-> Please refer to [original]CI Continuous Integration System Environment – Deployment Gitlab environment for a complete record