- 由 zhongluqiang创建, 最后修改于7月 19, 2021
安装环境
服务器:腾讯云Ubuntu20.04,配置2核8G3M,清华源,Confluence版本:7.10.2,下载地址下载 Confluence Server | Atlassian。
这里强调一下服务器的配置需求,按官方描述,服务器的最小配置要求为2核6G,这个要求相比于一般的云服务器要求还是很高的,个人实测过,1核2G的云服根本带不动,2核4G的云服勉强可以带动,但服务启动后可用内存只剩下200M左右,并且运行一段时间后出现过物理内存不足,kswapd0进程占满CPU,导致不得不重启服务器的问题。升级到2核8G的配置后,Confluence Server运行就正常了,启动后内存剩余4G左右,运行几天后虽然会出现大部分内存被cache占用,导致free命令显示的可用内存也只有几百兆的情况,但服务是正常运行的,占用的cache也可以通过echo 1 > /proc/sys/vm/drop_caches回收。
准备工作
安装MySQL和java环境
apt-get install mysql-client apt-get install mysql-server apt-get install default-jre
这里Ubuntu20.04默认安装的MySQL是8.0版,而老版本的Ubuntu会默认安装MySQL5.7版本,这两版在数据库初始化上可能有些许区别。安装之后mysqld会在后台运行,监听端口3306,root用户默认没有密码,可以使用mysql -u root进入MySQL的命令行。
调整MySQL的默认参数
这里参考链接:https://confluence.atlassian.com/doc/database-setup-for-mysql-128747.html,修改/etc/mysql/my.cnf,加入以下字段:
... [mysqld] character-set-server=utf8mb4 collation-server=utf8mb4_bin default-storage-engine=INNODB max_allowed_packet=256M innodb_log_file_size=2GB transaction-isolation=READ-COMMITTED
重启MySQL服务器使参数生效。
初始化Confluence数据库
在MySQL里创建Confluence的数据库,用户名,密码:
CREATE DATABASE confluence CHARACTER SET utf8mb4 COLLATE utf8mb4_bin; CREATE USER 'confluenceuser'@'localhost' IDENTIFIED BY 'yourpassword'; GRANT ALL PRIVILEGES ON confluence.* TO 'confluenceuser'@'localhost';
安装Confluence Server和MySQL数据库驱动
首先下载 Confluence Server | Atlassian,这里用wget进行下载并安装:
wget https://www.atlassian.com/software/confluence/downloads/binary/atlassian-confluence-7.10.2-x64.bin chmod +x atlassian-confluence-7.10.2-x64.bin ./atlassian-confluence-7.10.2-x64.bin
安装好后的confluence位于/opt/atlassian/confluence,启动脚本是该目录下的bin/startup.sh,关闭脚本是bin/shutdown.sh。默认数据位置是/var/atlassian/application-data/confluence。安装好之后再参考Download and install the MySQL driver安装数据库驱动即可开始使用。执行bin/startup.sh,从浏览器上访问Confluence执行初始化工作,默认端口是8090。
经常查看Confluence文档的话会用到两个路径,一个是<confluence-home>,默认为/var/atlassian/application-data/confluence,另一个是<installation-directory>,默认是/opt/atlassian/confluence。
使用Nginx+SSL反向代理Confluence
配置目标
上面的安装步骤完成之后,Confluence自动运行于8090端口,协议为HTTP。这种方式是不安全的,我们一般会为Confluence配置Nginx反向代理并使用HTTPS协议进行加密访问,这一步解决这个问题。
目标:外部使用https访问Nginx,Nginx反向代理Confluence,Nginx和Confluence运行在同一台机器上,使用非加密的http协议在本地网卡上进行通信。
参考链接: https://confluence.atlassian.com/doc/running-confluence-behind-nginx-with-ssl-858772080.html
配置步骤
设置Confluence的根路径
这一步可选,设置后将使原本为http://www.example.com:8090的访问路径变成http://www.example.com:8090/confluence。如果本身就想将Confluence以作为网站的根路径,那么可以跳过本步骤。
修改<installation-directory>/conf/server.xml文件,定位到Context字段,修改如下:
将
<Context path="" docBase="../confluence" debug="0" reloadable="false" useHttpOnly="true">
替换成
<Context path="/confluence" docBase="../confluence" debug="0" reloadable="false" useHttpOnly="true">
重启Confluence服务,即可以http://www.example.com:8090/confluence的方式访问Confluence主页。
配置Confluence自带的Tomcat连接器
这里要将Tomcat配置成支持https反向代理,并且为了避免在公网上暴露端口,要将Confluence绑定到本地网卡上。修改<installation-directory>/conf/server.xml,注释掉默认的连接器:
<!--
==============================================================================================================
DEFAULT - Direct connector with no proxy, for unproxied HTTP access to Confluence.
If using a http/https proxy, comment out this connector.
==============================================================================================================
-->
<!--
<Connector port="8090" connectionTimeout="20000" redirectPort="8443"
maxThreads="48" minSpareThreads="10"
enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8"
protocol="org.apache.coyote.http11.Http11NioProtocol"/>
-->
打开标记有HTTPS - Proxying Confluence via Apache or Nginx over HTTPS的连接器,这里以www.example.com为例:
<!--
==============================================================================================================
HTTPS - Proxying Confluence via Apache or Nginx over HTTPS
If you're proxying traffic to Confluence over HTTPS, uncomment the connector below and comment out the others.
Make sure you provide the right information for proxyName and proxyPort.
For more information see:
Apache - https://confluence.atlassian.com/x/PTT3MQ
nginx - https://confluence.atlassian.com/x/cNIvMw
==============================================================================================================
-->
<Connector port="8090" connectionTimeout="20000" redirectPort="8443" address="127.0.0.1"
maxThreads="48" minSpareThreads="10"
enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8"
protocol="org.apache.coyote.http11.Http11NioProtocol"
scheme="https" secure="true" proxyName="www.example.com" proxyPort="443"/>
增加了address参数,修改proxyName为实际的访问域名。
除了8090端口,Confluence还会默认使用8091端口来进行协同编辑,这个端口也要修改成只绑定到本地网卡上,这里通过修改<installation-directory>/bin/setenv.sh来实现,修改如下:
CATALINA_OPTS="-Dsynchrony.bind=127.0.0.1 ${CATALINA_OPTS}"
个人使用时,可以关闭协同编辑功能,这样8091端口就不会开启,另外在编辑页面还可以先预览再发布。
配置Nginx https及反向代理
这里以网站为example.com为例,附上https的配置文件:
# HTTPS server
server {
listen 443 ssl;
server_name example.com;
# 证书路径
ssl_certificate /path/to/your/server.crt;
ssl_certificate_key /path/to/your/server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root www;
index index.html index.htm;
}
location /confluence {
proxy_buffer_size 128k;
proxy_buffers 32 128k;
proxy_busy_buffers_size 128k;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
client_max_body_size 100m;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8090/confluence;
}
location /synchrony {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8091/synchrony;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
proxy_buffer相关的三行用以解决net::ERR_INCOMPLETE_CHUNKED_ENCODING 200错误,参考https://blog.csdn.net/baidu_19473529/article/details/87898939。
timeout相关的三行用于解决504 Gateway Time-out错误,在初化Confluence数据库时需要较长时间,默认的1分钟不够。
另外,nginx.conf首行还必须指定一个合法的用户,以默认的nobody运行的话,会出现无法保存问题,提示“无法保存页面。请检查与服务器通信,或检查内容是否有特殊字符/emoji表情。”或是“无法与服务器取得联系。检查您的网络链接,合流已开大并正在运行。”
- 无标签