Contents
- 1 GROWIについて
- 2 サーバー構築
- 3 設定
- 3.1 設定項目
- 3.1.1 MONGO_URI
- 3.1.2 NODE_ENV
- 3.1.3 PORT
- 3.1.4 ELASTICSEARCH_URI
- 3.1.5 REDIS_URI
- 3.1.6 PASSWORD_SEED
- 3.1.7 SECRET_TOKEN
- 3.1.8 SESSION_NAME
- 3.1.9 FILE_UPLOAD
- 3.1.10 HACKMD_URI
- 3.1.11 HACKMD_URI_FOR_SERVER
- 3.1.12 PLANTUML_URI
- 3.1.13 BLOCKDIAG_URI
- 3.1.14 OAUTH_GOOGLE_CLIENT_ID
- 3.1.15 OAUTH_GOOGLE_CLIENT_SECRET
- 3.1.16 OAUTH_GITHUB_CLIENT_ID
- 3.1.17 OAUTH_GITHUB_CLIENT_SECRET
- 3.1.18 OAUTH_TWITTER_CONSUMER_KEY
- 3.1.19 OAUTH_TWITTER_CONSUMER_SECRET
- 3.1.20 SAML_ENTRY_POINT
- 3.1.21 SAML_ISSUER
- 3.1.22 SAML_CERT
- 3.1 設定項目
- 4 運用
GROWIについて
Markdown系のWikiサーバーである。以前はcrowi-plusの名前で開発されていた。
JavaScript(Node.js)で開発されており、DBにはmongodbを使用している。
公式ページ
- 閲覧のみのゲストアカウントを使用可能
- メニューの日本語対応可能
- 差分表示機能有
- 画像以外の添付が可能
- 全文検索を行うにはElasticsearchが必要
- 公開範囲を設定可能
用語
サーバー構築
構築環境
- GROWI
3.2.9
パッケージ版は3.4.12-1.el7
- OS
CentOS 7.5
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を開ける
- 現在ルールが定義されていることを確認
firewall-cmd --permanent --info-service=http
- 現在ルールが適用されていないことを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep http
- ルールを適用する
firewall-cmd --add-service=http --zone=public --permanent
- ルールが適用されていることを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep http
- 設定を再読み込みして反映させる
firewall-cmd --reload
HTTPSも開ける場合
- 現在ルールが定義されていることを確認
firewall-cmd --permanent --info-service=https
- 現在ルールが適用されていないことを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep https
- ルールを適用する
firewall-cmd --add-service=https --zone=public --permanent
- ルールが適用されていることを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep https
- 設定を再読み込みして反映させる
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*
- 日本語対応の為のプラグインをインストールする
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のインストール
- 関連パッケージをインストールする
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
- ソースコードを取得する
- 最新版のURLを取得する
https://github.com/weseek/growi/releases - ダウンロードする
curl -s https://codeload.github.com/weseek/growi/zip/v3.2.10 -o growi.zip
- アーカイブファイルを展開する
unzip growi.zip rm -f growi.zip
- インストールディレクトリへ移動させる
mv growi-* /usr/local/
- 最新版のURLを取得する
- リンク作成、環境変数設定などを行う
- インストールディレクトリへのシンボリックリンクを作成する。
これによって、複数のバージョンを同居させ、リンクを切り替えることで、バージョン変更が可能となる。
各バージョンの実行ファイルはデフォルトでは各バージョンの設定ファイルを読み込むこととなる。
rm -f /usr/local/growi ln -s `ls -d /usr/local/growi-*` /usr/local/growi
- 簡単にアクセスできるように環境変数を設定する
export GROWI_HOME=/usr/local/growi
- 環境変数を再起動後も有効にする
echo "" >> /etc/bashrc echo "# GROWI ENVIRONMENT VARIABLE" >> /etc/bashrc echo "export GROWI_HOME=$GROWI_HOME" >> /etc/bashrc
- インストールディレクトリへのシンボリックリンクを作成する。
- 関連パッケージのインストールを行う
cd $GROWI_HOME yarn
- systemdの設定する
- サービスファイルを作成する
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
- サービスを有効化する
systemctl enable growi
- サービスが有効化されていることを確認する
systemctl list-unit-files --type service --no-pager | grep growi
- サービスファイルを作成する
- 設定ファイルを作成する
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
- GROWIを起動する
systemctl start growi
- 稼働確認
systemctl status growi
正常に起動していない場合、ログを確認する。
journalctl -u growi cat /var/log/messages
- GROWIがインストールされたサーバにWebブラウザでアクセスする
http://<IPアドレス>:3000/
※起動には数分かかる - 管理者アカウントを作成する
- 管理者アカウントでログインする
設定
設定項目
MONGO_URI
MongoDBのURIを指定する。
この設定のみ必須である。
- 設定値
MONGO_URI="mongodb://<IPアドレス>[:<ポート番号>]/<パス>"
- 設定例
MONGO_URI="mongodb://localhost/growi"
- デフォルト
なし
NODE_ENV
production OR development.
PORT
使用するポート番号
- デフォルト
PORT=3000
ELASTICSEARCH_URI
Elastic SearchのURIを指定する。
- 設定値
ELASTICSEARCH_URI="http://<IPアドレス>:<ポート番号>/<パス>"
- 設定例
ELASTICSEARCH_URI="http://localhost:9200/growi"
REDIS_URI
RedisのURIを指定する。
- 設定値
REDIS_URI="redis://<IPアドレス>[:<ポート番号>]/<パス>"
- 設定例
REDIS_URI="redis://localhost/growi"
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
ファイルをアップロードした際の格納場所を指定する。
- 書式
FILE_UPLOAD=<格納場所>
- 格納場所
- aws
AWS S3に保存する。デフォルト。
※管理者ページからAWSアカウントの設定が必要である。 - mongodb
MongoDBのGridFSに保存される。 - local
サーバローカルに保存する。 - none
ファイルアップロードを禁止する
- aws
- 格納場所
- デフォルト
FILE_UPLOAD=aws
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
管理者ページから上書き可能。
運用
アカウント
言語設定
使用する言語を変更できる。
- 右上のアカウントアイコンをクリックする
- User Information
- Basic Info
- LanguageをJapaneseに変更する
- Update
- 次に開いたページから日本語になる
全文検索
インデックス再作成
ElasticSearchを再インストールした等でインデックスを再作成したい場合は以下を行う
- 管理者でログインする
- 管理
- 全文検索管理
- Build Now
“Data is successfully indexed.”と表示されること