博客搬家 Hexo

说来也巧,上一篇博客刚好写在3年前,也是一篇替换的。

博客没写几篇,虚拟空间却已经被垃圾日志塞满,续费通知又来了,想想还是换个地方吧。

博客系统选择

WordPress 是不想继续用了,这么多年又出来好多博客框架可以玩一玩了。目标是支持 Markdown,导入 WP 历史文章。

首先尝试的 Ghost,商业化了,各种支持肯定更好。搭完了发现不太稳定,还以为是我的VPS太弱鸡(其实不是),就放弃了。

又尝试了 Hexo, 各种简洁,非常喜欢。当然遇到的问题还是不少,一路披荆斩棘,或者绕路,总算定型了。

稳定性问题

一番观察+思索后,锁定了博客不稳定的原因是 tls-shunt-proxy。作为 trojan 前的分流器,它承担了超出它能力范围的工作。打开一个页面,起码10个SSL请求,它忙不过来了。解决方法就是让它退居二线,让Nginx顶上去。

nginx 通过 ssl_preread_server_name 区别不同域名的流量,转发到不同的端口。科学上网专用域名的流量转给 tls-shunt-proxy (其实可以省了), hexo 静态文件一个端口,其他转发服务再一个端口。

1
2
3
4
5
6
7
8
9
nginx
├── hexo
├── other (redirect)
│ ├── nas
│ ├── gitea
│ └── webcam
└── tls-shutn-proxy
├── static fake site
└── trojan

SSL证书

为了实现上面的SNI转发,SSL是少不了的,可是那么多域名一个一个搞太麻烦,直接搞个泛域名证书。

1
acme.sh --issue -d zrenx.com -d *.zrenx.com --dns dns_cf 

HTTP 跳 HTTPS

找到两种跳转方式:

1
2
3
4
5
server {
...
#rewrite ^(.*) https://$server_name$1 permanent;
return 301 https://$host$request_uri;
}

导入文章

导入文章很简单,用 hexo-migrator-wordpress

导入评论

Valine比较简单,设置却走了很多弯路。

  • Valine.min.js CDN要换一个
  • LeanCloud 要设置安全域名
  • Valine 配置 serverUrls,要用 LeanCloud 绑定的域名,不然CORS错误

导入历史数据也挺麻烦,自己写了个脚本从Wordpress导出的xml里提取了,写成一个json文件,LeanCloud 结构化数据就能导入了。

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
import fs from "fs";
import { XMLParser } from "fast-xml-parser";

import { dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));

const comments = [];

function parseComment(wpc, postUrl) {
const time = new Date(wpc["wp:comment_date"]);
return {
nick: wpc["wp:comment_author"],
mail: wpc["wp:comment_author_email"],
link: wpc["wp:comment_author_url"],
ip: wpc["wp:comment_author_IP"],
insertedAt: {
"__type": "Date",
"iso": time
},
updatedAt: time,
createdAt: time,
comment: wpc["wp:comment_content"],
url: postUrl,
};
}

const xmlparse = new XMLParser();

const xmldata = fs
.readFileSync(__dirname + "/WordPress.2023-10-23.xml")
.toString();
const data = xmlparse.parse(xmldata);
//console.log("posts", data.rss.channel.item);
data.rss.channel.item.forEach((post) => {
const postUrl = post.link.substring(16);
const wpcs = post["wp:comment"];
if (wpcs ) {
if (wpcs instanceof Array) {
wpcs.forEach(wpc => {
comments.push(parseComment(wpc, postUrl))
});
} else {
comments.push(parseComment(wpcs, postUrl))
}

}
});

console.log("comments", comments);
fs.writeFileSync("comments.json", JSON.stringify(comments), 'utf8');

写作

Hexo 怎么写博客呢,试了几个后台管理插件,都不理想。
SSH 我熟,Markdown 容易写,结合起来却不怎么方便了。
最终想到我天天在用的VS Code,两个插件搞定了。Remote - SSH直接管理远程文件,Hexo Utils方便写博客。

Replace systemd with sysvinit (替换systemd为sysvinit)

It’s been a year after last rebuild of my LS-WXL. I’ve saw a lot of OOM termination of transmission, LS-WXL is sooo~~ limit in memory. Checking the memery usage, it’s “systemd-journald” is competing with transmission. I’ve tried limit the memory usage of systemd-journald, and then stop logging, none have worked. Since all those trouble are caused by systemd related stuff, my last option is to replace systemd with sysvinit. Luckily, there’s a group of smart guys have the same thoughts. Following the guide below, I’ve successfully remove systemd and systemd-journald of course. https://www.devuan.org/os/documentation/dev1fanboy/en/buster-to-beowulf

LS-WXL Debian rebuild

After 4 years of hard working, both hard drives in my LS-WXL have bad sectors. A replacement of hard drives is necessary, as the price of both SSD and large HDD are very good at the moment, I decided to install the system on a HIKVISION C160 256G SSD, while using a HGST 3TB HHD as storage. Here’s how I overcome the issues and finally did it. Prepare As described in: https://github.com/rogers0/OpenLinkstation Download files from https://d-i.debian.org/daily-images/armel/daily/kirkwood/network-console/buffalo/ However, this url might show “Not Found” as the daily build might fail, you have to check another day, say https://d-i.debian.org/daily-images/armel/20191028-01:09/kirkwood/network-console/buffalo/ls-wxl/ Files are downloaded and put in the first partition of the SSD. SSD partition is done as:

