在 Docker 中部署 Jira 和 Confluence 並連接到 Amazon RDS

在 Docker 中部署 Jira 和 Confluence 並連接到 Amazon RDS #

採用 Docker 部署 Jira,使用 Nginx 作爲反響代理,數據庫使用 Amazon RDS(MySQL 5.7)

Jira Application #

創建個目錄,內部放置一個 docker-compose.yml 文件,內容如下:

version: '3.3'
services:
    jira-software:
        image: atlassian/jira-software
        volumes:
            - ./jira\_data:/var/atlassian/application-data/jira
            - ./jira\_lib/mysql-connector-java-5.1.49-bin.jar:/opt/atlassian/jira/lib/mysql-connector-java-5.1.49-bin.jar
            - ./jira\_lib/mysql-connector-java-5.1.49.jar:/opt/atlassian/jira/lib/mysql-connector-java-5.1.49.jar
            - ./jira\_lib/server.xml:/opt/atlassian/jira/conf/server.xml:ro # 這裏一定要只讀掛載,不然 Jira 重啓後會用默認值去覆蓋,然後用反向代理的時候會出現問題
        ports:
            - '8080:8080'

在同目錄中創建 jira_lib 目錄,內部放上 mysql-connector-java-5.1.49-bin.jar , mysql-connector-java-5.1.49.jar 和 server.xml,其中前兩者可以在 https://lb.knat.network/mysql-connector-java-5.1.49.zip 下得到,後者內容如下(只修改了 Connector 部分,着重關注一下這個,如果懷疑版本不對的話,建議手動進入 Docker 容器內把 /opt/atlassian/jira/conf/server.xml 文件複製出來進行修改):

<?xml version="1.0" encoding="utf-8"?>

<Server port="8005"
        shutdown="SHUTDOWN">

  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
  <Listener className="org.apache.catalina.core.AprLifecycleListener"
            SSLEngine="on"/>
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>

  <Service name="Catalina">

    <Connector port="8080"
               maxThreads="100"
               minSpareThreads="10"
               connectionTimeout="20000"
               enableLookups="false"
               protocol="HTTP/1.1"
               redirectPort="8443"
               acceptCount="10"
               secure="true"
               scheme="https"
               proxyName="your-jira-website.com"
               proxyPort="443"

               relaxedPathChars="\[\]|"
               relaxedQueryChars="\[\]|{}^\\\`"<>"
               bindOnInit="false"
               maxHttpHeaderSize="8192"
               useBodyEncodingForURI="true"
               disableUploadTimeout="true" />

    <Engine name="Catalina"
            defaultHost="localhost">

      <Host name="localhost"
            appBase="webapps"
            unpackWARs="true"
            autoDeploy="true">

        <Context path=""
                 docBase="${catalina.home}/atlassian-jira"
                 reloadable="false"
                 useHttpOnly="true">
          <Resource name="UserTransaction"
                    auth="Container"
                    type="javax.transaction.UserTransaction"
                    factory="org.objectweb.jotm.UserTransactionFactory"
                    jotm.timeout="60"/>
          <Manager pathname=""/>
          <JarScanner scanManifest="false"/>
          <Valve className="org.apache.catalina.valves.StuckThreadDetectionValve"
                 threshold="120" />
        </Context>

      </Host>
      <Valve className="org.apache.catalina.valves.AccessLogValve"
             pattern="%a %{jira.request.id}r %{jira.request.username}r %t "%m %U%q %H" %s %b %D "%{Referer}i" "%{User-Agent}i" "%{jira.request.assession.id}r""/>
    </Engine>

  </Service>
</Server>

Nginx 配置 #

非常簡單,如下:

location /{
		proxy\_pass http://127.0.0.1:8080;
		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;
		client\_max\_body\_size 50M;
	}

RDS 配置 #

由於 Jira 對於數據庫的要求比較多,MySQL 默認編碼啥的都沒法滿足要求,所以需要在 Amazon 上設置 Parameter Group,需要修改的內容如下:

