I found someone submit a pull-request to redis, which modify the init.d script. The modification make me curious about the init script. So this is the research result.
LSB stand for Linux Standard Base.
LSB-compliant init scripts need to:
[optionally] Log messages using the Init.d functions: log_success_msg, log_failure_msg and log_warning_msg
#!/bin/sh ### BEGIN INIT INFO # Provides: scriptname # Required-Start: $all # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start daemon at boot time # Description: Enable service provided by daemon. ### END INIT INFO
解释:
2 3 4 5
0 1 6
几个虚设项目,以 $
开头
$local_fs
本地文件系统被挂载,用到 /var
目录的启动项都需要依赖此$network
网络被启用$named
名称功能被启用$remote_fs
所有文件系统被挂载,包含 /usr
$syslog
系统记录功能启用$time
系统时间被设定$all
所有项目一般的 daemon 应该依赖 $remote_fs
和 $syslog
,核心模块驱动程序等,需要依赖 $local_fs
在 /etc/init.d
目录下有一个 skeleton
文件,可以以此作为文件的基础来进行编辑。
一个脚本需要提供 start, stop, restart, force-reload, status 这几个动作。
最近整理文档,想起来自己的腾讯云,和 Google 云,好几十 G 的对象存储都空着,虽然腾讯云填了一部分同步的书籍,但是还是没有好好利用起来,然后就突然想起来之前看到过有人自己写了一份网盘同步程序,将对象存储作为同步工具来使用,这么一想确实可以尝试一下,毕竟现在 Dropbox 容量渐渐不够用了,如果能作为一份扩充也倒是不错的选择。所以这里就整理一下目前可用的一些方案,然后再做一下决择。
这是一款 PHP 所写的云盘系统,支持多家对象存储,设计采用 Material Design ,看起来也不错。
[[ZFile]] 是一款 Java 编写的在线文档分享工具。
[[lsky-pro]] 是一款用 PHP 框架 [[laravel]] 编写的图片管理系统。
基于 Python 的 OneDrive 网盘目录列表
[[oneindex]] 是一款用来展示 One Drive 列表的项目,PHP 编写。
基于 Python 的 onedrive 文件本地化浏览系统,使用 [[MongoDB]] 缓存文件
用 Go 实现了一套对象存储的服务端,兼容 AWS S3。
一款在线相册
在调查的过程中,还发现了日本的一个云存储服务,TeraCLOUD,提供 10G 空间,还支持 WebDAV ,果断注册一个。如果你也想注册可以注册完之后,用我的 CODE :NDMSQ
支持 [[WebDAV]] ,那么我就可以直接在我的 nemo 文件管理器 中 connect 到这个服务,在 File -> Connect to Server 中选择 Secure WebDAV(HTTPS),然后输入 TeraCLOUD 提供的 WebDAV 地址,以及用户名和密码来登录该服务,既不用多安装一个客户端,也可以非常方便的映射到本地文件管理器中。简单的测试了一下,发现上传速度,在我这里竟然达到了惊人的 800 kB/s
其他桌面版,或者移动客户端,只要支持 WebDAV 协议,那么都可以非常方便的使用该服务。官方也提供了一系列的选择方案。
This post is under the environment of Ubuntu 18.04, this instruction will guide how to install shadowsocks libev both server side and client settings manually. And show the step to configure the simple-obfs.
The source code is in following two repositories:
You can manually build and install yourself. But under Ubuntu 18.04, you can just install like this:
sudo apt install shadowsocks-libev simple-obfs
and the configuration is under /etc/shadowsocks-libev/
. You can manullay modify it and make it work.
If your system is before Ubuntu 18.04, you have to build it from source.
Install shadowsocks-libev via Ubuntu PPA
sudo apt-get install software-properties-common -y
sudo add-apt-repository ppa:max-c-lv/shadowsocks-libev -y
sudo apt-get update
sudo apt install shadowsocks-libev
Install simple-obfs
sudo apt-get install --no-install-recommends build-essential autoconf libtool libssl-dev libpcre3-dev libev-dev asciidoc xmlto automake
git clone https://github.com/shadowsocks/simple-obfs.git
cd simple-obfs
git submodule update --init --recursive
./autogen.sh
./configure && make
sudo make install
Make ~obfs-server~ able to listen on port 443
setcap cap_net_bind_service+ep /usr/local/bin/obfs-server
Server configuration
Add below to ~/etc/shadowsocks-libev/config.json~
{
"server":"0.0.0.0",
"server_port":443,
"local_port":1080,
"password":"password",
"timeout":300,
"method":"chacha20-ietf-poly1305",
"plugin":"obfs-server",
"plugin_opts": "obfs=tls;obfs-host=www.douban.com",
}
Start ~shadowsocks-libev~ server
systemctl enable shadowsocks-libev.service
systemctl start shadowsocks-libev.service
systemctl status shadowsocks-libev.service
Optimizations
Install & enable BBR TCP congestion control
apt install --install-recommends linux-generic-hwe-16.04
apt autoremove
modprobe tcp_bbr
echo "tcp_bbr" >> /etc/modules-load.d/modules.conf
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p
MISC
Add below to ~/etc/sysctl.d/local.conf~
fs.file-max = 51200
net.core.rmem_max = 67108864
net.core.wmem_max = 67108864
net.core.netdev_max_backlog = 250000
net.core.somaxconn = 4096
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 10000 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_mem = 25600 51200 102400
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 65536 67108864
net.ipv4.tcp_mtu_probing = 1
Reboot
reboot
Client configuration
Add below to /usr/local/etc/shadowsocks-libev.json
Note that the ~plugin~ has to be absolute path in order to be able to use ~brew services start shadowsocks-libev~.
{
"server":"SERVER",
"server_port":443,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"PASSWORD",
"timeout":300,
"method":"chacha20-ietf-poly1305",
"workers":8,
"plugin":"/usr/local/bin/obfs-local",
"plugin_opts": "obfs=tls;obfs-host=www.bing.com",
"fast_open":true,
"reuse_port":true
}
When you encouter the high cpu load caused by java application, you may follow these steps to troubleshooting.
identify the PID, use top
or htop
then press P
, sorted by CPU
identify the thread using top -n 1 -H -p PID
, this command will give an output listing all the threads in the selected process
like this:
KiB Mem : 16342620 total, 270500 free, 12773428 used, 3298692 buff/cache
KiB Swap: 7812092 total, 2654116 free, 5157976 used. 1999284 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
28958 einverne 20 0 8824828 3.021g 23784 S 30.0 19.4 0:00.00 java
28959 einverne 20 0 8824828 3.021g 23784 S 0.0 19.4 0:00.56 java
28960 einverne 20 0 8824828 3.021g 23784 S 0.0 19.4 0:10.35 GC Thread#0
28961 einverne 20 0 8824828 3.021g 23784 S 0.0 19.4 0:00.06 G1 Main Marker
28962 einverne 20 0 8824828 3.021g 23784 S 0.0 19.4 0:07.24 G1 Conc#0
28963 einverne 20 0 8824828 3.021g 23784 S 0.0 19.4 0:00.42 G1 Refine#0
Here for example, PID 28958 use 30% of CPU.
Then use jstack
to show the stack trace for the PID
jstack PID > jstack.out
Use the above result as example, thread id 28958 is the problem thread. Then convert it to hex value. 28958 -> 711e
Here I provide an easy way to convert decimal to hexadecimal under bash:
printf '%x\n' 28958
# or
echo "obase=16; 28958" | bc
Search the stack trace output for the hex value using the tools you’re familiar with, grep
, less
etc.
less jstack.out
Then you will found the thread details.
vim-abolish 又一款 Tim Pope 大神所制作的插件,这款插件扩展了一条名为 :Subvert
的自定义命令,作用类似于 Vim 内置命令 :substitute
的扩展。
比如说想要将整个文档中的 man 和 dog 两个单词交换,如果用 Vim 原生的替换比较麻烦,而使用该插件则只需要 :%S/{man,dog}/{dog,man}/g
在 GitHub 页面上也有大量的使用方式介绍,这里再提一个官方页面上的用例,比如想要把所有的 facility 替换成 building,那么 facility 有复数, building 也有复数,怎么办
:%S/facilit{y, ies}/building{,s}/g
这个比较好理解,但是 Abolish 还有一个非常贴心的转换,在编程中有驼峰命名,小写字母加下划线命令,假如要将一些变量从小写下划线变成驼峰命名,这个插件提供了一个方法 crc
compute_vm_current_status
将光标移动到该变量名,然后按下 crc
就可以快速将变量命名修改成 camelCase (crc).
同样的
更加详细内容 :help abolish
global 命令结合了 Ex 命令和 Vim 模式匹配的能力,借助该命令,可以在指定模式的所有匹配行上运行 Ex 命令。global 命令是除了点操作和宏命令之外,最强大的 Vim 工具之一。
global 命令基本形式,可以读作在 range 上,如果行匹配 pattern,那么执行全局命令 cmd
:[range] global[!]/{pattern}/[cmd]
说明:
global
还有 :vglobal
表示反转,在没有匹配 pattern 的行上执行 cmd:global
之外的任何 Ex 命令,如果不指定 [cmd], 那么缺省是 :print
比如删除所有空行
:g/^$/d
代码中经常会写一些 TODO , 如果想要统一处理这些 TODO,可以使用
:g/TODO/t$
将 TODO 行拷贝到文件末尾,来处理。
前两天在 Twitter 上看到有人分享新闻说,Oracle 发布了新的云服务政策,提供 Always Free 的主机和对象存储还是数据库,所以就看了一下,搜了一下新闻,还真的有 Oracle Offers Always Free Autonomous Database and Cloud Infrastructure,所以就注册一下。但是当天晚上创建 VM 的时候提示我 “out of host capacity”,Google 了一下才发现,原来这条消息早就在羊毛党炸锅了,不亚于 Google Cloud Platform 当年的新闻。不过我个人作为学习使用,并没有违背 Oracle 的政策。所以我就等着 Oracle 解决 “out of host capacity” 的问题。于是等到周末,突然想起这件事情,就登录账号是了一下,确实可以创建了。
这里再整理一下 Oracle 提供的服务内容,根据它官方的博文,Oracle 提供的服务没有像其他云服务提供商一样提供 12 个月的免费体验,而是对于基础服务,比如 Compute VMs, Database, Block and Object Storage, and Load Balancer, 等等只要在用,不超过限额,那么就在账号有效期内免费使用。
甲骨文的永久免费 VPS,可以永久免费使用 2 台 AMD 服务器,外加 4 台 Arm-based 云服务器,还有数据库,对象存储等等服务。
这里引用 Oracle 官方的文章:
The new program enables developers to build applications using any language and framework on top of Oracle Cloud Infrastructure and Autonomous Database. They can get started quickly without waiting for IT to provision and learn new technologies such as artificial intelligence and machine learning. Enterprises can use Free Tier to prototype, prove out new technologies, and do testing before moving production workloads to the cloud. They can sample robust enterprise infrastructure capabilities like load balancing and storage cloning. Additionally, students can learn how to use the latest technologies and become better prepared for their careers.
Oracle 提供的免费服务包括两个部分:
Free Trial, which provides $300 in credits for 30 days to try additional services and larger shapes 而 Always Free 项目涵盖了开发,测试应用必要的各种服务,包括 Oracle Autonomous Database, Compute VMs, Block Volumes, Object and Archive Storage, and Load Balancer 等等。具体来说:
这里可以看到提供的主机是 1/8 OCPU,什么是 OCPU ? 官方的解释是:OCPU 定义为等同于启用了超线程的 Intel Xeon 处理器一个物理核心的 CPU 容量或者等同于 Orcale SPARC 的一个物理核心。1 对于 Intel Xeon 处理器,每个 OCPU 对应于两个硬件执行线程 ( vCPU )。2
AWS, Microsoft 和 Google 提供的云服务都是以 vCPU 作为计算单元,每一个 vCPU 都表示 Intel Xeon 核心的的一个超线程。一个标准的 Intel 核心如果开启了超线程,有两个线程。
计算实例配置:
Shape: VM.Standard.E2.1.Micro
Processor: 1/8th of an OCPU with the ability to use additional CPU resources
Memory: 1 GB
Networking: Includes one VNIC with one public IP address and up to 480 Mbps network bandwidth
Operating System: Your choice of one of the following Always Free-eligible operating systems:
Oracle Linux
Canonical Ubuntu Linux
CentOS Linux
存储
100 GB total of combined boot volume and block volume Always Free Block Volume storage.
Five total volume backups (boot volume and block volume combined).
免费账户:
20 GiB of combined Object Storage and Archive Storage
50,000 Object Storage API requests per month
付费账户:
10 GiB of Object Storage
10 GiB of Archive Storage
50,000 Object Storage API requests per month
网站登录地址:
韩国区域后台管理地址:
Check this post
ubuntu@instance: $ sudo su - root
root@instance: # passwd # set password of root user
adduser yourname
apt install vim
update-alternatives --config editor # choose vim
visudo # add yourname ALL=(ALL:ALL) NOPASSWD:ALL
vi /etc/ssh/sshd_config # AllowUsers yourname
/etc/init.d/ssh reload
# copy ssh pub to ~/.ssh/authorized_keys
then
ssh -p 22 yourname@ip
另外我个人建议可以登陆后修改一下默认的 SSH 端口。
甲骨文的主机创建之后无法 ping 通,是因为在网络安全组里面禁用了 ICMP ping。
点击子网,在安全列表中,找到入站规则,允许 ICMP (IP 协议选项中)。
实例管理页面,Virtual Cloud Network Details,Security Lists, 在防火墙安全策略里面将需要的端口配上。
另外需要特别注意需要登录机器配置实例上的防火墙。
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -F
甲骨文的 Ubuntu 镜像内置了防火墙规则,即使在面板上开通了端口白名单,重启之后端口依然会被防火墙拦住,所以每次都得手动执行上面的命令。主要原因是 Oracle 自带的 Ubuntu 镜像默认设置了 iptable 规则,可以手动关闭:
sudo apt purge netfilter-persistent
sudo reboot
或者可以直接删除 iptabls 的配置文件
rm -rf /etc/iptables && reboot
sudo systemctl stop rpcbind.socket
sudo systemctl disable rpcbind.socket
卸载 Oracle 后台监控
sudo systemctl stop snap.oracle-cloud-agent.oracle-cloud-agent.service
sudo systemctl disable snap.oracle-cloud-agent.oracle-cloud-agent.service
新开的实例,我一般都会直接修改其 ssh 登录端口,而这台机器白天开了之后设置了 sshd 端口,并且 reload 了 sshd 设置,晚上回到家后发现
connect to host port xxx:xxx No route to host
这个时候我想着要不就是端口没有生效,要不就是防火墙问题,所以通过 Oracle 后台远程登录的方式进入到机器上,先关了防火墙,然后去控制后台配置了端口,然后再连接即可。
今天重新部署一个服务时发现了一个奇怪的错误,之前用很久都没有错,重新部署一个新环境就发生了这样的问题,问题应该就出现在新依赖的包中。
File "/usr/local/lib/python3.6/dist-packages/flask_marshmallow/fields.py", line 15, in <module>
from marshmallow.compat import iteritems
ModuleNotFoundError: No module named 'marshmallow.compat'
所以搜了一圈在原来的老环境中发现依赖的 marshmallow 是 2.15.4 重新安装这个版本之后解决了这个问题。那就可能是 marshmallow 这个包升级到 3.2.0 之后的问题了。
解决办法:
pip install marshmallow==2.15.4
后来查看 marshmallow 的升级说明,和一些 issue 发现 marshmallow 这个包 2.x 和 3.x 没有完全兼容,看来又要改代码了。
前两天收到一份邮件,标题写着 Google Translator Toolkit to be shut down on December 4, 2019
1,感叹又一款良心服务要终结其生命了。虽然不常用 Google 翻译工具包,甚至很长时间这个翻译工具都偷偷的被隐藏在翻译页面的角落里面,但是不得不说这个工具曾经帮助我翻译过不少文档内容,也非常适合学习。Google 翻译工具包提供上传文档自动翻译,术语翻译等等功能,结合 Google Translate 的帮助能非常快速的辅助完成一篇文档的翻译。在自动翻译完成的基础上可以人工的进行修改润色。更甚至可以添加好友一同翻译,将文档分享给他人。至今为止我也只有在 Google 翻译工具包中体验过如此完整的翻译体验。
很多其他的翻译工具大多只能够提供字符串的辅助翻译,比如之前帮别人翻译过 Android 应用内文本,这些工具都非常的简陋,甚至有些术语都不能自动帮忙翻译,还需要一个字一个字的输入。虽然 Google 在邮件中给出了一些 alternative 但我只想说这些工具要么就是限制平台的,要么就看起来不像是一个完整的产品。体验没有一个能比得上 Google Translator Toolkit.
这些网站多多少少我都有用过,目前 crowdin 做的还不错,有机器翻译自动提示,格式化处理的也比较好,快捷键也很合适。
另外开源版本的 Pootle,也有不少人推荐,用 Python + Django 写的。不过还没有尝试。
另一个开源的本地化工具 Weblate
在 sudo add-apt-repository
添加 PPA 时突然遇到 gpg 添加 key 失败,大概知道可能是因为网络问题,但是这个问题在我家里的网络一直存在,非常恼人。
gpg: keyserver receive failed: Server indicated a failure
所以我想从根本上解决这个问题,这个问题的根源可能是因为网络问题导致 gpg key 没有被导入到本地。所以如果能够手动下载 gpg public key 然后手动导入不就可以了?
所以随意打开一个 PPA,比如
在页面中 Technical details about this PPA
下方有 Signing key
点击该链接会跳转到一个签名的 key 列表,在该列表中找到报错内容中的 KEY
W: GPG error: http://ppa.launchpad.net/eosrei/fonts/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ADA83EDC62D7EDF8
复制该链接,然后使用下面的命令:
curl -sL https://keyserver.ubuntu.com/pks/lookup\?op\=get\&search\=0xada83edc62d7edf8 | sudo apt-key add -
等出现 OK 即可。注意这个 URL 中的 key 需要在前面加上 0x
,否则会找不到该 key.