Come installare Gerrit2 su CentOS 7. Gerrit è un'applicazione di revisione del codice basata sul Web che utilizza il sistema di controllo della versione Git. Gerrit semplifica la revisione del codice generando le modifiche al codice in un'anteprima affiancata, consentendo commenti in linea che possono essere aggiunti da un revisore. Gerrit consente a qualsiasi utente autorizzato di inviare modifiche al repository Git principale, il che semplifica il processo quando una modifica approvata deve essere unita manualmente dal manutentore del progetto.
Requisiti di sistema?
- Un hosting VPS Linux
- JAVA JDK superiore a 1.7
- Server di database
- Server Web
- GIT
- Sistema operativo CentOS 7
1. AGGIORNAMENTO DEL SISTEMA
La prima cosa da fare è SSH
sul tuo server, avvia una screen
sessione e assicurati che il tuo CentOS 7 VPS sia completamente aggiornato eseguendo:
## screen -U -S gerrit-screen ## yum update
installa git e vim
## yum install git vim
2. INSTALLA JAVA
Successivamente, JAVA è necessario per l'installazione di Gerrit, quindi scarica l'ultima versione di JAVA da qui. Al momento della stesura di questo articolo l'ultima versione di JAVA è 8u25 e può essere scaricata e installata utilizzando i seguenti comandi:
per sistemi a 64 bit:
## wget --no-cookies \ --no-check-certificate \ --header "Cookie: oraclelicense=accept-securebackup-cookie" \ "http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.rpm" \ -O /opt/jdk-8-linux-x64.rpm
per sistemi a 32 bit:
## wget --no-cookies \ --no-check-certificate \ --header "Cookie: oraclelicense=accept-securebackup-cookie" \ "http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-i586.rpm" \ -O /opt/jdk-8-linux-i586.rpm
una volta scaricato il pacchetto JAVA, installalo usando yum
come segue:
per sistemi a 32 bit utilizzare:
## yum install /opt/jdk-8-linux-i586.rpm
per sistemi a 64 bit utilizzare:
## yum install /opt/jdk-8-linux-x64.rpm
configura il pacchetto JAVA usando alternatives
come in:
## JDK_DIRS=($(ls -d /usr/java/jdk*)) ## JDK_VER=${JDK_DIRS[@]:(-1)} ## alternatives --install /usr/bin/java java /usr/java/"${JDK_VER##*/}"/jre/bin/java 20000 ## alternatives --install /usr/bin/jar jar /usr/java/"${JDK_VER##*/}"/bin/jar 20000 ## alternatives --install /usr/bin/javac javac /usr/java/"${JDK_VER##*/}"/bin/javac 20000 ## alternatives --install /usr/bin/javaws javaws /usr/java/"${JDK_VER##*/}"/jre/bin/javaws 20000 ## alternatives --set java /usr/java/"${JDK_VER##*/}"/jre/bin/java ## alternatives --set javaws /usr/java/"${JDK_VER##*/}"/jre/bin/javaws ## alternatives --set javac /usr/java/"${JDK_VER##*/}"/bin/javac ## alternatives --set jar /usr/java/"${JDK_VER##*/}"/bin/jar
controlla la versione JAVA in esecuzione sul tuo sistema:
## java -version
3. INSTALLA MARIADB (MYSQL)
Installa MariaDB, il server di database predefinito in CentOS 7 che è un sostituto drop-in per MySQL usando yum
:
## yum install mariadb mariadb-server mysql
Una volta installato, modifica il suo file di configurazione del server in /etc/my.cnf.d/server.cnf
e aggiungi quanto segue:
## vim /etc/my.cnf.d/server.cnf [mysqld] #log-bin=mysql-bin #binlog_format=mixed bind-address = 127.0.0.1
Avvia e aggiungi MariaDB all'avvio del tuo sistema usando systemctl
:
## systemctl restart mariadb ## systemctl status mariadb ## systemctl enable mariadb
Facoltativamente ma consigliato, esegui mysql_secure_installation
per finalizzare l'installazione di MariaDB:
## mysql_secure_installation Enter current password for root (enter for none): ENTER Set root password? [Y/n] Y Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y
4. INSTALLA GERRIT
Crea un database
È necessario creare un utente e un database e concedere i privilegi sul database all'utente appena creato. Puoi farlo usando i seguenti comandi:
## mysql -u root -p MariaDB> create database gerritdb; MariaDB> grant all on gerritdb.* to gerrit@localhost identified by 'secret';
Inizializza il sito
Gerrit archivia i file di configurazione, le chiavi SSH del server e i repository Git gestiti in una directory locale. Si consiglia di eseguire Gerrit Code Review come account utente separato sul sistema, quindi creiamo prima un nuovo utente e accediamo con l'utente appena creato:
## useradd -m gerrit2 ## su - gerrit2
Scarica gerrit
Puoi scaricare gerrit usando il comando seguente:
## wget https://gerrit-releases.storage.googleapis.com/gerrit-2.9.1.war -O /home/gerrit2/gerrit.war
una volta scaricato il file war di gerrit2 e dopo aver effettuato l'accesso come gerrit2
, esegui il comando seguente per inizializzare una nuova directory del sito:
## java -jar gerrit.war init -d /home/gerrit2/review_site
riempi le domande poste dalla procedura guidata, ad esempio:
Location of Git repositories [git]: Database server type [mysql]: Server hostname [localhost]: Server port [(mysql default)]: Database name [gerritdb]: Database username [gerrit]: Change gerrit's password [y/N]? n Type [LUCENE/?]: Authentication method [HTTP/?]: Get username from custom HTTP header [y/N]? SSO logout URL : Install Verified label [y/N]? SMTP server hostname [localhost]: SMTP server port [(default)]: SMTP encryption [NONE/?]: SMTP username : Run as [gerrit2]: Java runtime [/usr/java/jdk1.8.0_25/jre]: Upgrade /home/gerrit2/review_site/bin/gerrit.war [Y/n]? Copying gerrit.war to /home/gerrit2/review_site/bin/gerrit.war Listen on address [*]: Listen on port [29418]: Behind reverse proxy [Y/n]? Proxy uses SSL (https://) [y/N]? Subdirectory on proxy server [/gerrit/]: Listen on address [*]: Listen on port [8081]: Canonical URL [http://vs377.rosehosting.com/gerrit/]: Install plugin commit-message-length-validator version v2.9.1 [y/N]? Install plugin download-commands version v2.9.1 [y/N]? Install plugin replication version v2.9.1 [y/N]? Install plugin reviewnotes version v2.9.1 [y/N]? Install plugin singleusergroup version v2.9.1 [y/N]? Initialized /home/gerrit2/review_site
quindi, esegui il comando seguente per ricostruire l'indice gerrit:
## java -jar gerrit.war reindex -d /home/gerrit2/review_site
e avvia il gerrit usando il comando seguente:
## /home/gerrit2/review_site/bin/gerrit.sh start
esci su root eseguendo exit
comando.
5. INSTALLA APACHE
Installa Apache usando yum
:
## yum install httpd httpd-tools openssl mod_ssl
Aggiungi quanto segue a /etc/httpd/conf.d/options.conf
## vim /etc/httpd/conf.d/options.conf TraceEnable off ## Disable Signature ServerSignature Off ## Disable Banner ServerTokens Prod
## vim /etc/httpd/conf.d/vhosts.conf # Load my vhosts IncludeOptional vhosts.d/*.conf
## mkdir /etc/httpd/vhosts.d
Riavvia Apache e aggiungilo per l'avvio automatico all'avvio del tuo sistema utilizzando:
## systemctl restart httpd ## systemctl status httpd ## systemctl enable httpd
6. APACHE PROXY A GERRIT
## vim /etc/httpd/vhosts.d/gerrit.conf <VirtualHost your_ip_address:80> ServerName your_hostname ProxyRequests Off ProxyVia Off ProxyPreserveHost On <Proxy *> Order deny,allow Allow from all </Proxy> <Location /gerrit/login/> AuthType Basic AuthName "Gerrit Code Review" Require valid-user AuthUserFile '/etc/httpd/gerrit.htpasswd' </Location> AllowEncodedSlashes On ProxyPass /gerrit/ http://your_ip_address:8081/gerrit/ </VirtualHost>
crea utente usando htpasswd
## htpasswd -c /etc/httpd/gerrit.htpasswd admin New password: Re-type new password: Adding password for user admin
riavvia Apache usando
## systemctl restart httpd
quindi, vai a http://nome_host/gerrit/ e dovresti caricare l'applicazione di revisione Gerrit nel tuo browser.
Cosa c'è dopo?
- Configurazione del progetto
- Flusso di lavoro Gerrit
Ovviamente non devi installare Gerrit2 su CentOS 7, se utilizzi uno dei nostri servizi di hosting VPS CentOS, nel qual caso puoi semplicemente chiedere ai nostri esperti amministratori Linux di installare Gerrit2 su CentOS 7 per te. Sono disponibili 24 ore su 24, 7 giorni su 7 e si prenderanno immediatamente cura della tua richiesta.
PS. Se ti è piaciuto questo post su come installare Gerrit2 su CentOS 7, condividilo con i tuoi amici sui social network utilizzando i pulsanti a sinistra o semplicemente lascia una risposta qui sotto. Grazie.