/boot 200MB ext3 / 255GB ext4 /swap 800MB

Install Power up the machine and login with ssh:

ssh installer@192.168.1.100

Follow the instructions and reach the point when partition guide is done, there I met the first issue: OOM. Solution is to turn on SWAP. SSH with another terminal window and select “installer shell”, then

mkswap /dev/sda3 swapon /dev/sda3

Login again and redo the process, the installation is completed without further issues. Post install After installation, a few packages are installed to meet my need, however there’s a lot error messages showing up:

Failed to reload daemon: Refusing to reload, not enough space available on /run/ systemd. Currently, 11.0M are free, but a safety buffer of 16.0M is enforced.

To resolve this, I need to increase the run partition size, edit the initramfs.conf:

vim /etc/initramfs-tools/initramfs.conf

Find the line says: “RUNSIZE=10%” and change it to “RUNSIZE=15%” Regenerate the initramfs

dpkg-reconfigure linux-image-4.19.0-6-marvell

-— UPDATE —- Fan control Set signal 0/85/170/255 to pwm1

cat 85 > /sys/devices/platform/gpio_fan/hwmon/hwmon0/pwm1

Check RPM of the fan

cat 85 > /sys/devices/platform/gpio_fan/hwmon/hwmon0/fan1_input

For automatic fan control, install afancontrol and edit /etc/afancontrol/afancontrol.conf accordinglly. https://afancontrol.readthedocs.io/en/latest/

LS-WXL Debian Upgrade

I installed a Debian system on my Buffalo LS-WXL two years ago. Recently, I want to play with some Nodejs, the LS-WXL will be my server, but the Linux kernel on it was too old (2.6.32). So I decided to upgrade it first. Obviously, compile a new kernel was my first thought. However, when I compiled the first one, there was a few patches, which I don’t think I can find new ones for the new kernel version. I searched and searched, came across this thread, it says:

Support for the LS-XHL and LS-CHLv2 was added in the official Debian packets. Just install linux-image-kirkwood and flash-kernel from wheezy-backports and reboot.

Similar devices, this method might works on LS-WXL as well. I tried and failed on “Unsupported platform”. Early, I found this github repo: https://github.com/rogers0/OpenLinkstation It supposed to be able to convert stock Linux system into a Debian system. There are bash scripts I can use as a instruction. The magic begins:

  • Edit /etc/flash-kernel/db
Machine: Buffalo LS-WXL Kernel-Flavors: kirkwood Machine-Id: 527 DTB-Id: kirkwood-lswxl.dtb DTB-Append: yes U-Boot-Kernel-Address: 0x00008000 U-Boot-Initrd-Address: 0x0 Boot-Kernel-Path: /boot/uImage.buffalo Boot-Initrd-Path: /boot/initrd.buffalo Boot-DTB-Path: /boot/dtb Required-Packages: u-boot-tools Bootloader-Sets-Incorrect-Root: yes

I edited a little to match what’s on my machine. Boot-DTB-Path is where a dtb file will be generated

  • Copy kirkwood-lswxl.dtb and kirkwood-lswxl.dts from 1_debootstrap/dtb/ to /etc/flash-kernel/dtb/

  • Run: update-initramfs -uk all

  • Reboot and Good luck!

LS-WXL Debian改造过程

缘由

自从老婆搬过来,并且把我07年的笔记本霸占以后,台式机充当下载机已经一年多了。看着最近的电费单总是一阵阵的不爽,就想着弄个全职下载机。想要自己的VPS也不是一天两天了,AWS的micro instance免费体验也到期了,弄个机器也要能装linux才行。 半个月前买了个Buffalo LS-WXL,原因有很多

  • 便宜  —— 不到600,看中Synology的也有段时间了,可惜就是贵了点
  • 不带硬盘 —— WD My Book Live, 不错,可惜找不到不带硬盘的,刚买的2T硬盘不想浪费了
  • 可以改Debian —— Linux党的最爱,折腾不是问题
  • 有两个硬盘位 —— 不想格式化2T硬盘,里面积攒的电影要挪出来也没地方暂放了。还有两个多余的笔记本硬盘。

要折腾必先获取root权限,有了root就可以通过optware玩些初级的东西了。

获取Root权限

完整方法

参考:http://buffalo.nas-central.org/wiki/Category:LS-WXL#Gain_Root_Access 买过来直接就是1.60的固件了,直接跳到 #Firmware_1.41_and_later 开始就行。

偷懒方法

下载别人提供的已经破解好的固件,http://forum.buffalo.nas-central.org/viewtopic.php?f=68&t=23603 有了root权限也不是就能为所欲为了,Buffalo在固件里面直接定死了 —— 要么RAID0,要么RAID1。要让我多余的硬盘发挥余热还是得靠Debian。

改造成Debian

制作rootfs

