Etherpad-lite in Ubuntu 14.04 x64 server

etherpad

  1. 安裝基本套件需求
sudo apt-get install gzip git-core curl python libssl-dev pkg-config build-essential
  1. 更新安裝nodejs的來源
sudo curl -sL https://deb.nodesource.com/setup | sudo bash -
  1. 安裝nodejs
sudo apt-get install nodejs
  1. 新增etherpad的使用者
sudo useradd etherpad -m -s /bin/bash -r
sudo passwd etherpad
  1. 將etherpad使用者加入sudoers中
sudo usermod -a -G sudo etherpad
  1. 切換到etherpad使用者
su - etherpad
  1. 下載etherpad檔案
wget https://github.com/ether/etherpad-lite/zipball/master
  1. 安裝unzip
sudo apt-get install unzip
  1. 解壓縮etherpad壓縮檔
unzip master
  1. 將目錄名稱變好看一點
mv ether-etherpad-lite-3ebcaad etherpad-lite
  1. 切換到etherpad-lite目錄
cd etherpad-lite
  1. 複製設定檔範本
cp settings.json.template setting.json
  1. 設定etherpad基本環境
vim setting.json
# 找到以下的設定加以替換
   "requireSession" : false,
   "sessionNoPassword" : false,
   "requireAuthentication": false,
   "requireAuthorization": true,
   "users": {
      "admin": {
         "password": "password",
         "is_admin": true
      },
      "user": {
         "password": "password",
         "is_admin": false
      }
   },
  1. 試執行,可看 http://ip:9001 是否正常
./bin/run.sh
  1. 安裝mysql、nginx
sudo apt-get install mysql-server nginx
  1. 建立etherpad資料庫、設定使用者權限
mysql -uroot -p
> create database etherpad;
> grant all privileges on etherpad.* to 'etherpad'@'localhost' identified by 'password';
> exit
  1. 設定etherpad資料存放使用mysql
vim setting.json
   # 註解使用dirty的部分
   //"dbType" : "dirty",
   //"dbSettings" : {
   //                 "filename" : "var/dirty.db"
   //               },
   # 加入使用mysql的部分
   "dbType" : "mysql",
   "dbSettings" : {
                    "user"    : "etherpad",
                    "host"    : "localhost",
                    "password": "password",
                    "database": "etherpad"
                  },
  1. 試執行,並請連至 http://ip:9001 增加幾筆資料
./bin/run.sh
  1. 調整資料表屬性
mysql -uroot -p
> use etherpad;
> ALTER TABLE `store` CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
> ALTER DATABASE `etherpad` CHARACTER SET utf8 COLLATE utf8_bin;
  1. 設定nginx proxy
sudo vim /etc/nginx/sites-enabled/default
# 全部內容不用留,以下面替換
server {
    listen       80;
    access_log   /var/log/nginx/etherpad.log;
    error_log    /var/log/nginx/etherpad.log;
    location / {
        proxy_pass        http://localhost:9001/;
        proxy_set_header  Host $host;
        proxy_buffering   off;
    }
}
  1. 設定etherpad信任proxy
vim setting.json
   # 找到以下的設定加以替換
   "trustProxy": true,
  1. 創建etherpad使用之log目錄
sudo mkdir /var/log/etherpad-lite
  1. 調整權限
sudo chown -R etherpad:etherpad /var/log/etherpad-lite
  1. 建立etherpad系統服務設定
sudo vim /etc/init/etherpad.conf
# 加入以下內容
description "etherpad"

start on started networking
stop on runlevel [!2345]

env EPHOME=/home/etherpad/etherpad-lite
env EPLOGS=/var/log/etherpad-lite
env EPUSER=etherpad

respawn

pre-start script
    cd $EPHOME
    mkdir $EPLOGS                              ||true
    chown $EPUSER:admin $EPLOGS                ||true
    chmod 0755 $EPLOGS                         ||true
    chown -R $EPUSER:admin $EPHOME/var         ||true
    $EPHOME/bin/installDeps.sh >> $EPLOGS/error.log || { stop; exit 1; }
end script

script
  cd $EPHOME/
  exec su -s /bin/sh -c 'exec "$0" "$@"' $EPUSER -- node node_modules/ep_etherpad-lite/node/server.js 
                        >> $EPLOGS/access.log 
                        2>> $EPLOGS/error.log
end script
  1. 以系統服務啟動etherpad
sudo start etherpad
  1. 重新讀取nginx設定
sudo service nginx reload
  1. 修改npm權限,避免/admin中無法安裝plugin
cd ~/etherpad-lite
sudo npm install -g express
chown -R etherpad ~/.npm
  1. 創建使用者管理用之資料表
