GROWI

Contents

GROWIについて


Markdown系のWikiサーバーである。以前はcrowi-plusの名前で開発されていた。
JavaScript(Node.js)で開発されており、DBにはmongodbを使用している。
公式ページ


用語




サーバー構築


構築環境




OS設定


ネットワーク


固定IPアドレス割り当て


次のファイルを編集する
# ifcfg-loはループバックインタフェースであるため、触らない
vi /etc/sysconfig/network-scripts/ifcfg-<インタフェース名>

以下では例として192.168.0.51/24を割り当てた
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.0.51
NETMASK=255.255.255.0
NETWORK=192.168.0.0
GATEWAY=192.168.0.1

ネットワークを再起動する
systemctl restart network

ip addressコマンドにより、インタフェースが有効になっていることを確認する
これによりホストマシンなどからSSHでログイン可能となる


firewalld


HTTPを開ける

  1. 現在ルールが定義されていることを確認
    firewall-cmd --permanent --info-service=http
  2. 現在ルールが適用されていないことを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep http
  3. ルールを適用する
    firewall-cmd --add-service=http --zone=public --permanent
  4. ルールが適用されていることを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep http
  5. 設定を再読み込みして反映させる
    firewall-cmd --reload

HTTPSも開ける場合

  1. 現在ルールが定義されていることを確認
    firewall-cmd --permanent --info-service=https
  2. 現在ルールが適用されていないことを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep https
  3. ルールを適用する
    firewall-cmd --add-service=https --zone=public --permanent
  4. ルールが適用されていることを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep https
  5. 設定を再読み込みして反映させる
    firewall-cmd --reload

GROWI用ポートを開ける場合

GROWIはデフォルトではTCP/3000を使用する。ApacheなどのWebサーバを使用せず、かつGROWIのデフォルトポートを使用する場合は、このポートを開放する必要がある。


ホスト名


ホスト名としてgrowiを設定する
# 再起動しても有効にする
hostnamectl set-hostname growi.corp
再ログインすることで有効になる。

ユーザ作成


GROWI用のユーザを作成する
useradd --user-group --no-create-home --shell /sbin/false growi

Apacheの構築


Apacheのインストール


参考:apache2.4.34

今回はバージョン2.4.34をソースコードインストールしたとする。


Apacheの設定


cat >> $APACHE_HOME/conf/httpd.conf << EOT

# GROWI Configuration
ProxyPass /growi http://127.0.0.1:3000/
EOT

Elasticsearchの構築


Javaのインストール


java8u192

Elasticsearchのインストール


参考

バージョン6は使用できない。
使用すると、次のようなエラーが出る。
Error: [illegal_argument_exception] Rejecting mapping update to [growi] as the final mapping would have more than 1 type: [pages, users] :: {"path":"/growi","query":{},"body":"{\"settings\":{\"analysis\":{\"filter\":{\"english_stop\":{\"type\":\"stop\",\"stopwords\":\"_english_\"},\"english_stemmer\":{\"type\":\"stemmer\",\"language\":\"english\"},\"english_possessive_stemmer\":{\"type\":\"stemmer\",\"language\":\"possessive_english\"}},\"tokenizer\":{\"ngram_tokenizer\":{\"type\":\"ngram\",\"min_gram\":2,\"max_gram\":3,\"token_chars\":[\"letter\",\"digit\"]}},\"analyzer\":{\"autocomplete\":{\"tokenizer\":\"keyword\",\"filter\":[\"lowercase\",\"nGram\"]},\"japanese\":{\"tokenizer\":\"kuromoji_tokenizer\",\"char_filter\":[\"icu_normalizer\"]},\"english\":{\"tokenizer\":\"ngram_tokenizer\",\"filter\":[\"english_possessive_stemmer\",\"lowercase\",\"english_stop\",\"english_stemmer\"]}}}},\"mappings\":{\"users\":{\"properties\":{\"name\":{\"type\":\"text\",\"analyzer\":\"autocomplete\"}}},\"pages\":{\"properties\":{\"path\":{\"type\":\"text\",\"copy_to\":[\"path_raw\",\"path_ja\",\"path_en\"],\"index\":\"false\"},\"path_raw\":{\"type\":\"text\",\"analyzer\":\"standard\"},\"path_ja\":{\"type\":\"text\",\"analyzer\":\"japanese\"},\"path_en\":{\"type\":\"text\",\"analyzer\":\"english\"},\"body\":{\"type\":\"text\",\"copy_to\":[\"body_raw\",\"body_ja\",\"body_en\"],\"index\":\"false\"},\"body_raw\":{\"type\":\"text\",\"analyzer\":\"standard\"},\"body_ja\":{\"type\":\"text\",\"analyzer\":\"japanese\"},\"body_en\":{\"type\":\"text\",\"analyzer\":\"english\"},\"username\":{\"type\":\"text\"},\"comment_count\":{\"type\":\"integer\"},\"bookmark_count\":{\"type\":\"integer\"},\"like_count\":{\"type\":\"integer\"},\"created_at\":{\"type\":\"date\",\"format\":\"dateOptionalTime\"},\"updated_at\":{\"type\":\"date\",\"format\":\"dateOptionalTime\"}}}}}","statusCode":400,"response":"{\"error\":{\"root_cause\":[{\"type\":\"illegal_argument_exception\",\"reason\":\"Rejecting mapping update to [growi] as the final mapping would have more than 1 type: [pages, users]\"}],\"type\":\"illegal_argument_exception\",\"reason\":\"Rejecting mapping update to [growi] as the final mapping would have more than 1 type: [pages, users]\"},\"status\":400}"}

