ubuntu postgresql gerrit nginx安装配置
开发能力不强,对代码review要求比较高的话,gerrit是一个不错的选择。对代码版本的管理,个人还是推荐用gitlab。
1,gerrit使用mysql问题
gerrit-2.15.1.war,用的是mysql5.7,报了以下错误
Fri May 25 15:47:41 CST 2018 WARN: Establishing ssl connection without server's identity verification is not recommended. According to mysql 5.5.45+, 5.6.26+ and 5.7.6+ requirements ssl connection must be established by default if explicit option isn't set. For compliance with existing applications not using ssl the verifyServerCertificate property is set to 'false'. You need either to explicitly disable ssl by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Fri May 25 15:47:42 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to mysql 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Exception in thread "main" com.google.gwtorm.server.OrmException: Cannot apply SQL
CREATE TABLE account_group_by_id_aud (
added_by INT DEFAULT 0 NOT NULL,
removed_by INT,
removed_on TIMESTAMP NULL DEFAULT NULL,
group_id INT DEFAULT 0 NOT NULL,
include_uuid VARCHAR(255) BINARY DEFAULT '' NOT NULL,
added_on TIMESTAMP NOT NULL
,PRIMARY KEY(group_id,include_uuid,added_on)
)
at com.google.gwtorm.jdbc.JdbcExecutor.execute(JdbcExecutor.java:44)
at com.google.gwtorm.jdbc.JdbcSchema.createRelations(JdbcSchema.java:134)
mysql gerrit连接成功了,并且创建了几张表,但是这张表报语法错误,单独copy出来,在mysql 命令行,也是执行不成功的。
mysql> CREATE TABLE account_group_by_id_aud (
-> added_by INT DEFAULT 0 NOT NULL,
-> removed_by INT,
-> removed_on TIMESTAMP NULL DEFAULT NULL,
-> group_id INT DEFAULT 0 NOT NULL,
-> include_uuid VARCHAR(255) BINARY DEFAULT '' NOT NULL,
-> added_on TIMESTAMP NOT NULL
-> ,PRIMARY KEY(group_id,include_uuid,added_on)
-> );
ERROR 1067 (42000): Invalid default value for 'added_on'
正确的sql是:
CREATE TABLE account_group_by_id_aud (
added_by INT DEFAULT 0 NOT NULL,
removed_by INT,
removed_on TIMESTAMP NULL DEFAULT NULL,
group_id INT DEFAULT 0 NOT NULL,
include_uuid VARCHAR(255) BINARY DEFAULT '' NOT NULL,
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
,PRIMARY KEY(group_id,include_uuid,added_on)
)
产生这个错误的原因是,在mysqld,加了NO_ZERO_DATE
[mysqld]
sql_mode=NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
去掉后gerrit就可以安装成功了
2,安装postgresql Nginx java1.8
apt-get install postgresql-client postgresql postgresql-contrib Nginx openjdk-8-jdk
3,创建postgresql用户和数据库
$ su - postgres //切换用户,很重要,下面的操作都是在这个用下操作的 postgres@localhost:~$ createuser -P -D -R -e gerrit //创建 Enter password for new role: Enter it again: postgres@localhost:~$ createdb gerrit //创建数据库 postgres@localhost:~$ psql -U gerrit -d gerrit //登录数据库报错 psql: FATAL: Peer authentication failed for user "gerrit"
解决办法:
vim /etc/postgresql/9.5/main/pg_hba.conf //找到以下内容 # "local" is for Unix domain socket connections only local all all md5 //peer改成md5
重新登录:
postgres@localhost:/etc/postgresql/9.5/main$ psql -U gerrit -d gerrit Password for user gerrit: psql (9.5.12) Type "help" for help. gerrit=> \dt No relations found.
到这儿,postgresql安装完成,数据库和用户创建完成
4,安装gerrit
adduser gerrit //添加用户 su - gerrit //切换用户 gerrit@localhost:~$ mkdir gerrit_web //创建目录 gerrit@localhost:~$ wget https://gerrit-releases.storage.googleapis.com/gerrit-2.15.1.war //下载 gerrit@localhost:~$ java -jar gerrit-2.15.1.war init -d /home/gerrit/gerrit_web //安装 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 server type [mysql]: postgresql Server hostname [localhost]: Server port [(postgresql default)]: 5432 Database name [gerrit]: Database username [gerrit]: Change gerrit's password [y/N]? y gerrit's password : confirm password : *** Index *** Type [lucene/?]: *** User Authentication *** Authentication method [http/?]: http //重要 Get username from custom HTTP header [y/N]? SSO logout URL : 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 [gerrit]: Java runtime [/usr/lib/jvm/java-8-openjdk-amd64/jre]: Upgrade /home/gerrit/gerrit_web/bin/gerrit.war [Y/n]? Copying gerrit-2.15.1.war to /home/gerrit/gerrit_web/bin/gerrit.war *** ssh Daemon *** Listen on address [*]: Listen on port [29418]: *** HTTP Daemon *** Behind reverse proxy [y/N]? Use SSL (https://) [y/N]? n Listen on address [*]: Listen on port [18080]: Canonical URL [http://localhost:18080/]: *** Cache *** *** Plugins *** Installing plugins. Install plugin commit-message-length-validator version v2.15.1 [y/N]? Install plugin download-commands version v2.15.1 [y/N]? Install plugin hooks version v2.15.1 [y/N]? Install plugin replication version v2.15.1 [y/N]? Install plugin reviewnotes version v2.15.1 [y/N]? Install plugin singleusergroup version v2.15.1 [y/N]? Initializing plugins. No plugins found with init steps. *** Experimental features *** Enable any experimental features [y/N]? Initialized /home/gerrit/gerrit_web
安装成功后,在postgresql能看到创建的表
5,修改gerrit.sh,并启动
# vim /home/gerrit/gerrit_web/bin/gerrit.sh GERRIT_SITE=/home/gerrit/gerrit_web //头部加上 $ ./gerrit.sh start Starting Gerrit Code Review: OK $ netstat -tpnl |grep -i gerrit //出现以下内容说明成功了 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 0.0.0.0:29418 0.0.0.0:* LISTEN 31647/GerritCodeRev tcp 0 0 0.0.0.0:18080 0.0.0.0:* LISTEN 31647/GerritCodeRev
6,配置gerrit.config
$ cat gerrit.config [gerrit] basePath = git serverId = 745420d2-cd46-41c6-aca9-4321ad12355d canonicalWebUrl = http://gerrit.xxxx.com/ //Nginx域名 [database] type = postgresql hostname = localhost database = gerrit username = gerrit port = 5432 [index] type = LUCENE [auth] type = HTTP [receive] enableSignedPush = false [sendemail] smtpServer = localhost [container] user = gerrit javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre [sshd] listenAddress = *:29418 [httpd] listenUrl = http://*:18080/ [cache] directory = cache $ ./gerrit.sh restart //重启 Stopping Gerrit Code Review: OK Starting Gerrit Code Review: OK
7,配置Nginx
htpasswd -c /home/gerrit/gerrit_web/etc/passwords gerrit //创建访问密码 # cat gerrit.conf server { listen 80; server_name gerrit.xxx.com; location / { auth_basic "Gerrit Code Review"; auth_basic_user_file /home/gerrit/gerrit_web/etc/passwords; proxy_pass http://localhost:18080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } # /etc/init.d/nginx restart
到这儿,gerrit就安装成功了