新方法:
# install rpm source: the path took through INSTALL file
sudo rpm -i https://gerritforge.com/gerritforge-repo-1-2.noarch.rpm
#install gerrit
sudo yum install -y gerrit
会安装到/var/gerrit目录下。
Init gerrit configuration (can be run multiple times, options are saved).
java -jar /var/gerrit/bin/gerrit.war init
Launch:
java -jar /var/gerrit/bin/gerrit.war daemon --console
之前的方法:
文档:https://gerrit-review.googlesource.com/Documentation/linux-quickstart.html
jar包:https://gerrit-releases.storage.googleapis.com/index.html
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum -y install java-1.8.0-openjdk postfix mailx mariadb mariadb-server httpd nginx net-tools lrzsz
java、mariadb httpd nginx是必须的。
root账户下:
useradd gerrit -m -d /home/gerrit
passwd gerrit
设置密码为123456
(postfix是用来发邮件的)
systemctl start postfix
systemctl enable postfix
测试:echo "content" | mail -s "title" guang11cheng@qq.com
systemctl start mariadb
systemctl enable mariadb
初始化root密码:
mysql_secure_installation
mysql -uroot -p
mysql>create user gerrit@localhost identified by '123456';
mysql>create database reviewdb CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql>grant all on reviewdb.* to 'gerrit'@'localhost' identified by '123456';
su gerrit
cd
cp gerrit-2.15.1.war /home/gerrit/
java -jar gerrit-2.15.1.war init -d gerrit_site/
除了选用mysql数据库,Verified Label,http认证代理,Canonical URL改为:http://实际ip地址:端口/,安装插件,其他的都是一路回车。
cd /etc/nginx/conf.d
vi gerrit.conf
server {
listen 80; # Canonical URL中的端口要与这个一致
server_name localhost;
location / {
auth_basic "Gerrit Code Review";
auth_basic_user_file /home/gerrit/gerrit_site/etc/passwords;
proxy_pass http://127.0.0.1:8080; # gerrit实际监听的端口
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
3.0版本的安装好就能启动,不需要防火墙的设置了。
mv default.conf default.conf-bak
su root
setfacl -m g:nginx:rx /home/gerrit/
setfacl -m g:nginx:rx /home/gerrit/gerrit_site/
systemctl start nginx
systemctl enable nginx
查看nginx日志:tail -f /var/log/nginx/error.log
2018/04/24 01:33:00 [crit] 1947#1947: *1 open() "/home/gerrit/gerrit_site/etc/passwords" failed (13: Permission denied), client: 192.168.8.1, server: localhost, request: "GET / HTTP/1.1", host: "192.168.8.128"
关闭防火墙和selinux:
su root
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
vi /etc/selinux/config
把SELINUX=enforcing 改成 SELINUX=disabled
reboot
su gerrit
cd /home/gerrit/gerrit_site/etc
htpasswd -c passwords admin
/// 其他
删除用户:
mysql>use mysql;
mysql>Delete FROM user Where User='gerrituser' and Host='localhost';
mysql>flush privileges;
mysql>drop user gerrituser@localhost;