collation-server=utf8mb4\_bin
character\_set\_server=utf8mb4
innodb\_large\_prefix=ON
innodb\_file\_format=Barracuda
transaction-isolation=READ-COMMITTED
binlog\_format=row
innodb\_log\_file\_size=2GB
max\_allowed\_packet=256M
default-storage-engine=INNODB

注意這個地方,sql_mode 不!要!看!飄!了!

這裏(https://confluence.atlassian.com/doc/database-setup-for-mysql-128747.html)很明白是 Ensure the sql_mode parameter does not specify NO_AUTO_VALUE_ON_ZERO,對於 Amazon RDS MySQL 5.7 默認的值是 NO_ENGINE_SUBSTITUTION,默認值就是 OK 的,如果你和我一樣看飄了調成了 NO_AUTO_VALUE_ON_ZERO 的話,在 Confluence 創建 Project 的頁面就等着看一個 500 Error 吧,像這樣:

Software: gnome-screenshot

很快樂是不是?

Jira 降級操作 #

如果需要從一個高版本的 Jira 降級到低版本的 Jira 的話,可以直接修改 image 後面的 tag 進行,然後加入一個環境變量讓 Jira 嘗試給數據庫內容降級(不然會報錯),樣例 docker-compose.yml 文件內容如下:

version: '3.3'
services:
    jira-software:
        image: atlassian/jira-software:8.5.3
        environment:
           JVM\_SUPPORT\_RECOMMENDED\_ARGS: '-Djira.downgrade.allowed=true'
        volumes:
            - ./jira\_data:/var/atlassian/application-data/jira
            - ./jira\_lib/mysql-connector-java-5.1.49-bin.jar:/opt/atlassian/jira/lib/mysql-connector-java-5.1.49-bin.jar
            - ./jira\_lib/mysql-connector-java-5.1.49.jar:/opt/atlassian/jira/lib/mysql-connector-java-5.1.49.jar
            - ./jira\_lib/server.xml:/opt/atlassian/jira/conf/server.xml:ro
        ports:
            - '8080:8080'

Confluence #

既然有了 Jira 了,爲什麼不再加入一個 Confluence 的部署呢?我們弄個 docker-compose.yml 文件如下:

version: '3.3'
services:
    jira-software:
        image: atlassian/confluence-server
        volumes:
            - ./confluence\_data:/var/atlassian/application-data/confluence
            - ./confluence\_lib/mysql-connector-java-5.1.49-bin.jar: /opt/atlassian/confluence/confluence/WEB-INF/lib/mysql-connector-java-5.1.49-bin.jar
            - ./confluence\_lib/mysql-connector-java-5.1.49.jar: /opt/atlassian/confluence/confluence/WEB-INF/lib/mysql-connector-java-5.1.49.jar
            - ./confluence\_lib/server.xml:/opt/atlassian/confluence/conf/server.xml:ro

        ports:
            - '8090:8090'
            - '8091:8091'

其中上面的 mysql connector 可以直接沿用 Jira 的,server.xml 可以參照上面 Jira 的寫法配置好反響代理的一些信息,然後我們配置 Nginx

Nginx 配置 #

也很簡單,如下:

location /{
                proxy\_pass http://127.0.0.1:8090;
                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;
                client\_max\_body\_size 50M;
        }

Timezone #

Confluence 的默認 Timezone 是 GMT,網上有些不靠譜的修改方式,如果你和我一樣使用的是官方的 Docker Image 的話,可以通過加入一個環境變量的方式進行:

environment:
            - TZ=Asia/Shanghai

TZ 列表可以參考:https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

參考資料 #

  1. https://confluence.atlassian.com/doc/database-setup-for-mysql-128747.html
  2. https://confluence.atlassian.com/jirakb/jira-server-startup-fails-with-tomcat-misconfigured-error-958453799.html
  3. https://community.atlassian.com/t5/Jira-questions/Modify-conf-server-xml-if-running-Jira-standalone/qaq-p/305963
  4. https://confluence.atlassian.com/jirakb/startup-check-jira-build-version-867185576.html
  5. https://confluence.atlassian.com/kb/how-to-set-the-timezone-for-docker-container-976780914.html