mysql -uroot -p
> use etherpad;
> CREATE TABLE IF NOT EXISTS GroupPads ( GroupID int(11) NOT NULL, PadName varchar(255) COLLATE utf8_bin NOT NULL, PRIMARY KEY (GroupID, PadName) );
> CREATE TABLE IF NOT EXISTS User ( userID int(11) NOT NULL AUTO_INCREMENT, name varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', pwd varchar(255) COLLATE utf8_bin DEFAULT NULL, considered tinyint(11) DEFAULT NULL, SSO tinyint(4) DEFAULT NULL, FullName varchar(255) COLLATE utf8_bin DEFAULT NULL, considerationString varchar(50) COLLATE utf8_bin DEFAULT NULL, salt varchar(255) COLLATE utf8_bin DEFAULT NULL, active int(1) DEFAULT NULL, PRIMARY KEY (userID,name) );
> CREATE TABLE IF NOT EXISTS NotRegisteredUsersGroups (  email varchar(255) NOT NULL,  groupID int(11) NOT NULL  );
> CREATE TABLE IF NOT EXISTS UserGroup ( userID int(11) NOT NULL DEFAULT 0, groupID int(11) NOT NULL DEFAULT 0, Role int(11) DEFAULT NULL, PRIMARY KEY (userID,groupID) );
> CREATE TABLE IF NOT EXISTS Groups (  groupID int(11) NOT NULL AUTO_INCREMENT,  name varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',  PRIMARY KEY (groupID, name )  );
> exit
  1. 安裝使用者管理套件
cd ~/etherpad-lite
npm install ep_user_pad
  1. 安裝使用者管理前端介面
cd ~/etherpad-lite
npm install ep_user_pad_frontend
  1. 修正email function,這邊改用gmail為例
sudo vim node_modules/ep_user_pad/email.json
    # 找到以下的設定加以替換
    "smtp": "true",
    "user": "cowman.chiang@gmail.com",
    "password": "password",
    "host": "smtp.gmail.com",
    "port": "465",
    "tls": "true",
    "ssl": "true",
  1. 修正email function,這邊改用gmail為例
sudo vim node_modules/ep_user_pad_frontend/email.json
    # 找到以下的設定加以替換
    "smtp": "true",
    "user": "cowman.chiang@gmail.com",
    "password": "password",
    "host": "smtp.gmail.com",
    "port": "465",
    "tls": "true",
    "ssl": "true",
  1. 修正hooks.js,不然會發生錯誤
sudo vim node_modules/ep_user_pad/hooks.js
# 註解下面這一行
//settings.encryptPassword = function (password, salt, cb) {
# 以下面這一行取代
var encryptPassword = function (password, salt, cb) {
  1. 安裝顯示作者名稱的功能
    cd ~/etherpad-lite
    npm install ep_authornames

  2. 建議安裝套件
    (1) adminpads : 在/admin中可以管理所有的筆記
    (2) authornames: 可以在筆記內容中顯示編輯的作者名稱
    (3) colors : 增加筆記的顏色功能
    (4) draw : 提供畫圖的功能
    (5) headings : 提供使用標題字型的功能
    (6) historicalsearch : 提供在筆記編輯歷史中搜尋的功能
    (7) padlist : 以/list顯示所有的筆記
    (8) user_pad : 提供使用者、群組及權限的管理方式
    (9) user_pad_forntend : user_pad的使用者介面

  3. 修正圖檔路徑問題

vim node_modules/ep_user_pad_frontend/templates/group.ejs 
vim node_modules/ep_user_pad_frontend/templates/public_pad.ejs
vim node_modules/ep_user_pad_frontend/templates/public_pad_logged_in.ejs
vim node_modules/ep_user_pad_frontend/templates/pad.ejs 
# 上述兩個檔案是修正下面這部分
img src="./static/plugins/ep_user_pad_frontend/static/images/pad-illustration-01.png" alt="Etherpad" 
# 修正為
img src="../static/plugins/ep_user_pad_frontend/static/images/pad-illustration-01.png" alt="Etherpad" 

pre lang=”bash”>vim node_modules/ep_user_pad_frontend/static/css/styles.less

上述這個檔案是修正下面這部分

.at2x(‘images/close-cyan-12.png’);

修正為

.at2x(‘../images/close-cyan-12.png’);

下面這句

list-style-image: url(images/users-cyan-16.png);

修正為

list-style-image: url(../images/users-cyan-16.png

  1. 設定 Log rotation
sudo vim /etc/logrotate.d/etherpad-lite
# 加入以下內容
/var/log/etherpad-lite/*.log
{
        rotate 4
        weekly
        missingok
        notifempty
        compress
        delaycompress
        sharedscripts
        postrotate
                restart etherpad-lite >/dev/null 2>&1 || true
        endscript
}
  1. 加入開機啟動
sudo vim /etc/rc.local
# 加入下面
/sbin/start etherpad start
This entry was posted in etherpad, MySQL, Nagios, Ubuntu. Bookmark the permalink.