1. vmware搭建centos8
1.1 虚拟机设置
- 网络连接选择NAT模式,此模式下主机和虚拟机在局域网内有不同的ip,并且虚拟机也可以上广域网
1.2 SSH登录 虚拟机
- 需修改centos的网络连接为自动获取ip,否则ifconfig会没有ip显示
- 利用ssh工具登录虚拟机
login as: root
root@192.168.206.128's password:
┌────────────────────────────────────────────────────────────────────┐
│ • MobaXterm 11.0 • │
│ (SSH client, X-server and networking tools) │
│ │
│ ➤ SSH session to root@192.168.206.128 │
│ • SSH compression : ✔ │
│ • SSH-browser : ✔ │
│ • X11-forwarding : ✔ (remote display is forwarded through SSH) │
│ • DISPLAY : ✔ (automatically set on remote server) │
│ │
│ ➤ For more info, ctrl+click on help or visit our website │
└────────────────────────────────────────────────────────────────────┘
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Fri Sep 4 10:01:00 2020
/usr/bin/xauth: file /root/.Xauthority does not exist
[root@192 ~]# uname -a
Linux 192.168.206.128 4.18.0-193.el8.x86_64 #1 SMP Fri May 8 10:59:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
1.3 修改软件源为阿里云
root@192 ~]# cd /etc/yum.repos.d/
[root@192 yum.repos.d]# ls
CentOS-AppStream.repo CentOS-Devel.repo CentOS-PowerTools.repo
CentOS-Base.repo CentOS-Extras.repo CentOS-Sources.repo
CentOS-centosplus.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-HA.repo
CentOS-Debuginfo.repo CentOS-Media.repo
[root@192 yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@192 yum.repos.d]# curl -o CentOS-Base.repo https://mirrors.aliyun.com/repo /Centos-8.repo
[root@192 yum.repos.d]# yum update -y
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
CentOS-8 - Base - mirrors.aliyun.com 4.0 MB/s | 2.2 MB 00:00
CentOS-8 - Extras - mirrors.aliyun.com 19 kB/s | 7.3 kB 00:00
Dependencies resolved.
================================================================================
Package Arch Version Repo SizeInstalled:
.
.
.
grub2-tools-efi-1:2.02-87.el8_2.x86_64 kernel-4.18.0-193.14.2.el8_2.x86_64 kernel-core-4.18.0-193.14.2.el8_2.x86_64 kernel-modules-4.18.0-193.14.2.el8_2.x86_64
Complete!
2 搭建gerrit
2.1 安装java
- 查询可安装的版本
[root@192 yum.repos.d]# yum -y list java*
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Last metadata expiration check: 0:16:24 ago on Fri 04 Sep 2020 11:31:52 PM EDT.
Available Packages
java-1.8.0-openjdk.x86_64 1:1.8.0.262.b10-0.el8_2 AppStream
java-1.8.0-openjdk-accessibility.x86_64
1:1.8.0.262.b10-0.el8_2 AppStream
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.262.b10-0.el8_2 AppStream
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.262.b10-0.el8_2 AppStream
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.262.b10-0.el8_2 AppStream
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.262.b10-0.el8_2 AppStream
java-1.8.0-openjdk-javadoc-zip.noarch
1:1.8.0.262.b10-0.el8_2 AppStream
java-1.8.0-openjdk-src.x86_64 1:1.8.0.262.b10-0.el8_2 AppStream
java-11-openjdk.x86_64 1:11.0.8.10-0.el8_2 AppStream
java-11-openjdk-demo.x86_64 1:11.0.8.10-0.el8_2 AppStream
java-11-openjdk-devel.x86_64 1:11.0.8.10-0.el8_2 AppStream
java-11-openjdk-headless.x86_64 1:11.0.8.10-0.el8_2 AppStream
java-11-openjdk-javadoc.x86_64 1:11.0.8.10-0.el8_2 AppStream
java-11-openjdk-javadoc-zip.x86_64 1:11.0.8.10-0.el8_2 AppStream
java-11-openjdk-jmods.x86_64 1:11.0.8.10-0.el8_2 AppStream
java-11-openjdk-src.x86_64 1:11.0.8.10-0.el8_2 AppStream
java-atk-wrapper.x86_64 0.33.2-6.el8 AppStream
javapackages-filesystem.noarch 5.3.0-1.module_el8.0.0+11+5b8c10bd AppStream
javapackages-tools.noarch 5.3.0-1.module_el8.0.0+11+5b8c10bd AppStream
- 默认安装最新的版本
[root@192 yum.repos.d]# yum install -y java
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Last metadata expiration check: 0:19:46 ago on Fri 04 Sep 2020 11:31:52 PM EDT.
Dependencies resolved.
===============================================================================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================================================================
Installing:
java-1.8.0-openjdk x86_64 1:1.8.0.262.b10-0.el8_2 AppStream 323 k
Installing dependencies:
copy-jdk-configs noarch 3.7-1.el8 AppStream 27 k
java-1.8.0-openjdk-headless x86_64 1:1.8.0.262.b10-0.el8_2 AppStream 34 M
javapackages-filesystem noarch 5.3.0-1.module_el8.0.0+11+5b8c10bd AppStream 30 k
lksctp-tools x86_64 1.0.18-3.el8 base 100 k
ttmkfdir x86_64 3.0.9-54.el8 AppStream 62 k
tzdata-java noarch 2020a-1.el8 AppStream 189 k
xorg-x11-fonts-Type1 noarch 7.5-19.el8 AppStream 522 k
Enabling module streams:
javapackages-runtime 201801
Transaction Summary
[root@192 yum.repos.d]# java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
2.2 安装git
[root@192 yum.repos.d]# yum install -y git
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Last metadata expiration check: 0:28:36 ago on Fri 04 Sep 2020 11:31:52 PM EDT.
Dependencies resolved.
===============================================================================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================================================================
Installing:
git x86_64 2.18.4-2.el8_2 AppStream 186 k
Installing dependencies:
git-core x86_64 2.18.4-2.el8_2 AppStream 4.0 M
git-core-doc noarch 2.18.4-2.el8_2 AppStream 2.3 M
perl-Error noarch 1:0.17025-2.el8 AppStream 46 k
perl-Git noarch 2.18.4-2.el8_2 AppStream 77 k
perl-TermReadKey x86_64 2.37-7.el8 AppStream 40 k
Transaction Summary
[root@192 yum.repos.d]# git --version
git version 2.18.4
2.3 安装apache(httpd)
[root@192 yum.repos.d]# yum install -y httpd
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Last metadata expiration check: 0:31:02 ago on Fri 04 Sep 2020 11:31:52 PM EDT.
Dependencies resolved.
===============================================================================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================================================================
Installing:
httpd x86_64 2.4.37-21.module_el8.2.0+382+15b0afa8 AppStream 1.7 M
Installing dependencies:
apr x86_64 1.6.3-9.el8 AppStream 125 k
apr-util x86_64 1.6.1-6.el8 AppStream 105 k
centos-logos-httpd noarch 80.5-2.el8 base 24 k
httpd-filesystem noarch 2.4.37-21.module_el8.2.0+382+15b0afa8 AppStream 36 k
httpd-tools x86_64 2.4.37-21.module_el8.2.0+382+15b0afa8 AppStream 103 k
mod_http2 x86_64 1.11.3-3.module_el8.2.0+307+4d18d695 AppStream 157 k
Installing weak dependencies:
apr-util-bdb x86_64 1.6.1-6.el8 AppStream 25 k
apr-util-openssl x86_64 1.6.1-6.el8 AppStream 27 k
Enabling module streams:
httpd 2.4
[root@192 yum.repos.d]# httpd -v
Server version: Apache/2.4.37 (centos)
Server built: Jun 8 2020 20:14:33
2.3 下载gerrit包
# curl -o gerrit-3.2.3.war https://gerrit-releases.storage.googleapis.com/gerrit-3.2.3.war
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 69.3M 100 69.3M 0 0 1891k 0 0:00:37 0:00:37 --:--:-- 2007k
2.4 安装gerrit包
[root@192 develops_tools]# java -jar gerrit-3.2.3.war init -d review_size
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2020-09-05 00:12:17,415] [main] INFO com.google.gerrit.server.config.GerritServerConfigProvider : No /home/develops_tools/review_size/etc/gerrit.config; assuming defaults
*** Gerrit Code Review 3.2.3
***
Create '/home/develops_tools/review_size' [Y/n]? y
*** Git Repositories
***
Location of Git repositories [git]: GerritResource
*** Index
***
Type [lucene]:
*** User Authentication
***
Authentication method [openid/?]: 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 [root]:
Java runtime [/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el8_2.x86_64/jre]:
Copy gerrit-3.2.3.war to review_size/bin/gerrit.war [Y/n]? y
Copying gerrit-3.2.3.war to review_size/bin/gerrit.war
*** SSH Daemon
***
Listen on address [*]:
Listen on port [29418]:
Generating SSH host key ... rsa... ed25519... ecdsa 256... ecdsa 384... ecdsa 521... done
*** HTTP Daemon
***
Behind reverse proxy [y/N]?
Use SSL (https://) [y/N]?
Listen on address [*]:
Listen on port [8080]:
Canonical URL [http://192.168.206.128:8080/]:
*** Cache
***
*** Plugins
***
Installing plugins.
Install plugin codemirror-editor version v3.2.3 [y/N]? y
Installed codemirror-editor v3.2.3
Install plugin commit-message-length-validator version v3.2.3 [y/N]? y
Installed commit-message-length-validator v3.2.3
Install plugin delete-project version v3.2.3 [y/N]? y
Installed delete-project v3.2.3
Install plugin download-commands version v3.2.3 [y/N]? y
Installed download-commands v3.2.3
Install plugin gitiles version v3.2.3 [y/N]? y
Installed gitiles v3.2.3
Install plugin hooks version v3.2.3 [y/N]? y
Installed hooks v3.2.3
Install plugin plugin-manager version v3.2.3 [y/N]? y
Installed plugin-manager v3.2.3
Install plugin replication version v3.2.3 [y/N]? y
Installed replication v3.2.3
Install plugin reviewnotes version v3.2.3 [y/N]? y
Installed reviewnotes v3.2.3
Install plugin singleusergroup version v3.2.3 [y/N]? y
Installed singleusergroup v3.2.3
Install plugin webhooks version v3.2.3 [y/N]? y
Installed webhooks v3.2.3
Initializing plugins.
Initialized /home/**/review_size
Init complete, reindexing accounts with: reindex --site-path review_size --threads 1 --index accountsReindexed 0 documents in accounts index in 0.0s (0.0/s)
Index accounts in version 11 is ready
Warning: InterruptedException
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.Thread.join(Thread.java:1260)
at org.h2.util.MathUtils.getSecureRandom(MathUtils.java:105)
at org.h2.util.MathUtils.secureRandomBytes(MathUtils.java:307)
at org.h2.store.FileLock.setUniqueId(FileLock.java:315)
at org.h2.store.FileLock.lockFile(FileLock.java:345)
at org.h2.store.FileLock.lock(FileLock.java:136)
at org.h2.engine.Database.open(Database.java:622)
at org.h2.engine.Database.openDatabase(Database.java:260)
at org.h2.engine.Database.<init>(Database.java:254)
at org.h2.engine.Engine.openSession(Engine.java:57)
at org.h2.engine.Engine.openSession(Engine.java:164)
at org.h2.engine.Engine.createSessionAndValidate(Engine.java:142)
at org.h2.engine.Engine.createSession(Engine.java:125)
at org.h2.engine.Engine.createSession(Engine.java:27)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:331)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:107)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:91)
at org.h2.Driver.connect(Driver.java:74)
at com.google.gerrit.server.cache.h2.H2CacheImpl$SqlHandle.<init>(H2CacheImpl.java:637)
at com.google.gerrit.server.cache.h2.H2CacheImpl$SqlStore.acquire(H2CacheImpl.java:605)
at com.google.gerrit.server.cache.h2.H2CacheImpl$SqlStore.buildBloomFilter(H2CacheImpl.java:331)
at com.google.gerrit.server.cache.h2.H2CacheImpl$SqlStore.open(H2CacheImpl.java:303)
at com.google.gerrit.server.cache.h2.H2CacheImpl.start(H2CacheImpl.java:189)
at com.google.gerrit.server.logging.LoggingContextAwareRunnable.run(LoggingContextAwareRunnable.java:110)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Collecting projects: 2 changes with: reindex --site-path review_size --threads 1 --index changes
Reindexing changes: project-slices: 100% (2/2), done
Reindexed 0 documents in changes index in 0.0s (0.0/s)
Index changes in version 60 is ready
Reindexing groups: 100% (2/2)ith: reindex --site-path review_size --threads 1 --index groups
Reindexed 2 documents in groups index in 0.1s (19.4/s)
Index groups in version 8 is ready
Reindexing projects: 100% (2/2) with: reindex --site-path review_size --threads 1 --index projects
Reindexed 2 documents in projects index in 0.2s (11.1/s)
Index projects in version 4 is ready
Executing /home/**/review_size/bin/gerrit.sh start
Starting Gerrit Code Review: OK
Waiting for server on 192.168.206.128:8080 ... OK
Opening http://192.168.206.128:8080/#/admin/projects/ ...OK
2.4 修改gerrit配置文件gerrit.config
[gerrit]
basePath = GerritResource
canonicalWebUrl = http://192.168.206.128:8080/
serverId = 02b75760-****-****-9425-528189d16eeb
[container]
javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"
javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance"
user = root
javaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el8_2.x86_64/jre
[index]
type = lucene
[auth]
type = HTTP
[receive]
enableSignedPush = false
[sendemail]
smtpServer = smtp.163.com
smtpServerPort = 25
smtpUser = ***@163.com
from = CodeReview<***@163.com>
[sshd]
listenAddress = 192.168.206.128:29418
[httpd]
listenUrl = http://192.168.206.128:8080/
[cache]
directory = cache
2.5.1 验证邮箱
- 在gerrit.config中花了很多时间在验证邮箱,需采用授权码的形式
- 在 secure.config中输入授权码
[sendemail]
smtpPass = AUYJOXBALR*****#授权码
* 可以采用telnet的方法测试邮箱是否正常
```shell
[root@192 etc]# telnet smtp.163.com 25 //step1 连接邮箱服务器25端口
Trying 220.181.12.15...
Connected to smtp.163.com.
Escape character is '^]'.
220 163.com Anti-spam GT for Coremail System (163com[20141201])
helo 163.com //step2 握手
250 OK
auth login //step3 开始认证登录
334 dXNlcm5hbWU6
********* //step4 输入邮箱地址(Base64加密)
334 UGFzc3dvcmQ6
********* //step5 输入授权码(Base64加密)
235 Authentication successful
注意:gerrit.config和security.config中的信息无需Base64加密
2.5 修改apache配置文件httpd.conf
- 设置反向代理
<VirtualHost *:80>
ServerName 192.168.206.128
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /login/>
AuthType Basic
AuthName "Gerrit Code Review"
Require valid-user
AuthUserFile /etc/httpd/passwords
</Location>
AllowEncodedSlashes On
ProxyPass / http://192.168.206.128:8080/
</VirtualHost>
2.6 设置防火墙
- 打开需要的端口80,8080和29418
[root@192 etc]## firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@192 etc]## firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@192 etc]## firewall-cmd --zone=public --add-port=29418/tcp --permanent
success
- 更新防火墙规则
[root@192 etc]# firewall-cmd --reload
success
- 查看端口
[root@192 etc]# firewall-cmd --zone=public --list-ports
80/tcp 29418/tcp
2.7 启动apache
- 创建httpd用户
htpasswd -cb /etc/httpd/passwords admin admin
htpasswd -b /etc/httpd/passwords freind freind
2.8 启动gerrit
./gerrit.sh start
2.9 登录gerrit网页
- 报如下错误
Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
- 查看/var/log/httpd/error_log
[Sat Sep 05 03:02:49.910157 2020] [proxy:error] [pid 83500:tid 140528133842688] (13)Permission denied: AH00957: HTTP: attempt to connect to 192.168.206.128:8080 (192.168.206.128) failed
[Sat Sep 05 03:02:49.910187 2020] [proxy_http:error] [pid 83500:tid 140528133842688] [client 192.168.206.1:58110] AH01114: HTTP: failed to make connection to backend: 192.168.206.128
- 解决方法: 需操作SELinux
- 查看SElinux
[root@192 etc]# getenforce
Enforcing
- 改成permissive(宽容模式)
[root@192 etc]# setenforce 0
[root@192 etc]# getenforce
Permissive