作者:冥王星 "noright0@163.com"
前言
宿舍有個樹莓派2B,連接到電視機,安裝OSMC系統,USB接口連接移動硬盤一塊,平時用來BT下載和看電影、美劇。
OSMC是基於Debian系統的,可以通過apt-get安裝軟件,軟件倉庫中有mongodb,而leanote也有相應的用於arm的二進制包,所以把leanote安裝到樹莓派是可行的。
mongodb 部分
安裝mongodb
sudo apt-get install mongodb
安裝軟件一般我都用aptitude
配置mongodb運行的用戶名
OSMC系統使用的是systemd,mongodb服務啟動是在這個文件配置的:/etc/systemd/system/multi-user.target.wants/mongodb.service
文件的內容如下:
[Unit]
Description=An object/document-oriented database
Documentation=man:mongod(1)
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --config /etc/mongodb.conf
[Install]
WantedBy=multi-user.target
我們把User=mongodb
改為User=osmc
,使其用osmc
身份運行。(只是為了方便)
運行命令使配置生效。
sudo systemctl daemon-reload
修改mongodb配置文件
從上邊的啟動配置文件中可以看出,mongodb啟動時讀取/etc/mongodb.conf
作為配置文件,這個文件的內容如下:
# mongodb.conf
# Where to store the data.
dbpath=/data/db
#where to log
logpath=/data/log/mongodb.log
logappend=true
bind_ip = 127.0.0.1
#port = 27017
# Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
journal=true
# Enables periodic logging of CPU utilization and I/O wait
#cpu = true
# Turn on/off security. Off is currently the default
#noauth = true
#auth = true
# Verbose logging output.
#verbose = true
# Inspect all client data for validity on receipt (useful for
# developing drivers)
#objcheck = true
# Enable db quota management
#quota = true
# Set oplogging level where n is
# 0=off (default)
# 1=W
# 2=R
# 3=both
# 7=W+some reads
#oplog = 0
# Diagnostic/debugging option
#nocursors = true
# Ignore query hints
#nohints = true
# Disable the HTTP interface (Defaults to localhost:27018).
#nohttpinterface = true
# Turns off server-side scripting. This will result in greatly limited
# functionality
#noscripting = true
# Turns off table scans. Any query that would do a table scan fails.
#notablescan = true
# Disable data file preallocation.
#noprealloc = true
# Specify .ns file size for new databases.
# nssize = <size>
# Accout token for Mongo monitoring server.
#mms-token = <token>
# Server name for Mongo monitoring server.
#mms-name = <server-name>
# Ping interval for Mongo monitoring server.
#mms-interval = <seconds>
# Replication Options
# in replicated mongo databases, specify here whether this is a slave or master
#slave = true
#source = master.example.com
# Slave only: specify a single database to replicate
#only = master.example.com
# or
#master = true
#source = slave.example.com
# Address of a server to pair with.
#pairwith = <server:port>
# Address of arbiter server.
#arbiter = <server:port>
# Automatically resync if slave data is stale
#autoresync
# Custom size for replication operation log.
#oplogSize = <MB>
# Size limit for in-memory storage of op ids.
#opIdMem = <bytes>
# SSL options
# Enable SSL on normal ports
#sslOnNormalPorts = true
# SSL Key file and password
#sslPEMKeyFile = /etc/ssl/mongodb.pem
#sslPEMKeyPassword = pass
我們只需要修改數據庫文件目錄和日志文件的文件名。
因為樹莓派的系統安裝在TF卡上,頻繁讀寫不僅速度慢,而且容易壞卡。而我的樹莓派長期連接一個移動硬盤,所有把數據庫文件和日志文件放到移動硬盤也就順理成章了。
# Where to store the data.
dbpath=/media/sea2t/srv/db
#where to log
logpath=/media/sea2t/srv/log/mongodb.log
啟動mongodb
# 啟動命令
sudo service mongodb start
# 停止命令
sudo service mongodb stop
# 查看狀態
sudo service mongodb status
leanote 部分
下載二進制安裝包
從官網下載 leanote 的 for arm 的二進制文件。下載地址在這個網站:http://leanote.org/#download
https://sourceforge.net/projects/leanote-bin/files/2.0/leanote-linux-arm-v2.0.bin.tar.gz/download
解壓文件
把安裝包解壓至移動硬盤。
/media/sea2t/srv/leanote
修改 leanote 配置文件
leanote的配置文件在這里:
/media/sea2t/srv/leanote/conf/app.conf
內容是這樣的:
#------------------------
# leanote config
#------------------------
http.port=9000
site.url=http://localhost:9000 # or http://x.com:8080, http://www.xx.com:9000
# admin username
adminUsername=admin
# mongdb
db.host=127.0.0.1
db.port=27017
db.dbname=leanote # required
db.username= # if not exists, please leave it blank
db.password= # if not exists, please leave it blank
# or you can set the mongodb url for more complex needs the format is:
# mongodb://myuser:mypass@localhost:40001,otherhost:40001/mydb
# db.url=mongodb://root:root123@localhost:27017/leanote
# db.urlEnv=${MONGODB_URL} # set url from env. eg. mongodb://root:root123@localhost:27017/leanote
# You Must Change It !! About Security!!
app.secret=V85kbQ8qqtju9y2aDM55VWxAH9Qop19kcDVvrD0y
#--------------------------------
# revel config
# for dev
#--------------------------------
app.name=leanote
http.addr=
http.ssl=false
cookie.httponly=false
cookie.prefix=LEANOTE
cookie.domain= # for share cookie with sub-domain
cookie.secure=false
format.date=2006-01-02
format.datetime=2006-01-02 15:04:05 # 必須這樣配置
results.chunked=false
log.trace.prefix = "TRACE "
log.info.prefix = "INFO "
log.warn.prefix = "WARN "
log.error.prefix = "ERROR "
# The default language of this application.
i18n.default_language=en-us
module.static=github.com/revel/modules/static
[dev]
mode.dev=true
results.pretty=true
watch=true
module.testrunner = # github.com/revel/modules/testrunner
log.trace.output = stderr
log.info.output = stderr
log.warn.output = stderr
log.error.output = stderr
[prod]
mode.dev=false
results.pretty=false
watch=false
module.testrunner =
log.trace.output = off
log.info.output = off
log.warn.output = %(app.name)s.log
log.error.output = %(app.name)s.log
我們需要修改的部分有:http.port
,site.url
,app.secret
,其他暫時不需要修改。
需要注意的是site.url
,這個是你正文中加在圖片等附件前邊的url部分,如果和你訪問網站的url不同,就不能在網站中看到圖片等附件。切切!
設置 leanote 的啟動服務
我們把 mongodb.service
復制一下,修改為啟動 leanote
sudo cp /etc/systemd/system/multi-user.target.wants/mongodb.service /etc/systemd/system/multi-user.target.wants/leanote.service
[Unit]
Description=Leanote, Not Just A Notepad!
[Service]
User=osmc
ExecStart=/media/sea2t/srv/leanote/bin/run.sh
[Install]
WantedBy=multi-user.target
運行命令使配置生效
sudo systemctl daemon-reload
初始化數據庫
運行這個命令初始化數據庫(請確認數據庫已啟動)
mongorestore -h localhost -d leanote --directoryperdb /media/sea2t/srv/leanote/mongodb_backup/leanote_install_data/
啟動 leanote
# 啟動 leanote
sudo service leanote start
# 停止 leanote
sudo service leanote stop
# 查看狀態
sudo service leanote status
備份
一個是數據庫文件,備份這個目錄
/media/sea2t/srv/db
一個是內容圖片附件,備份這個目錄
/media/sea2t/srv/leanote/files
一個是leanote配置文件
/media/sea2t/srv/leanote/conf/app.conf
存在的問題
由於 /media/sea2t
是通過usb接口連接到系統,系統啟動后自動掛載的,所以mongodb
和leanote
啟動時/media/sea2t
還沒掛載上,兩個服務會啟動失敗,需要手動啟動一下。
解決辦法:寫啟動腳本,啟動前先等待移動硬盤掛載。
/home/osmc/start_mongodb.sh
#!/bin/bash
while [ ! -f "/media/sea2t/srv/db/local.0" ]; do
echo "=> Waiting for sea2t to be mounted"
sleep 5
done
/usr/bin/mongod --config /etc/mongodb.conf
/home/osmc/start_leanote.sh
#!/bin/bash
while [ ! -f "/media/sea2t/srv/leanote/bin/run.sh" ]; do
echo "=> Waiting for sea2t to be mounted"
sleep 5
done
/media/sea2t/srv/leanote/bin/run.sh
/etc/systemd/system/multi-user.target.wants/mongodb.service
[Unit]
Description=An object/document-oriented database
Documentation=man:mongod(1)
[Service]
User=osmc
ExecStart=/home/osmc/start_mongodb.sh
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target
/etc/systemd/system/multi-user.target.wants/leanote.service
[Unit]
Description=Leanote, Not Just A Notepad!
[Service]
User=osmc
ExecStart=/home/osmc/start_leanote.sh
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target