使用Gerrit发送测试邮件
使用Gerrit发送测试邮件
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.安装HTTP服务
1>.安装HTTP服务
[root@gerrit.yinzhengjie.org.cn ~]# yum -y install httpd
2>.使用HTTP配置反响代理
[root@gerrit.yinzhengjie.org.cn ~]# tail -23 /etc/httpd/conf/httpd.conf Listen 8090 <VirtualHost *:8090> ServerName gerrit.yinzhengjie.org.cn 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://gerrit.yinzhengjie.org.cn:8888/ </VirtualHost> [root@gerrit.yinzhengjie.org.cn ~]#
3>.创建passwd文件,添加gerrit登录用户
[root@gerrit.yinzhengjie.org.cn ~]# htpasswd -cb /etc/httpd/passwords admin admin #注意,"-c"参数为创建,仅限第一次添加用户时使用,用户名和密码均为admin Adding password for user admin [root@gerrit.yinzhengjie.org.cn ~]# htpasswd -b /etc/httpd/passwords jason yinzhengjie #第二次创建时不要加"-c"参数。创建一个jason用户,密码为"yinzhengjie" Adding password for user jason [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# cat /etc/httpd/passwords #我们查看该文件的确有2个用户,但是密码时经过加密处理的! admin:$apr1$Em..sIno$GMpAsQlJ4l.S4C0Qnu0iD/ jason:$apr1$892G6DfX$IBkKm8paM/4wPvowppI/d1 [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]#
4>.启动HTTP服务
[root@gerrit.yinzhengjie.org.cn ~]# systemctl start httpd [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2019-06-26 04:48:49 EDT; 22h ago Docs: man:httpd(8) man:apachectl(8) Main PID: 9413 (httpd) Status: "Total requests: 233; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─ 9413 /usr/sbin/httpd -DFOREGROUND ├─ 9509 /usr/sbin/httpd -DFOREGROUND ├─ 9512 /usr/sbin/httpd -DFOREGROUND ├─ 9514 /usr/sbin/httpd -DFOREGROUND ├─19612 /usr/sbin/httpd -DFOREGROUND ├─19613 /usr/sbin/httpd -DFOREGROUND ├─19617 /usr/sbin/httpd -DFOREGROUND ├─20856 /usr/sbin/httpd -DFOREGROUND ├─20863 /usr/sbin/httpd -DFOREGROUND ├─20864 /usr/sbin/httpd -DFOREGROUND └─21731 /usr/sbin/httpd -DFOREGROUND Jun 26 04:48:49 gerrit.yinzhengjie.org.cn systemd[1]: Starting The Apache HTTP Server... Jun 26 04:48:49 gerrit.yinzhengjie.org.cn systemd[1]: Started The Apache HTTP Server. [root@gerrit.yinzhengjie.org.cn ~]#
二.安装Gerrit(需要有jdk环境)
1>.安装Gerrit
[root@gerrit.yinzhengjie.org.cn ~]# java -jar gerrit-3.0.0.war init -d /yinzhengjie/softwares/gerrit Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore [2019-06-27 02:50:33,855] [main] INFO com.google.gerrit.server.config.GerritServerConfigProvider : No /yinzhengjie/softwares/gerrit/etc/gerrit.config; assuming defaults *** Gerrit Code Review 3.0.0 *** Create '/yinzhengjie/softwares/gerrit' [Y/n]? *** Git Repositories *** Location of Git repositories [git]: *** Index *** Type [lucene/?]: *** User Authentication *** Authentication method [openid/?]: http Get username from custom HTTP header [y/N]? n SSO logout URL : Enable signed push support [y/N]? *** Review Labels *** Install Verified label [y/N]? *** Email Delivery *** SMTP server hostname [localhost]: smtp.ym.163.com SMTP server port [(default)]: 25 SMTP encryption [none/?]: SMTP username [root]: yinzhengjie@aggrx.com yinzhengjie@aggrx.com's password : confirm password : *** Container Process *** Run as [root]: Java runtime [/yinzhengjie/softwares/jdk1.8.0_201/jre]: Copy gerrit-3.0.0.war to /yinzhengjie/softwares/gerrit/bin/gerrit.war [Y/n]? y Copying gerrit-3.0.0.war to /yinzhengjie/softwares/gerrit/bin/gerrit.war *** SSH Daemon *** Listen on address [*]: gerrit.yinzhengjie.org.cn Listen on port [29418]: Generating SSH host key ... rsa... ed25519... ecdsa 256... ecdsa 384... ecdsa 521... done *** HTTP Daemon *** Behind reverse proxy [y/N]? y Proxy uses SSL (https://) [y/N]? n Subdirectory on proxy server [/]: Listen on address [*]: gerrit.yinzhengjie.org.cn Listen on port [8081]: 8888 Canonical URL [http://gerrit.yinzhengjie.org.cn/]: http://gerrit.yinzhengjie.org.cn:8090/ *** Cache *** *** Plugins *** Installing plugins. Install plugin codemirror-editor version v3.0.0 [y/N]? y Installed codemirror-editor v3.0.0 Install plugin commit-message-length-validator version v3.0.0 [y/N]? y Installed commit-message-length-validator v3.0.0 Install plugin delete-project version v3.0.0 [y/N]? y Installed delete-project v3.0.0 Install plugin download-commands version v3.0.0 [y/N]? y Installed download-commands v3.0.0 Install plugin gitiles version v3.0.0 [y/N]? y Installed gitiles v3.0.0 Install plugin hooks version v3.0.0 [y/N]? y Installed hooks v3.0.0 Install plugin plugin-manager version v3.0.0 [y/N]? y Installed plugin-manager v3.0.0 Install plugin replication version v3.0.0 [y/N]? y Installed replication v3.0.0 Install plugin reviewnotes version v3.0.0 [y/N]? y Installed reviewnotes v3.0.0 Install plugin singleusergroup version v3.0.0 [y/N]? y Installed singleusergroup v3.0.0 Install plugin webhooks version v3.0.0 [y/N]? y Installed webhooks v3.0.0 Initializing plugins. yInitialized /yinzhengjie/softwares/gerrit Reindexing projects: 100% (2/2) with: reindex --site-path /yinzhengjie/softwares/gerrit --threads 1 --index projects Reindexed 2 documents in projects index in 0.1s (23.0/s) Executing /yinzhengjie/softwares/gerrit/bin/gerrit.sh start Starting Gerrit Code Review: OK Waiting for server on gerrit.yinzhengjie.org.cn:80 ... OK Opening http://gerrit.yinzhengjie.org.cn/#/admin/projects/ ...FAILED Open Gerrit with a JavaScript capable browser: http://gerrit.yinzhengjie.org.cn/#/admin/projects/ [root@gerrit.yinzhengjie.org.cn ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 172.30.1.81:29418 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 *:22 *:* LISTEN 0 50 172.30.1.81:8888 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:8090 *:* LISTEN 0 128 :::22 :::* [root@gerrit.yinzhengjie.org.cn ~]#
2>.修改Gerrit配置文件,添加from字段
[root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# ll total 12 drwxr-xr-x 2 root root 84 Jun 27 02:53 bin drwxr-xr-x 2 root root 4096 Jun 27 02:57 cache drwxr-xr-x 5 root root 69 Jun 27 02:54 data drwxr-xr-x 2 root root 78 Jun 27 02:57 db drwxr-xr-x 3 root root 4096 Jun 27 02:56 etc drwxr-xr-x 4 root root 51 Jun 27 02:53 git drwxr-xr-x 6 root root 114 Jun 27 02:53 index drwxr-xr-x 2 root root 6 Jun 27 02:50 lib drwxr-xr-x 2 root root 130 Jun 27 02:57 logs drwxr-xr-x 2 root root 288 Jun 27 02:53 plugins drwxr-xr-x 2 root root 6 Jun 27 02:50 static drwx------ 2 root root 4096 Jun 27 02:57 tmp [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# cat etc/gerrit.config [gerrit] basePath = git canonicalWebUrl = http://gerrit.yinzhengjie.org.cn:8090/ serverId = 8102839b-2686-4d4c-8e55-ecfe5c397833 [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 = /yinzhengjie/softwares/jdk1.8.0_201/jre [index] type = LUCENE [auth] type = HTTP [receive] enableSignedPush = false [sendemail] smtpServer = smtp.ym.163.com smtpServerPort = 25 smtpUser = yinzhengjie@aggrx.com from = yinzhengjie@aggrx.com [sshd] listenAddress = gerrit.yinzhengjie.org.cn:29418 [httpd] listenUrl = proxy-http://gerrit.yinzhengjie.org.cn:8888/ [cache] directory = cache [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# ./bin/gerrit.sh restart Stopping Gerrit Code Review: OK Starting Gerrit Code Review: OK [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 172.30.1.81:29418 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 *:22 *:* LISTEN 0 50 172.30.1.81:8888 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:8090 *:* LISTEN 0 128 :::22 :::* [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]#
三.使用Gerrit Web UI发送邮件
1>.使用admin用户登陆
2>.点击设置
3>.设置发送邮箱地址为:yinzhengjie@aggrx.com
4>.邮箱发送成功
5>.登陆yinzhengjie@aggrx.com邮箱验证是否成功接收邮件
6>.查看测试邮件内容
7>.根据链接点进去,可以发现邮件添加成功啦~
当你的才华还撑不起你的野心的时候,你就应该静下心来学习。当你的能力还驾驭不了你的目标的时候,你就应该沉下心来历练。问问自己,想要怎样的人生。
欢迎交流学习技术交流,个人微信: "JasonYin2020"(添加时请备注来源及意图备注)
作者: 尹正杰, 博客: https://www.cnblogs.com/yinzhengjie/p/11075145.html