最新版を確認する
https://www.elastic.co/guide/en/elasticsearch/reference/5.6/es-release-notes.html
curl -s -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.13.tar.gz
tar xvzf elasticsearch-5.6.13.tar.gz
mv elasticsearch-5.6.13 /usr/local/
ln -s /usr/local/elasticsearch-5.6.13 /usr/local/elasticsearch
export ELASTICSEARCH_HOME=/usr/local/elasticsearch
export PATH=$ELASTICSEARCH_HOME/bin:$PATH
echo "" >> /etc/bashrc
echo "# ELASTICSEARCH ENVIRONMENT VARIABLE" >> /etc/bashrc
echo "export ELASTICSEARCH_HOME=$ELASTICSEARCH_HOME" >> /etc/bashrc
echo "export PATH=\$ELASTICSEARCH_HOME/bin:\$PATH" >> /etc/bashrc
rm -f $ELASTICSEARCH_HOME/bin/*.bat
useradd --user-group --no-create-home --shell /sbin/false elasticsearch
chown elasticsearch:elasticsearch -R /usr/local/elasticsearch*
  1. 日本語対応の為のプラグインをインストールする
    elasticsearch-plugin install analysis-kuromoji
    elasticsearch-plugin install analysis-icu
    cat > /etc/systemd/system/elasticsearch.service << EOT
    [Unit]
    Description=Elasticsearch server
    After=local-fs.target network.target network-online.target
    
    [Service]
    Type=forking
    User=elasticsearch
    Group=elasticsearch
    EnvironmentFile=$ELASTICSEARCH_HOME/config/service-env
    ExecStart=$ELASTICSEARCH_HOME/bin/elasticsearch -d -p $ELASTICSEARCH_HOME/logs/elasticsearch.pid
    ExecStop=/bin/kill -SIGTERM $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    EOT
    cat > $ELASTICSEARCH_HOME/config/service-env << EOT
    JAVA_HOME=$JAVA_HOME
    EOT
    systemctl enable elasticsearch
    systemctl start elasticsearch
    curl http://localhost:9200/

Redisの構築


セッション格納用にRedisを使用することができる。
Redisを使用しない場合は、MongoDBにセッション情報が格納される。

yum install epel-release -y
yum install redis -y
systemctl enable redis
systemctl start redis

MongoDBの構築


MongoDBのインストール


ソースコードからインストール



yum install cyrus-sasl cyrus-sasl-gssapi cyrus-sasl-plain krb5-libs libcurl libpcap lm_sensors-libs net-snmp net-snmp-agent-libs openldap openssl rpm-libs tcp_wrappers-libs -y
curl -s -O https://downloads.mongodb.com/linux/mongodb-linux-x86_64-enterprise-rhel70-4.0.4.tgz
tar xvzf mongodb-linux-x86_64-enterprise-*.tgz
rm -f mongodb-linux-x86_64-enterprise-*.tgz
mv mongodb-linux-x86_64-enterprise-* /usr/local/mongodb-`ls -d mongodb* | sed "s/.*-//"`
ln -s /usr/local/mongodb-* /usr/local/mongodb
export MONGODB_HOME=/usr/local/mongodb
export PATH=$MONGODB_HOME/bin:$PATH
echo "" >> /etc/bashrc
echo "# MONGODB ENVIRONMENT VARIABLE" >> /etc/bashrc
echo "export MONGODB_HOME=$MONGODB_HOME" >> /etc/bashrc
echo "export PATH=\$MONGODB_HOME/bin:\$PATH" >> /etc/bashrc
useradd --user-group --no-create-home --shell /sbin/false mongod
mkdir $MONGODB_HOME/log/ $MONGODB_HOME/data/
cat > $MONGODB_HOME/mongod.conf << EOT
systemLog:
  destination: file
  logAppend: true
  path: $MONGODB_HOME/log/mongod.log

storage:
  dbPath: $MONGODB_HOME/data
  journal:
    enabled: true

processManagement:
  fork: true
  pidFilePath: $MONGODB_HOME/mongod.pid
  timeZoneInfo: /usr/share/zoneinfo

net:
  port: 27017
  bindIp: 127.0.0.1
EOT
chown mongod:mongod -R /usr/local/mongodb*
cat > /etc/systemd/system/mongod.service << EOT
[Unit]
Description=MongoDB Database Server
After=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f $MONGODB_HOME/mongod.conf"
#EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=$MONGODB_HOME/bin/mongod \$OPTIONS
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
PermissionsStartOnly=true
PIDFile=$MONGODB_HOME/mongod.pid
Type=forking
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

[Install]
WantedBy=multi-user.target
EOT
systemctl enable mongod
systemctl start mongod


パッケージからインストール


curl -s -O https://repo.mongodb.com/yum/redhat/7/mongodb-enterprise/4.0/x86_64/RPMS/mongodb-enterprise-server-4.0.4-1.el7.x86_64.rpm
yum localinstall mongodb-enterprise-server-4.0.4-1.el7.x86_64.rpm

GROWIの構築


GROWIのインストール



  1. 関連パッケージをインストールする
    curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
    curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
    yum install unzip nodejs yarn -y
  2. ソースコードを取得する
    1. 最新版のURLを取得する
      https://github.com/weseek/growi/releases
    2. ダウンロードする
      curl -s https://codeload.github.com/weseek/growi/zip/v3.2.10 -o growi.zip
    3. アーカイブファイルを展開する
      unzip growi.zip
      rm -f growi.zip
    4. インストールディレクトリへ移動させる
      mv growi-* /usr/local/
  3. リンク作成、環境変数設定などを行う
    1. インストールディレクトリへのシンボリックリンクを作成する。
      これによって、複数のバージョンを同居させ、リンクを切り替えることで、バージョン変更が可能となる。
      各バージョンの実行ファイルはデフォルトでは各バージョンの設定ファイルを読み込むこととなる。
      rm -f /usr/local/growi
      ln -s `ls -d /usr/local/growi-*` /usr/local/growi
    2. 簡単にアクセスできるように環境変数を設定する
      export GROWI_HOME=/usr/local/growi
    3. 環境変数を再起動後も有効にする
      echo "" >> /etc/bashrc
      echo "# GROWI ENVIRONMENT VARIABLE" >> /etc/bashrc
      echo "export GROWI_HOME=$GROWI_HOME" >> /etc/bashrc
  4. 関連パッケージのインストールを行う
    cd $GROWI_HOME
    yarn
  5. systemdの設定する
    1. サービスファイルを作成する
      cat > /etc/systemd/system/growi.service << EOT
      [Unit]
      Description=GROWI Server
      After=network.target
      After=mongod.service
      After=elasticsearch.service
      After=redis.service
      
      [Service]
      WorkingDirectory=$GROWI_HOME
      EnvironmentFile=$GROWI_HOME/growi.env
      ExecStart=`which npm` start
      ExecStop=/bin/kill -SIGTERM \$MAINPID
      Type=simple
      
      [Install]
      WantedBy=multi-user.target
      EOT
    2. サービスを有効化する
      systemctl enable growi
    3. サービスが有効化されていることを確認する
      systemctl list-unit-files --type service --no-pager | grep growi
  6. 設定ファイルを作成する
    cat > $GROWI_HOME/growi.env << EOT
    PORT=3000
    NODE_ENV=production
    PASSWORD_SEED="`openssl rand -base64 128 | head -1`"
    MONGO_URI="mongodb://localhost/growi"
    ELASTICSEARCH_URI=http://localhost:9200/growi
    FILE_UPLOAD=local
    EOT
  7. GROWIを起動する
    systemctl start growi
  8. 稼働確認
    systemctl status growi
    正常に起動していない場合、ログを確認する。
    journalctl -u growi
    cat /var/log/messages
  9. GROWIがインストールされたサーバにWebブラウザでアクセスする
    http://<IPアドレス>:3000/
    ※起動には数分かかる
  10. 管理者アカウントを作成する
  11. 管理者アカウントでログインする

設定


設定項目


MONGO_URI


MongoDBのURIを指定する。
この設定のみ必須である。




NODE_ENV



production OR development.

PORT


使用するポート番号


ELASTICSEARCH_URI


Elastic SearchのURIを指定する。



REDIS_URI


RedisのURIを指定する。



PASSWORD_SEED



A password seed used by password hash generator.

SECRET_TOKEN



A secret key for verifying the integrity of signed cookies.

SESSION_NAME



The name of the session ID cookie to set in the response by Express. default
connect.sid

FILE_UPLOAD


ファイルをアップロードした際の格納場所を指定する。



HACKMD_URI



URI to connect to HackMD(CodiMD) server.
           This server must load the GROWI agent. Here's how to prepare it.

HACKMD_URI_FOR_SERVER



URI to connect to HackMD(CodiMD) server from GROWI Express server. If not set, HACKMD_URI will be used.

PLANTUML_URI



URI to connect to PlantUML server.

BLOCKDIAG_URI



URI to connect to blockdiag server.
   Option (Overwritable in admin page)

OAUTH_GOOGLE_CLIENT_ID



Google API client id for OAuth login.
管理者ページから上書き可能。

OAUTH_GOOGLE_CLIENT_SECRET



Google API client secret for OAuth login.
管理者ページから上書き可能。

OAUTH_GITHUB_CLIENT_ID



GitHub API client id for OAuth login.
管理者ページから上書き可能。

OAUTH_GITHUB_CLIENT_SECRET



GitHub API client secret for OAuth login.
管理者ページから上書き可能。

OAUTH_TWITTER_CONSUMER_KEY



Twitter consumer key(API key) for OAuth login.
管理者ページから上書き可能。

OAUTH_TWITTER_CONSUMER_SECRET



Twitter consumer secret(API secret) for OAuth login.
管理者ページから上書き可能。

SAML_ENTRY_POINT



IdP entry point
管理者ページから上書き可能。

SAML_ISSUER



Issuer string to supply to IdP
管理者ページから上書き可能。

SAML_CERT



PEM-encoded X.509 signing certificate string to validate the response from IdP
管理者ページから上書き可能。




運用


アカウント


言語設定


使用する言語を変更できる。

  1. 右上のアカウントアイコンをクリックする
  2. User Information
  3. Basic Info
  4. LanguageをJapaneseに変更する
  5. Update
  6. 次に開いたページから日本語になる

全文検索


インデックス再作成


ElasticSearchを再インストールした等でインデックスを再作成したい場合は以下を行う

  1. 管理者でログインする
  2. 管理
  3. 全文検索管理
  4. Build Now
    “Data is successfully indexed.”と表示されること

Notice: Trying to get property 'queue' of non-object in /usr/local/wordpress/wp-includes/script-loader.php on line 2876

Warning: Invalid argument supplied for foreach() in /usr/local/wordpress/wp-includes/script-loader.php on line 2876