静态网站评论系统 Twikoo 私有化部署
| 字数总计:1.2k|阅读时长:5 分钟 | 阅读量:341
简介
Twikoo 是一个简洁、安全、免费的静态网站评论系统,支持邮件、QQ 提醒、微信提醒,访客在昵称栏输入 QQ 号,会自动补全 QQ 昵称和 QQ 邮箱,免费搭建,简单部署。
私有部署
安装 node
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| if ! type node >/dev/null 2>&1; then echo 'node 已安装' else echo "----------------------------------start yum install node -----------------------------" wget https://cdn.npm.taobao.org/dist/node/latest-v16.x/node-v16.14.0-linux-x64.tar.gz tar -xvf node-v16.14.0-linux-x64.tar.gz mv node-v16.14.0-linux-x64 /usr/local/node
#删除配置文件中原有的环境变量 sed -ie '/NODE_HOME/d' /etc/profile sed -ie '/cnpm/d' /etc/profile
#修改maven的环境变量,直接写入配置文件 echo "export NODE_HOME=/usr/local/node" >>/etc/profile echo "export PATH=\$NODE_HOME/bin:\$PATH" >>/etc/profile
source /etc/profile
npm install -g cnpm -registry=https://registry.npm.taobao.org echo "export PATH=/usr/local/node/lib/node_moudles/cnpm/bin:$PATH" >>/etc/profile source /etc/profile npm config set registry https://registry.npm.taobao.org npm install npm -g source /etc/profile node -v npm -v cnpm -v echo "----------------------------------yum install node success -----------------------------" fi
|
安装 Twikoo server
根据需要配置环境变量
名称 | 描述 | 默认值 |
---|
TWIKOO_DATA | 数据库存储路径 | ./data |
TWIKOO_PORT | 端口号 | 8080 |
TWIKOO_THROTTLE | IP 请求限流,当同一 IP 短时间内请求次数超过阈值将对该 IP 返回错误 | 250 |
启动 Twikoo server: tkserver
访问 http://服务端IP:8080
若能正常访问,服务端地址(包含 http://
和端口号,例如 http://12.34.56.78:8080
)即为您的环境 id
修改 Butterfly 配置
修改_config.butterfly.yml
:
1 2 3 4 5 6 7
|
twikoo: envId: https://twikoo.aqcoder.cn/ region: visitor: false option:
|
envId
:即为上述的子域名
配置 Twikoo
hexo 三连
启动博客
1
| hexo clean && hexo g && hexo s
|
进入任意评论页面,点击齿轮,twikoo 默认第一个用户为管理员,注册密码后进入配置:

配置 https
添加解析
前提要有域名,这里以腾讯云域名解析为例:

申请免费证书
这里以腾讯云域名申请证书为例:
腾讯云申请免费证书
这里绑定的是子域名

验证域名后,等待签发,签发成功后是这样,点击下载:

下载后解压出来有四个文件:

只需要上传 twikoo.aqcoder.cn_bundle.pem
和 twikoo.aqcoder.cn.key
到服务器即可。
Nginx 配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #监听twikoo.aqcoder.cn server { listen 80; server_name twikoo.aqcoder.cn; return 301 https://$server_name$request_uri; }
server { listen 443 ssl; ssl_certificate /etc/ssl/twikoo.aqcoder.cn/twikoo.aqcoder.cn.pem; ssl_certificate_key /etc/ssl/twikoo.aqcoder.cn/twikoo.aqcoder.cn.key; ssl_session_cache shared:SSL:4m; ssl_session_timeout 10m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; server_name twikoo.aqcoder.cn; location /{ proxy_pass http://127.0.0.1:8080/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
|
在本配置中,证书的位置在 /etc/ssl/twikoo.aqcoder.cn
,请根据需要自行修改
访问 twikoo.aqcoder.cn
:

添加自启动脚本
编写启动脚本
为防止服务器重启造成服务中断,可以添加自启动脚本,开机自启:
vim twikoo
将以下内容粘贴,:wq 保存
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #!/bin/sh # chkconfig: 2345 85 15 # description:auto_run
#评论数据存放路径 ROOT_PATH="/www/data/twikoo/" TWIKOO_DATA=$ROOT_PATH"data" #启动端口 TWIKOO_PORT=8080 #限流 TWIKOO_THROTTLE=250
#初始化方法,安装node init() {
#删除twikoo配置文件中原有的环境变量 sed -ie '/TWIKOO_DATA/d' /etc/profile sed -ie '/TWIKOO_PORT/d' /etc/profile sed -ie '/TWIKOO_THROTTLE/d' /etc/profile
#添加twikoo的环境变量,直接写入配置文件 echo "export TWIKOO_DATA=$TWIKOO_DATA" >>/etc/profile echo "export TWIKOO_PORT=$TWIKOO_PORT" >>/etc/profile echo "export TWIKOO_THROTTLE=$TWIKOO_THROTTLE" >>/etc/profile echo "export PATH=\$TWIKOO_DATA:\$PATH" >>/etc/profile echo "export PATH=\$TWIKOO_PORT:\$PATH" >>/etc/profile echo "export PATH=\$TWIKOO_THROTTLE:\$PATH" >>/etc/profile
#判断文件夹是否存在 -d if [[ ! -d "$TWIKOO_DATA" ]]; then mkdir -p $TWIKOO_DATA else echo "文件夹存在" fi source /etc/profile }
#开始方法 start() { echo '运行twikoo' source /etc/profile cd ~ nohup tkserver >> $ROOT_PATH"tkserver.log" 2>&1 & ps -ef | grep twikoo }
#结束方法 stop() { kill -9 `ps -ef|grep tkserver|grep -v grep|grep -v stop|awk '{print $2}'` }
case "$1" in start) init start ;; stop) stop ;; restart) init stop start ;; *) echo "Userage: $0 {start|stop|restart}" exit 1 esac
|
脚本中可以按需修改 ROOT_PATH
,TWIKOO_PORT
,TWIKOO_THROTTLE
设置脚本存放路径
复制刚刚保存的脚本到 /etc/init.d/
添加执行权限
给脚本可执行权限
1
| chmod +x /etc/init.d/twikoo
|
设置开机启动
添加为系统服务
开机自启动
查看
启动
停用
重启