解决我这个Piggydb访问很慢的问题

经过腾讯云在线检测,说是出外网流量过大,有很大风险。之前通过iftop检测过,但是它只能实时显示当前流量情况,而且又没写日志,虽然确实检测到有大流量出现过,但是等我再次查看时,已经不知道是哪个程序导致的了。
所以,我尝试验证Piggydb访问过慢是否由系统资源紧张导致,经过多方搜索,过程如下记录:
 查看内存占用前五的进程
 ps auxw | head -1;ps auxw|sort -rn -k4|head -5
很巧,我觉得应该一下子就找到了原因,是由于Halo服务器占用cpu和mem过大导致的。估计大流量也是由它引起的。因此,备份了Halo博客数据后,准备丢弃它。做了一下实验,stop掉halo服务后,Piggydb瞬间响应了能够。坚定了我丢弃halo的决心。
 如何列出正在运行的服务
 systemctl list-unit-files | grep enabled
 其实准确点应该用grep running
在打印出的service列表里,我看到了Halo,接下来就要干掉它。不过我已经不记得这个service文件放在哪儿了,于是:
 systemctl cat halo
输出的第一行就看到了文件地址,于是继续:
 如何删除系统服务
 sudo systemctl stop halo
 sudo systemctl disable halo
 sudo rm /etc/systemd/system/halo.service
 sudo systemctl daemon-reload
 sudo systemctl reset-failed

腾讯云主机piggydb的架设

建立zbjxb.service服务(using systemd)
 sudo cd /lib/systemd/system/
 sudo touch zbjxb.service
 sudo vim zbjxb.service
 sudo chmod 644 zbjxb.service
 sudo systemctl start zbjxb
 sudo systemctl enable zbjxb
 journalctl -u zbjxb
zbjxb.service服务中启动piggydb的run脚本
 [Unit]
 Description=zbjxb.cn http server
 [Service]
 ExecStart=/bin/sh /home/ubuntu/download/piggydb/run.sh
 [Install]
 WantedBy=multi-user.target
run.sh脚本
 #!/bin/bash
 MY_FOLDER=/home/ubuntu/download/piggydb
 #java -Dpiggydb.database.prefix=file:~/piggydb -Dpiggydb.database.name=piggydb -Dpiggydb.enableAnonymous=false -jar winstone.jar --warfile=piggydb-7.0.war $1 $2 $3 $4 $5
 java -Dpiggydb.database.prefix=file:~/piggydb -Dpiggydb.database.name=piggydb -Dpiggydb.enableAnonymous=true -jar ${MY_FOLDER}/winstone.jar --warfile=${MY_FOLDER}/piggydb-7.0.war $1 $2 $3 $4 $5
java -jar winstone.jar --warfile=piggydb.war \ --httpsListenAddress=0.0.0.0 --httpsPort=443 \ --httpPort=-1 --ajp13Port=-1 \ --httpsKeyStore=your_keystore_name.jks --httpsKeyStorePassword=your_keystore_password
根据上面这段github上的issue 27,可以尝试在java命令行加参数--httpPort=80
重启服务:

服务相关

列出服务
 systemctl list-units --type=service | grep zbjxb
或者
 systemctl list-unit-files | grep xxx
重启服务
 systemctl restart zbjxb
 service zbjxb restart
移除服务
 systemctl revert zbjxb