Ubuntu 22.04にGrowi 6.xをインストール

GrowiをUbuntu22.04をインストールしたので、そのときの手順です。

※ Growi v7以降、いくつか設定が異なりますので本稿ではv6での手順を示します。

環境

の基本的な設定が済んだという状況です。

前提

さっくりとはならない手順

  1. Node.js/npmをインストールします。
  2. Redis-serverをインストールします。
  3. Javaをインストールします。
  4. ElasticSearch 8をインストールします。
    1. ElasticSearchの設定変更を行います。
    2. ElasticSearchのプラグインをインストールします。
    3. ElasticSearchの設定変更を反映します。
  5. MongoDBをインストールします。
    1. MongoDBのデータ格納先を変更します。
    2. MongoDBのアップデートを防ぎます。
    3. MongoDBの設定変更を反映します。
  6. yarnのインストールを行います。
    1. 必要パッケージをインストールします。
    2. turboパッケージをインストールします。
  7. Growiのインストールを行います。
    1. yarnを用いてインストールします。
    2. 自動起動のスクリプトを作成します。
  8. Apacheのリバースプロキシの設定を行います。
  9. ブラウザで起動します。

手順

node18をインストールします。

sudo curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash
sudo aptitude update
sudo aptitude install nodejs
node -v

2024/04/03現在:v18.20.0

npm -v

2024/04/03現在:10.5.0

redis-serverをインストールします。

sudo  aptitude install redis-server
systemctl status redis-server

active(running)を確認します。

sudo systemctl enable redis-server

Javaをインストールします。

sudo aptitude install openjdk-17-jdk

ElasticSearhをインストールします。

sudo wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
sudo aptitude install apt-transport-https
sudo echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list
sudo aptitude update
sudo aptitude install elasticsearch

※この後、デフォルトパスワードが表示されますが、控えておく程度にしましょう。

JVM設定変更
sudo mkdir /etc/elasticsearch/old

※任意のバックアップディレクトリを指定します。

sudo cp -pi /etc/elasticsearch/jvm.options /etc/elasticsearch/old/jvm.options.$(date +%Y%m%d)
echo -e "-Xms256m\n-Xmx256m" | sudo tee -a /etc/elasticsearch/jvm.options
sudo diff -u /etc/elasticsearch/old/jvm.options.$(date +%Y%m%d) /etc/elasticsearch/jvm.options
+-Xms256m
+-Xmx256m
ElasticSearchの設定変更

※この作業だけ管理者権限で実行します。

sudo su -
cp -pi /etc/elasticsearch/elasticsearch.yml /path/to/backup/elasticsearch.yml.$(date +%Y%m%d)

任意のバックアップディレクトリを指定します。

sed -i -e 's/xpack.security.enabled: true/xpack.security.enabled: false/' \
       -e '/xpack.security.http.ssl:/{n; s/  enabled: true/  enabled: false/}' \
       -e '/xpack.security.transport.ssl:/{n; s/  enabled: true/  enabled: false/}' /etc/elasticsearch/elasticsearch.yml
diff -u /path/to/backup/elasticsearch.yml.$(date +%Y%m%d) /etc/elasticsearch/elasticsearch.yml
 # Enable security features
-xpack.security.enabled: true
+xpack.security.enabled: false
 
 xpack.security.enrollment.enabled: true
 
 # Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
 xpack.security.http.ssl:
-  enabled: true
+  enabled: false
   keystore.path: certs/http.p12
 
 # Enable encryption and mutual authentication between cluster nodes
 xpack.security.transport.ssl:
-  enabled: true
+  enabled: false
exit
ElasticSearchのプラグインを追加
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-kuromoji
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icu
自動起動設定反映
sudo systemctl start elasticsearch
systemctl status elasticsearch

active(running)を確認します。

sudo systemctl enable elasticsearch

MongoDBインストール

レポジトリ追加

sudo aptitude install gnupg
curl -fsSL https://pgp.mongodb.com/server-6.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
MongoDBインストール
sudo aptitude update
sudo aptitude install mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools
MongoDBバージョン固定

※2024/04/03現在、GrowiはMongoDBのバージョンが固定されているので、自動更新されないようにします。

sudo aptitude hold mongodb-org
sudo aptitude hold mongodb-org-server
sudo aptitude hold mongodb-org-shell
sudo aptitude hold mongodb-org-mongos
sudo aptitude hold mongodb-org-tools
保存先変更(オプション)

MongoDBの格納先を、冗長化構成されているパーティションにするため対応しました。

sudo mkdir /home/mongodb

保存先を変えたいところにします

sudo chown -R mongodb:mongodb /home/mongodb
ls -ld /home/mongodb
sudo cp -pi /etc/mongod.conf /path/to/backup/mongod.conf.$(date +%Y%m%d)

任意のバックアップディレクトリを指定します。

sudo diff -u /etc/mongod.conf /path/to/backup/mongod.conf.$(date +%Y%m%d)

バックアップが保存されたか、差分がないことで確認します。

