在Ubuntu 18.04上安装Growi
简明摘要这是在Ubuntu(18.04)上安装Growi的步骤的备忘录。
我基本上遵循官方流程。
考虑到在局域网中的使用,我没有配置反向代理或防火墙。
此外,我只安装了一个node.js版本,所以如果要使用nvm等工具,可能需要进行路径设置。
按照上述顺序进行复制粘贴,应该可以将Growi最低限度地运行起来。
必需的环境在GitHub上查看,必要的环境如下所示。
-
node.js 8.x (DO NOT USE 9.x)
- node.js 8.x (DO NOT USE 9.x)
-
- npm 5.x
-
- yarn
-
- MongoDB 3.x
-
- Redis 3.x (Optional)
-
- Elasticsearch 5.x (Optional)
Japanese (kuromoji) Analysis plugin
ICU Analysis Plugin
安装
Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行时。安装Node.js 8.x版本。同时也会安装npm。
$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$ sudo apt install -y nodejs
$ node -v
v8.11.4
$ npm -v
v5.6.0
纱线如果默认情况下安装了cmdtest,则如果出现错误,需要先删除再安装。请参考官方文档。
$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt-get update && sudo apt-get install yarn
$ yarn -v
1.9.4
摩哥DB (Mogē DB)可以正常安装。
$ sudo apt update
$ sudo apt install -y mongodb mongodb-server mongo-tools
$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$ sudo apt install -y nodejs
$ node -v
v8.11.4
$ npm -v
v5.6.0
纱线如果默认情况下安装了cmdtest,则如果出现错误,需要先删除再安装。请参考官方文档。
$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt-get update && sudo apt-get install yarn
$ yarn -v
1.9.4
摩哥DB (Mogē DB)可以正常安装。
$ sudo apt update
$ sudo apt install -y mongodb mongodb-server mongo-tools
$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt-get update && sudo apt-get install yarn
$ yarn -v
1.9.4
$ sudo apt update
$ sudo apt install -y mongodb mongodb-server mongo-tools
启动服务并进行确认。
$ sudo systemctl start mongodb
$ sudo systemctl status mongodb
Active: 如果状态为active(运行中),就可以了。
设定自动启动。
$ sudo systemctl enable mongodb
确认版本(使用exit以退出)
$ mongo
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
Server has startup warnings:
:
> exit
bye
弹性搜索这里有公式文件。让它可以通过apt来安装。
首先,确认是否已安装了Java8。
$ java --version
Command 'java' not found, but can be installed with:
sudo apt install default-jre
sudo apt install openjdk-11-jre-headless
sudo apt install openjdk-8-jre-headless
$ java --version
Command 'java' not found, but can be installed with:
sudo apt install default-jre
sudo apt install openjdk-11-jre-headless
sudo apt install openjdk-8-jre-headless
被告知未被录取,所以按照所注明的进行录取。
$ sudo apt install -y default-jre openjdk-11-jre-headless openjdk-8-jre-headless
$ java --version
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.1)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.1, mixed mode)
确认安装路径,并将JAVA_HOME设置为java8。
$ update-alternatives --list java
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
$ cd /etc/profile.d/
$ sudo vi java.sh
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
您可以先登出一次,然后确认一下JAVA_HOME的设置。
$ echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64
设定Elasticsearch存储库并进行安装。
$ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
$ echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list
$ sudo apt update
$ sudo apt install -y 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
$ sudo systemctl status elasticsearch
如果发生错误,可能是因为内存不足。要设置内存使用量(以下为256MB的情况)。
$ sudo vi /etc/elasticsearch/jvm.options
-Xms256m
-Xmx256m
自动启动的设置
$ sudo systemctl enable elasticsearch
确认运动
$ curl localhost:9200
Redis 是一种高性能的开源内存数据结构存储系统。Redis是REmote DIctionary Server的简称,指的是一种Key-Value类型的NoSQL数据库。它在Elasticsearch中被使用。详细信息请参阅官方文档。
添加存储库并检查版本。
$ sudo add-apt-repository ppa:chris-lea/redis-server
$ sudo apt update
$ sudo apt show redis-server
安装
$ sudo apt install -y redis-server
$ redis-cli --version
$ redis-server --version
启动服务并进行确认。
$ sudo systemctl start redis-server
$ sudo systemctl status redis-server
設定自動啟動。
$ sudo systemctl enable redis-server
成长
根据公式,在 /opt/groiw 上进行安装。检查标签并创建最新版本的分支(最新版本是 ver3.2.1),使用 yarn 进行安装。
$ cd /opt
$ sudo git clone https://github.com/weseek/growi
$ cd growi
$ sudo git tag -l
$ sudo git checkout -b v3.2.1 refs/tags/v3.2.1
$ sudo yarn
$ cd /opt
$ sudo git clone https://github.com/weseek/growi
$ cd growi
$ sudo git tag -l
$ sudo git checkout -b v3.2.1 refs/tags/v3.2.1
$ sudo yarn
使用以下步骤进行启动确认。
sudo \
NODE_ENV=production \
MONGO_URI=mongodb://localhost:27017/growi \
ELASTICSEARCH_URI=http://localhost:9200/growi \
REDIS_URI=redis://localhost:6379 \
PASSWORD_SEED=xxxx (MAX64文字のランダム文字列) \
FILE_UPLOAD=local \
npm start
电脑性能较好的情况下,若在大约1分钟内出现[production] Express server listening on port 3000的显示,则说明启动成功。
在浏览器中打开http://serverIP:3000/,并确认是否显示初始页面。
※若防火墙开启,则需要开放相应的端口。
确认完毕后,按Ctrl+C结束。
※PASSWORD_SEED用于密码加密,一旦更改将导致无法登录。请确保一旦设定就不要进行更改。
可以从启动Mongo后显示的日志中确认MONGO_URI的设置。
$ mongo
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
我需要获取第2行的”mongodb://127.0.0.1:27017″信息。其中127.0.0.1可以理解为本地主机。
我不清楚ELASTICSEARCH_URI(^^;
Growi的自动启动设置创建一个名为xxx.service的文件并将其注册为自动启动的服务,文件名(xxx)可以任意。
$ sudo vi /etc/systemd/system/growi.service
[Unit]
Description = growi
After=network-online.target mongod.service
ConditionPathExists=/opt/growi
[Service]
ExecStart=/opt/growi/growi-start.sh
Restart=no
Type=simple
[Install]
WantedBy=multi-user.target
$ sudo vi /etc/systemd/system/growi.service
[Unit]
Description = growi
After=network-online.target mongod.service
ConditionPathExists=/opt/growi
[Service]
ExecStart=/opt/growi/growi-start.sh
Restart=no
Type=simple
[Install]
WantedBy=multi-user.target
描述:可以写任何内容的说明文字。
之后:指定启动顺序。设置在network和mongod启动后开始。
ConditionPathExists:安装目录。
ExecStart:启动脚本。
其他的无需特别调整。
修改所创建文件的权限。
$ sudo chown root:root /etc/systemd/system/growi.service
$ sudo chmod 644 /etc/systemd/system/growi.service
创建启动脚本。
在growi.service的ExecStart设置的路径中创建。
服务将以root权限运行,所以不需要sudo。
$ sudo vi /opt/growi/growi-start.sh
#!/bin/sh
cd /opt/growi
NODE_ENV=production \
MONGO_URI=mongodb://localhost:27017/growi \
ELASTICSEARCH_URI=http://localhost:9200/growi \
REDIS_URI=redis://localhost:6379 \
PASSWORD_SEED=xxxx (MAX64文字のランダム文字列) \
FILE_UPLOAD=local \
npm start
授予执行权限。
$ sudo chmod +x /opt/growi/growi-start.sh
重新启动 Daemon 并启动和验证 Growi 服务。
$ sudo systemctl daemon-reload
$ sudo systemctl start growi.service
$ sudo systemctl status growi.service
开始后,由于Growi需要一些时间才能启动,所以请稍等片刻后再检查状态。如果最后显示”[production] Express server listening on port 3000″,那就可以了。
查看systemctl日志的方法
$ sudo journalctl -u growi -b
设定自动启动。
$ sudo systemctl enable growi.service
写笔记数据的位置等。
-
本文
- 本文
-
- mongodb内にある(はず)。
- バックアップやリストアは、mongoの手順通りにやればできる。
$ mongo
> use growi
> db.getCollectionNames()
> db.pages.find()
:
-
- アップロードしたファイル
-
- 投稿した記事を開くと、ページ上部にhttp://xxx.xxx.xxx.xxx:3000/5b9a12e799eea20ca1c79bddのようなリンクが表示されている。
- /opt/growi/public/uploads/attachmentにリンクと同じ文字列のディレクトリが生成され、その中に保存されている。
参考来源的网站
-
GROWI Docs
- GROWI Docs
-
- Growi(github)
-
- CentOS7.5にGrowiをインストール
-
- How To Install MongoDB on Ubuntu 18.04 LTS
-
- systemdを用いたプログラムの自動起動
- UbuntuにElasticsearchをインストールして使えるようにするまで