• 安装配置gerrit


    Centos 安装配置gerrit

    关闭selinux,不然nginx的反向代理会报错connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to upstream,或者使用这个命令:

     

    setsebool -P httpd_can_network_connect 1

     

    关闭selinux:

     

    修改/etc/selinux/config 文件

     

    将SELINUX=enforcing改为SELINUX=disabled

     

    reboot

     

     

    首先安装jdk

     

    yum install java java-devel,如果直接yum install java会自动找到相应的包的,我这里安装的是openjdk的1.7.0版本,目录可以自己看到。

     

    配置java环境变量:

     

    vim /etc/profile

     

    1
    2
    3
    4
    export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.99-2.6.5.0.el7_2.x86_64
    export JRE_HOME=$JAVA_HOME/jre
    export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
    export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

     

    然后source /etc/profile

     

    javac有输出说明安装成功

     

    安装mysql,请看http://www.cnblogs.com/juandx/p/5208613.html

     

    然后给gerrit建一个库,并且授权

     

    复制代码
    mysql> create database gerritdb;
    Query OK, 1 row affected (0.00 sec)
    
    mysql> GRANT ALL PRIVILEGES ON gerritdb.* TO 'gerrituser'@'localhost' IDENTIFIED BY 'gerritpass';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> GRANT ALL PRIVILEGES ON gerritdb.* TO 'gerrituser'@'%' IDENTIFIED BY 'gerritpass';
    复制代码

     

     

    下载gerrit的java包https://www.gerritcodereview.com/download/gerrit-2.12.2.war

     

    然后安装就行啦,这里会提示你很多选择

     

    复制代码
    [gerrit@gerrit ~]$ java -jar gerrit-2.12.2.war init -d review_site
    Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
    
    *** Gerrit Code Review 2.12.2
    *** 
    
    
    *** Git Repositories
    *** 
    
    Location of Git repositories   [/home/gerrit/git]:          这里一定要写git放的目录,没有的话自己会创建的
    
    *** SQL Database
    *** 
    
    Database server type           [mysql]:                     db这个不用说吧
    Server hostname                [localhost]: 
    Server port                    [(mysql default)]: 
    Database name                  [gerritdb]: 
    Database username              [gerrituser]: 
    Change gerrituser's password   [y/N]? 
    
    *** Index
    *** 
    
    Type                           [LUCENE/?]:                          默认就好,直接回车
    
    The index must be rebuilt before starting Gerrit:
      java -jar gerrit.war reindex -d site_path
    
    *** User Authentication
    *** 
    
    Authentication method          [HTTP/?]:                            一定要写http,不然就不是反向代理了,写development_become_any_account就随意登陆了
    Get username from custom HTTP header [Y/n]? n                       一定要n,不然反向代理gerrit报错为缺少一个y的header
    SSO logout URL                 : 
    Enable signed push support     [y/N]? n
    
    *** Email Delivery
    *** 
    
    SMTP server hostname           [smtp.163.com]:                       25端口是163的smtp
    SMTP server port               [25]: 
    SMTP encryption                [NONE/?]: 
    SMTP username                  [littlexiaowen@163.com]: 
    Change littlexiaowen@163.com's password [y/N]? 
    
    *** Container Process
    *** 
    
    Run as                         [gerrit]:                              这是用户,root也可以
    Java runtime                   [/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.99-2.6.5.0.el7_2.x86_64/jre]: 
    Upgrade review_site/bin/gerrit.war [Y/n]? y
    Copying gerrit-2.12.2.war to review_site/bin/gerrit.war
    
    *** SSH Daemon
    *** 
    
    Listen on address              [*]: 
    Listen on port                 [29418]: 
    
    *** HTTP Daemon
    *** 
    
    Behind reverse proxy           [Y/n]? y
    Proxy uses SSL (https://)      [y/N]? n
    Subdirectory on proxy server   [/]: 
    Listen on address              [127.0.0.1]: 
    Listen on port                 [8081]: 
    Canonical URL                  [http://gerrit.wenbin.com]: 
    
    *** Plugins
    *** 
    
    Installing plugins.
    Install plugin singleusergroup version v2.12.2 [Y/n]? y
    version v2.12.2 is already installed, overwrite it [Y/n]? y
    Install plugin commit-message-length-validator version v2.12.2 [Y/n]? y
    version v2.12.2 is already installed, overwrite it [Y/n]? y
    Install plugin reviewnotes version v2.12.2 [Y/n]? y
    version v2.12.2 is already installed, overwrite it [Y/n]? y
    Install plugin replication version v2.12.2 [Y/n]? y
    version v2.12.2 is already installed, overwrite it [Y/n]? y
    Install plugin download-commands version v2.12.2 [Y/n]? y
    version v2.12.2 is already installed, overwrite it [Y/n]? y
    Initializing plugins.
    No plugins found with init steps.
    
    Initialized /home/gerrit/review_site
    [gerrit@gerrit ~]$ vim review_site/etc/gerrit.config 
    [gerrit@gerrit ~]$ vim sshd_log ^C
    [gerrit@gerrit ~]$ ./review_site/bin/gerrit.sh restart
    Stopping Gerrit Code Review: OK
    Starting Gerrit Code Review: OK
    [gerrit@gerrit ~]$
    复制代码

     

     

    没办法,报错了很多,遇到了很多问题,但是也知道了反向代理的原理,httpd和nginx的设置,知道了原来nginx这么好用, 并发量还这么好,以后要多多了解,单线程解决并发速度更快,算法很好,错的越多学的越多吧,一定要多看log啊

     

    /review_gerrit/etc/gerrit.conf

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    [gerrit]
            basePath = /home/gerrit/git
            canonicalWebUrl = http://gerrit.wenbin.com
    [database]
            type = mysql
            hostname = localhost
            database = gerritdb
            username = gerrituser
    [index]
            type = LUCENE
    [auth]
            type = HTTP
    [receive]
            enableSignedPush = false
    [sendemail]
            smtpServer = smtp.163.com
            smtpServerPort = 25
            smtpUser = littlexiaowen@163.com<br>        from=CodeReview<littlexiaowen@163.com>       这行是自己加的,不然注册的时候会提示失败,这里不用写密码,密码是写在security里的另一个文件里
    [container]
            user = gerrit
            javaHome = /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.99-2.6.5.0.el7_2.x86_64/jre
    [sshd]
            listenAddress = *:29418
    [httpd]
            listenUrl = proxy-http://127.0.0.1:8081/
    [cache]
            directory = cache

     

    看到网上有一种修改邮件发送方式的方法:ssh ha gerrit set-account --add-email user99@163.com user99,还没有试过 

     

     

    先生存一个http的认证文件,创建admin用户

     

    # htpasswd -c /passwords admin

     

    然后会提示输入密码

     

     

    安装nginx  yum install nginx

     

    /etc/nginx/nginx.conf

     

    复制代码
    ...
    # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80; server_name gerrit.wenbin.com; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { auth_basic "Gerrit Code Review"; auth_basic_user_file /passwords; 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; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
    复制代码

     

    systemctl restart nginx就可以了 

     

     

    如果使用apache,那么yum install httpd,更改配置文件

     

    /etc/httpd/httpd.conf

     

     

    复制代码
    # Defaults if commented: EnableMMAP On, EnableSendfile Off
    #
    #EnableMMAP off
    EnableSendfile on
    
    # Supplemental configuration
    #
    # Load config files in the "/etc/httpd/conf.d" directory, if any.
    IncludeOptional conf.d/*.conf
    #增加下面这些 <VirtualHost *:80> ProxyRequests Off ProxyVia Off ProxyPreserveHost On <Proxy *> Order deny,allow Allow from all </Proxy> <Location /> AuthType Basic AuthName "Gerrit Code Review" Require valid-user AuthUserFile /passwords </Location> ProxyPass / http://127.0.0.1:8081/ </VirtualHost>
    复制代码

     

     

    systemctl resatrt httpd

     

    如果nginx报错不能连接到8081端口,可能是selinux没有关

     

    设置开机启动

     

    sudo cp etc/gerrit.config /etc/init.d/gerrit

     

    sudo ln -snf /etc/init.d/gerrit /etc/rc2.d/S90gerrit

     

    sudo ln -snf /etc/init.d/gerrit /etc/rc3.d/S90gerrit

     

     

    这样就安装成功了,哎。。。遇到的问题是gerrit repository not found: All-Projects,这样是发现没有在第二个回答中写git目录,如果再次出现这个错误,那就先在mysql中drop再create一遍db就好了。。。

     

     

    在/review_gerrit/bin/gerrit.sh中实际代码第一行加入

     

    GERRIT_SITE=/home/gerrit/review_site

     

    执行/home/gerrit/review_site/bin/gerrit.sh就可以启动gerrit了

     

     

    这样在浏览器中访问域名或者ip地址就ok了,输入admin的用户名和密码就可以看到界面了。

     

    会提示注册邮箱,自己注册个就行了,

     

    在右上角点击用户,选setting设置ssh-key

     

    在主机上执行 ssh-keygen -C ***@163.com

     

    把公钥放进页面的sshkey

     

     

    这样就可以了,下面就需要把gitlab,gerrit,jenkins配置起来

     

    收获不会与付出成反比 by juandx

     

     

     

  • 相关阅读:
    read-uncommited 下脏读的实现
    MySQL 加锁处理分析【重点】
    Next-key locking是如何解决幻读(当前读)问题的
    spring ioc
    讨论 update A set number=number+ ? where id=?的原子性 (含数据库原理)
    PESSIMISTIC_READ & PESSIMISTIC_WRITE 与 共享锁 & 排它锁
    innodb当前读 与 快照读 and rr级别是否真正避免了幻读
    java finalize及实践
    uva 539 The Settlers of Catan
    zoj 1016 Parencodings
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/5377386.html
Copyright © 2020-2023  润新知