sudo sed -i 's/dbPath: \/var\/lib\/mongodb/dbPath: \/home\/mongodb/' /etc/mongod.conf
sudo diff -u /path/to/backup/mongod.conf.$(date +%Y%m%d) /etc/mongodb.conf
-  dbPath: /var/lib/mongodb
+  dbPath: /home/mongodb
自動起動有効
sudo systemctl start mongod
systemctl status mongod

active (running)を確認します

sudo systemctl enable mongod

yarnインストール

sudo npm install -g yarn

※Growi v6.1.0から必須パッケージとなりました。

sudo yarn global add turbo@1.12.2

※最新版のturboをインストールするとv6では動きませんでした。

Growiインストール

sudo git clone https://github.com/weseek/growi /home/www-data/growi

※任意のディレクトリを指定します。

cd /home/www-data/growi && pwd

先ほどcloneしたディレクトリです。

sudo git checkout -b v6.3.5 refs/tags/v6.3.5

2024/06/25現在、Growi6系最新版の6.3.5をインストールします

sudo yarn

CPUのスペックによっては相当な時間がかかります。

自動起動スクリプトの作成

cat <<- __EOF__ | sudo tee -a /etc/systemd/system/growi.service
[Unit]
Description = growi
After=network-online.target mongod.service
ConditionPathExists=【/home/www-data/growi】

[Service]
ExecStart=【/home/www-data/growi/】growi-start.sh
Restart=no
Type=simple

[Install]
WantedBy=multi-user.target
__EOF__

※【】内を、git cloneしたディレクトリにします。

#!/bin/bash
cd 【/home/www-data/growi】
NODE_ENV=production \
AUDIT_LOG_ENABLED=true \
FORCE_WIKI_MODE=private \
MONGO_URI=mongodb://localhost:27017/growi \
ELASTICSEARCH_URI=http://localhost:9200/growi \
REDIS_URI=redis://localhost:6379 \
PASSWORD_SEED=[任意の文字列] \
FILE_UPLOAD=local \
npm start

※【】内を、git cloneしたディレクトリにします。 []内には任意の文字列を入れます。 例:PASSWORD_SEED=GOLDEN_SEED

また、オプションなどは好みに応じて指定してください。(FILE_UPLOAD=localは添付ファイルの保存先をDBではなくローカルに保存するオプションです)

sudo chmod +x /home/www-data/growi/growi-start.sh
sudo systemctl daemon-reload
sudo systemctl start growi.service
systemctl status growi.service

active(running)を確認

sudo systemctl enable growi.service

Apacheによるリバースプロキシの設定

sudo a2enmod proxy_http rewrite header
sudo systemctl restart apache2.service
suod mkdir /var/log/growi/
sudo chown -R www-data:www-data /var/log/growi
cat <<- __EOF__ | sudo tee -a /etc/apache2/sites-available/growi.conf
<VirtualHost _default_:80>
    ServerName 【hoge.example.com】
    # ドメイン名を指定します
    RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# HTTPアクセスを強制的にHTTPSにリダイレクトします
</VirtualHost>

<VirtualHost _default_:443>
    ServerName 【hoge.example.com】
    # ドメイン名を指定します
    CustomLog /var/log/growi/growi_access.log combined 
    ErrorLog /var/log/growi/growi_error.log

#SSL設定
  SSLEngine on
    Protocols h2 http/1.1
  # SSLを有効化します

SSLCertificateFile 【/etc/certs/hoge.example.com.crt】
# SSL証明書を指定します
SSLCertificateKeyFile 【/etc/private/hoge.example.com.key】
# 秘密鍵を指定します

    # Header に Host: example.com を追加するため
    ProxyPreserveHost On
    # HTTPS利用時: Header に x-forwarded-proto: https を追加するため
    RequestHeader set x-forwarded-proto 'https'
    # Apache では static assets で 304 が返らないことがあるので ETag を無効化する
    <ifModule mod_headers.c>
            Header unset ETag
    </ifModule>
    FileETag None

    # socket.io の path を rewrite する
    RewriteEngine On
    RewriteCond %{REQUEST_URI}  ^/socket.io            [NC]
    RewriteCond %{QUERY_STRING} transport=websocket    [NC]
    RewriteRule /(.*) ws://localhost:3000/$1 [P,L]

    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/

</VirtualHost>

SSLProtocol             all -SSLv3 -TLSv1 -TLSv1.1 -TLSv1.2
SSLCipherSuite          ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:EC6-GCM-SHA384
SSLHonorCipherOrder     off
SSLSessionTickets       off
__EOF__

【】内を自分の環境に変更してください。

※v7とはWebSocketの書き方が異なります。ご注意ください。

sudo a2ensite growi.conf
sudo apache2ctl configtest

Syntax OKを確認します。

sudo systemctl restart apache2.service

Growiインストール確認

http://設定したドメイン でアクセスします。

この初期サイトが表示されたらインストール完了です。


Revision #8
Created 3 April 2024 14:52:46 by manualmaton
Updated 27 June 2024 16:40:55 by manualmaton