参考:Debian Squeeze on ‘V’ and ‘X’ Series (LS-WXL and others)

装Debian系统

  • 一开始参照前面的教程复制文件到/boot,启动后只能是闪蓝灯的无限循环; 用LSupdaterg刷,同样结果。
  • 后来找到了这个帖子,有外国网友已经制作好了一个完整的刷机包,第一次就刷成了,很兴奋,可是为什么就不能装软件?(一定是我打开方式不对,XD)  这个方法后来辗转又回来试过,不过不知道为什么就不行了。
  • 又找到个国内网友的帖子,他的方法只要直接解压rootfs就行了。可惜他的包放在115,而115关了大众分享。

想了想,hddrootfs.buffalo.buffalo本来就是系统根文件夹的压缩包,国内网友的帖子很靠谱。找出前面的自己做的 hddrootfs.buffalo.updated 准备就这么干了。 拔出硬盘,装到移动硬盘盒里,插上电脑,重建gpt分区表,手动分区。 sdd1 1G  /boot ext3 sdd2 5G  /         ext3 sdd3 1G  swap sdd4 剩下的100多G xfs /mnt/disk1 找出前面收集到的2.7M的 uImage.buffalo、 1.5K的空白 initrd.buffalo,放入sdd1。把hddrootfs.buffalo.updated放入sdd2,解压,针对当前分区修改 /etc/fstab。 把硬盘重新插入LS-WXL,召唤神龙 启动。过一会儿后,ssh能连入就是成功了。 继续参考前面制作rootfs的文章下文,安装blstools(修复LED灯状态,控制风扇速度),打开开机日志,安装xfs文件系统工具,设置时区,开启debian安全更新源。 Debian系统总算是可以用了,关机插上第二块硬盘,再开机,发现不能mount ext4分区。Buffalo官方uImage.buffalo内核不支持ext4文件系统。

编译内核

参考:Building the Debian kernel 编译之前修改.config,在File systems下加入

CONFIG_EXT4_FS=y
CONFIG_EXT4_FS_XATTR=y
CONFIG_EXT4_FS_POSIX_ACL=y
CONFIG_EXT4_FS_SECURITY=y

内核编译安装完成,重启后就能加载ext4分区了。 直接使用http://pastebin.com/9yWQBnhW的脚本会有一堆如下的错误信息:

cat: /sys/class/gpio/gpio42/value: No such file or directory

原因是以上脚本有误,导致无法创建GPIO signals。脚本中的字符串比较要用“=”而不是“==”, 默认的dash不支持“==”。

gpio_config()
{
if [ $1 = “enable” ]; then
[ -d /sys/class/gpio/gpio$2 ] echo $2 > /sys/class/gpio/export
if [ $3 = “output” ]; then
echo out > /sys/class/gpio/gpio$2/direction
else
echo in > /sys/class/gpio/gpio$2/direction
fi
else
echo $2 > /sys/class/gpio/unexport
fi
}

Linux Chrome Flash 音乐破音

最近发现新的Chrome听 xiami.com 的音乐会有破音,豆瓣电台也一样。 这对遇喜欢写代码时塞着耳塞的我来说,相当难受。 想到Chrome是直接包含了Flash插件的,一看它的安装目录里面有个 libgcflashplayer.so 文件,跟正常的官方的Flash插件的不同。 于是就直接换用Adobe官方的 libflashplayer.so 第一步:

sudo cp /usr/lib/flashplugin-nonfree/libflashplayer.so /opt/google/chrome/

PS:请先确认你已经安装了flashplugin-nonfree 第二步: 在Chrome中打开 about:plugins -> 点开右上角的 Details. 看到 Shockwave Flash 下有两个文件,禁用其中的 libgcflashplayer.so ,Done! PS:libgcflashplayer.so 和 libflashplayer.so 两个文件的大小完全一样,md5sum 不同,不知道是出了什么差错。

Debian上真机开发OPhone应用

前面一篇文章介绍过Nexus One在Debian系统上无法被ADB识别的解决办法,这两天在弄移动的OMS平台,发现需要使用同样的办法解决同样的问题。Debian 调试 Nexus One 的设置 OPhone1.5 插上 USB会有5个选项,选中”adb”就可以了。 OPhone2.0 插上 USB只有4个,选”同步“。 lsusb 找到手机对应的制造商和设备的ID,在/etc/udev/rules.d/51-android.rules上照样写一行就好了。

Debian 调试 Nexus One 的设置

问题:无法在Nexus One上调试,adb无法识别设备。

richard@r:~$ adb devices
List of devices attached
????????????no permissions

原因:USB 设备ID无法被系统识别。(参考) 解决方法: 创建或修改文件(参考)

sudo vim /etc/udev/rules.d/51-android.rules

添加一行

SUBSYSTEMS==”usb”, SYSFS{idVendor}==”18d1”, SYSFS{idProduct}==”4e12”,
MODE=”0666”, OWNER=”YOUR_USERNAME”

改权限

chmod a+r /etc/udev/rules.d/51-android.rules

重新载入USB设备

sudo service udev reload

看效果

richard@r:~$ adb devices
List of devices attached
HT9CXP811756device