Entware-ng 使用

Entware-ng 是一个适用于嵌入式系统的软件包库,使用 opkg 包管理系统进行管理。之前的路由器刷了 Openwrt 之后直接能用命令行安装相关命令,之后的路由器,NAS 也能安装 Entware-ng 。可以将 Entware-ng 想象成嵌入式设备的一个包管理软件,能方便的用来在嵌入式设备上安装软件,现在在官方的源上已经有超过 2000 个软件包。

相关网址:

Installation

在群晖上安装

更具体的可以参考我之前的文章

在 QNAP 上安装

Usage

和普通 Linux 下的包管理一样,只要输入命令就能够联网下载相关软件。

opkg update
opkg install git

所有软件包列表可以查看 http://pkg.entware.net/binaries/armv7/Packages.html

通过 opkg 安装的软件启动脚本在 /opt/etc/init.d/ 目录

单个启动命令 /opt/etc/init.d/software_name start


2019-05-19 entware-ng , package , linux , openwrt , merlin , 路由器

每天学习一个命令:pidstat 查看进程消耗资源

pidstat 是 sysstat 工具包含的一个命令,主要用于监控 Linux Kernel 管理的进程资源占用情况,包括 CPU,IO,内存,线程等等。

The pidstat command is used for monitoring individual tasks currently being managed by the Linux kernel.

pidstat 首次运行会显示系统自开机起各项统计,之后运行将显示从上一次运行到该次运行的统计信息。

installation

apt-get install sysstat

usage

pidstat [options] [interval] [times]

常用的参数:

  • -u 默认参数,显示各个进程的 CPU 统计信息
  • -r 显示各个进程的内存使用情况
  • -d 显示各个进程的 IO 使用
  • -w 显示各个进程的上下文切换
  • -p PID 指定 PID

比如常见的每一秒查看 IO 统计,统计 10 次

pidstat -d 1 10

Examples

所有进程的 CPU 统计信息

直接运行 pidstat 默认显示所有进程的 CPU 使用信息,等效于 pidstat -u -p ALL

pidstat -u 1 10
pidstat

Result fields:

  • UID
  • PID
  • %usr: 进程在用户空间占用 cpu 的百分比
  • %system: 进程在内核空间占用 CPU 百分比
  • %guest: 进程在虚拟机占用 CPU 百分比
  • %wait: 进程等待运行的百分比
  • %CPU: 进程占用 CPU 百分比
  • CPU: 处理进程的 CPU 编号
  • Command: 进程名

显示内存统计信息

Following command will display PID memory usage 10 times every 2 seconds:

pidstat -r 2 10

Result fields:

  • UID
  • PID
  • Minflt/s : 每秒次缺页错误次数 (minor page faults),虚拟内存地址映射成物理内存地址产生的 page fault 次数
  • Majflt/s : 每秒主缺页错误次数 (major page faults), 虚拟内存地址映射成物理内存地址时,相应 page 在 swap 中
  • VSZ virtual memory usage : 该进程使用的虚拟内存 KB 单位
  • RSS : 该进程使用的物理内存 KB 单位
  • %MEM : 内存使用率
  • Command : 该进程的命令 task name

显示 IO 统计信息

pidstat -d

Result field:

  • UID
  • PID
  • kB_rd/s: 每秒进程从磁盘读取的数据量 KB 单位 read from disk each second KB
  • kB_wr/s: 每秒进程向磁盘写的数据量 KB 单位 write to disk each second KB
  • kB_ccwr/s: 每秒进程向磁盘写入,但是被取消的数据量,This may occur when the task truncates some dirty pagecache.
  • iodelay: Block I/O delay, measured in clock ticks
  • Command: 进程名 task name

T 选项来打印更详细信息

使用 -T [TASK|CHILD|ALL] 来报告打印更详细的信息,默认 pidstat 使用 TASK,表示监控独立的任务信息。

  • TASK 报告独立的进程
  • CHILD 报告进程下所有线程的情况
  • ALL 输出进程及线程统计信息

Specific PID

To show CPU, memory, IO:

pidstat -u -p PID
pidstat -r -p PID
pidstat -d -p PID

比如要查看 PID 为 12002 的进程的 CPU 使用情况,并且要查看所有子线程,每隔 1 秒输出一次,输出 10 次,则可以

pidstat -T ALL -u -p 12002 1 10

reference


2019-05-14 linux , commmand , network , pidstat , iotop , ram , cpu

每天学习一个命令:pidof 查找进程 PID

pidof finds the process id’s(pids) of the names programs.

Usage

pidof [name]

Example

find chrome pid

pidof chrome
pidof -s chrome

Options:

  • -s instructs the program to only return one pid.

Extension

  • pgrep

2019-05-14 pid , netstat , command , linux

Cross-platform Softwares I am using

This post will only list cross-platform softwares I used now. Each software has its own behaviors, and binded with its own shortcut. It takes time to be familiar with it. So I decided to use only cross-platform softwares in daily life in case I have to swith my main System. But it seems fine till now. I am happy with these great softwares.

IntelliJ IDEA

DescriptionIntelliJ IDEA is a Java integrated development environment for developing computer software. It is developed by JetBrains, and is available as an Apache 2 Licensed community edition, and in a proprietary commercial edition. Both can be used for commercial development.

Open Sources Alternatives:

  • Eclipse

Chrome

DescriptionGoogle Chrome is a cross-platform web browser developed by Google. It was first released in 2008 for Microsoft Windows, and was later ported to Linux, macOS, iOS, and Android. The browser is also the main component of Chrome OS, where it serves as the platform for web apps.

Alternatives:

  • vivaldi

SmartGit

SmartGit is a Git GUI client with support for SVN, GitHub, BitBucket pull requests and comments.

WizNote

WizNote for Windows/Mac/Linux is a cross-platform cloud based note-taking client.

GoldenDict

GoldenDict is an open-source dictionary program that gives translations of words and phrases for different languages. It allows the use of several popular dictionary file formats simultaneously and without conversion. The project aims to create a feature-rich dictionary search program.

TeamViewer

[[TeamViewer]] is proprietary software for remote control, desktop sharing, online meetings, web conferencing and file transfer between computers.

pCloud

pCloud is the secure cloud storage, where you can store, share and work on all your files.

Crypt

VeraCrypt is a source-available freeware utility used for on-the-fly encryption. It can create a virtual encrypted disk within a file or encrypt a partition or the entire storage device with pre-boot authentication. VeraCrypt is a fork of the discontinued TrueCrypt project.

TagSpace

TagSpaces is an open-source data manager and file navigator. It helps organize files on local drives by adding tags to files. Users get the same user interface to manage their files on different platforms. TagSpaces is compatible with Windows, Linux, Mac, Android, iPhone, Firefox and Chrome.

Calibre

Calibre is a cross-platform open-source suite of e-book software. Calibre supports organizing existing e-books into virtual libraries, displaying, editing, creating and converting e-books, as well as syncing e-books with a variety of e-readers. Editing books is supported for EPUB and AZW3 formats.

Telegram

Telegram is a cloud-based instant messaging and voice over IP service developed by Telegram Messenger LLP, a privately held company registered in London, United Kingdom, founded by the Russian entrepreneur Pavel Durov and his brother Nikolai.

balenaEtcher

[[balenaEtcher]] is a powerful OS image flasher built with web technologies to ensure flashing an SDCard or USB drive is a pleasant and safe experience.


2019-05-10 applications , apps

使用 Stylus 扩展自定义页面样式

有油猴脚本可以用来修改网页页面,那么相应的也能通过挂载自己的定义的 CSS 来实现对页面的修改。

如果有了这样的概念,那么可以在页面做到,完全修改页面显示的样式,增加背景,移除广告等等事情。

installation

安装扩展

CSS 样式

从该站点寻找可用的样式

InoReader

  • https://userstyles.org/styles/119240/inoreader-countrystyle-flat-ui-remove-ads

reference


2019-05-08 stylus , css , chrome , firefox , extension

Ruby 国内镜像

Update ruby

gem update --system
gem -v
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
gem sources -l

确保只有 gems.ruby-china.com

Bundler

bundle config mirror.https://rubygems.org https://gems.ruby-china.com
bundle install

reference


2019-05-02 ruby , source , bundler , jekyll

威联通折腾篇十五:rtorrent-Pro 使用

QNAP CLUB 中淘到很多不错的应用,rtorrent-Pro 就是一款,现在作者升级了 rtorrent-pro 付费 15 欧元。这又是一款 BT 下载工具,界面非常美观。

rtorrent development for QNAP was started in 2008. Today after 10yrs from its 1st build, we provide you best Torrent app ever. rtorrent is an high performance and extra featured bittorrent client combined with simple and elegant user interface. rtorrent differentiates itself from other implementations by transferring data directly between file pages mapped to memory by the mmap() function and the network stack. On high-bandwidth connections, it claims to be able to seed at 3 times the speed of the official client. We strive to make rtorrent the best torrent client you could ever want!

rtorrent ui

支持的 QNAP 型号

  • armv7l - ARM processors: TS-x28/x31P/x31P2/x41 and more…
  • x86_64 - Intel/AMD64 CPU: TS-x51 and all higher (x53/61/63/70/71/73/77/78/80/82/88…)

如果不确定自己的 QNAP 型号,登录后台运行 uname -m 输出 CPU 架构如果是上面提到的两个就是支持的。

Installation

安装非常简单,下载应用,在后台上传安装即可。安装后默认的用户名是:rtorrent 密码是:admin.

rtorrent pro splash screen

重启,启动,暂停的使用:

/etc/init.d/rtorrent.sh [start|stop|restart]

Things to do

在安装完毕之后,第一件事情就是更改密码。

用新密码登录进去之后进行配置,首先熟悉配置文件的地址。

Config

配置文件地址:

vi /share/CACHEDEV1_DATA/.qpkg/rtorrent/etc/rtorrent.conf

需要注意的是如果之前安装过其他 BT 下载工具,比如 Transmission 之类,可能会造成端口冲突 (DHT 端口),需要手工调整一下端口设置。

rtorrent 用到的端口:

  • 6881 DHT, 可在配置文件修改
  • 42000 连入端口
  • 19000

Change Paths

注意到该路径,rtorrent 相关的内容都安装在了该路径中。安装完毕之后 rtorrent 会在 Download 目录下创建名为 rtorrent 的文件夹,并且创建软链接 /share/Rdownload,rtorrent 下载的内容都会在该目录中。

In stock QNAP applications, a default Download share is used to save downloaded data from the Internet. Download share location is always static and only on the first initiated disk volume. In the default configuration, Rtorrent also uses the Download network share.

可以自定义 Rtorrent 存储的路径,创建共享文件夹名为 Rdownload,指定一块硬盘,当创建共享文件夹时,记得关闭 Rtorrent-Pro,创建成功后再启动。这样 rtorrent-Pro 就会使用新的路径。

Watch 监控目录

Transmission 之前的文章 也提到过监控某个文件夹,一旦有文件新加进去自动下载。

rtorrent 同样可以实现,默认的配置已经有配置,如果想要更加详细的了解,可以参考这里

Schedule 的语法:

# Schedule syntax: id,start,interval,command call cmd every interval seconds

比如:

schedule = watch_directory_1,20,10,"load.start=/downloads/watched/*.torrent"

说明:

用简短的一句话来总结上面的配置含义就是,定义了一个定时器,名叫 watch_directory_1, rTorrent 启动后 20 秒开始,每隔 10 秒执行一次命令,这个命令是从给定的目录中加载 torrent 文件。

  • schedule 的语法用逗号分隔四段,分别是 ID,启动,间隔时间,执行的命令
  • id 可以自行定义
  • start,rTorrent 启动后多久开始执行
  • interval ,间隔多长时间执行,如果是 0 则表示执行一次
  • load.start 表示从给定的目录(该目录必须要存在)加载 torrent 文件,这个地方除了 load.start 还可以用
    • load.start_verbose = file
    • load.verbose = file, verbose 会在终端将任何错误打印出来
    • load.normal

rtorrent 配置说明

# Maximum and minimum number of peers to connect to per torrent.
# throttle.min_peers.normal.set = 40
# throttle.max_peers.normal.set = 100
# 最小允许的 peer
min_peers = 40
# 最大允许 peer
max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
# throttle.min_peers.seed.set = 25
# throttle.max_peers.seed.set = 60
min_peers_seed = 10
max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
# throttle.max_uploads.set = 30
# 最大同时上传数
max_uploads = 10

# Global upload and download rate in KiB. "0" for unlimited.
# throttle.global_up.max_rate.set_kb = 0
# throttle.global_down.max_rate.set_kb = 0
# 最大下载速度
download_rate = 1024
# 最大上传速度
upload_rate = 512

# tracker_numwant = -1
#trackers.numwant.set = -1

# Max mapped memory
# nb does not refer to physical memory
# max_memory_usage = 768M
pieces.memory.max.set = 1024M

# Max number of files to keep open simultaneously
# max_open_files = 65536
#network.max_open_files.set = 1024

# max_open_http = 48
#network.http.max_open.set = 48

# Default directory to save the downloaded torrents.
# directory.default.set = /share/Rdownload/downloads/
# 下载目录
directory = /share/Rdownload/downloads/

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
# session.path.set = /share/Rdownload/session
# 下载历史,包括进度信息,DHT 节点缓存
session = /share/Rdownload/session

# Schedule syntax: id,start,interval,command call cmd every interval seconds,
#                  starting from start.
# An interval of zero calls the task once while a start of zero calls it immediately.
# Start and interval may optionally use a time format dd:hh:mm:ss
# e.g. to start a task every day at 18:00, use 18:00:00,24:00:00.
# Commands: stop_untied =, close_untied =, remove_untied =
# Stop, Close or Remove the torrents that are tied to filenames that have been deleted

# Watch a directory for new torrents, and stop those that have been
# deleted.
# 将 torrent 文件放到该目录自动下载
schedule = watch_directory,10,10,load_start=/share/Rdownload/watch/*.torrent
# 将 torrent 文件移走停止下载
#schedule = untied_directory,10,10,stop_untied=

# Close torrents when diskspace is low.
# 当硬盘空间不足停止所有下载
schedule = low_diskspace,5,60,close_low_diskspace=1000M

# Stop torrents when reaching upload ratio in percent, when also reaching
# total upload in bytes, or when reaching final upload ratio in percent
# Example: stop at ratio 2.0 with at least 200 MB uploaded, or else ratio 20.0
# 在总上传量达到 200M 的情况下上传 / 下载率达到 200%,
# 或者在总上传量不足 200M 情况下上传 / 下载率达到 2000%, 则停止上传
#schedule = ratio,60,60,stop_on_ratio=200,200M,2000
#ratio.enable=
#ratio.min.set=500
#ratio.max.set=2000
#ratio.upload.set=200M
#method.set = group.seeding.ratio.command, d.close=

# Port range to use for listening.
# network.port_range.set = 6890-6999
# bt 监听端口
port_range = 42000-42000

# Start opening ports at a random position within the port range.
# network.port_random.set = no
# 是否随机从上面的端口中选择
port_random = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
# pieces.hash.on_completion.set = yes
check_hash = yes

# Set whether the client should try to connect to UDP trackers.
# use_udp_trackers = yes
trackers.use_udp.set = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Remove a scheduled event
# schedule_remove = "ip_tick"


# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
#
# dht.mode.set = auto
dht = auto

# UDP port to use for DHT.
# DHT 的 UDP 端口
# dht_port = 6881
dht.port.set = 6882

# Enable peer exchange (for torrents not marked private)
#
# protocol.pex.set = yes
protocol.pex.set = yes
#peer_exchange = yes

# network.scgi.open_port = 127.0.0.1:5000
scgi_port = 127.0.0.1:19000
#scgi_local = /var/run/rtorrent-rpc.socket

network.xmlrpc.dialect.set = i8
#xmlrpc_dialect=i8
encoding_list = UTF-8

以上配置文件非全部,如果要应用到真实环境,请拷贝完整的配置,以上只作为演示和注释使用。

Other

BT 下载的工具有很多,qBittorrent,Transmission,rtorrent, uTorrent,等等,非常多,wiki 有一张非常详细的对比图,在不同系统上都有着各自的最佳选择。对占用资源,下载效率的测试还没有来得及验证,等使用一段时间后再来更新吧。

Android Client

记得启用之后可以使用 [[Transdroid]] Android 客户端来管理 rtorrent-pro. 可以从 Google Play Store 下载,或者从官网:

安装之后在设置中添加 Server,名字,服务器类型,IP,HOST NAME,User name, password 没啥好说,这里的用户名和密码和界面上的用户名和密码一致。

在高级设置中,记得将 Port Number 设置为 6009, 或者使用 Use SSL 的话,输入 6008.

详细的每一步指导看这里

reference


2019-05-02 qnap , nas , bt , pt

威联通折腾篇十三:替换默认 shell 为 zsh

默认 SSH 登录到 QNAP 的 login shell 可以通过 echo $SHELL 来查看到是

/bin/sh

默认的这个 bash 是 QNAP 自带的

/bin/sh --version
GNU bash, version 3.2.57(1)-release (x86_64-QNAP-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

也是一个相对比较简陋的版本,自动补全很难用,也没有语法高亮。所以想能不能把 QNAP 自带的 shell 换成日常使用的 ZSH,QNAP 本质上就是一个 Linux,所以理所当然的应该是可行的。

Installation

首先要要解决的问题是安装问题,普通的 Linux 发行版直接使用一行命令就可以完成,QNAP 可以使用 QNAP club 别人提供的版本,直接安装即可

wget https://cdn.qnapclub.eu/qpkg_artifacts/ZSH_5.7.0_x86_64/ZSH_5.7.0_x86_64.qpkg
sh ZSH_5.7.0_x86_64.qpkg

如果你参考过我之前的文章 你应该知道添加了 QNAP Club 的地址可以直接在 App Center 中直接搜索下载。

安装好之后,默认的 zsh 会安装到

/opt/ZSH

Usage

SSH 登陆 QNAP 之后直接在终端输入 zsh 即可进入 zsh。

ZSH 一些强大的功能:

  • 强大的补全功能
  • 错误检查以及自动更正
  • 命令别名、路径别名
  • 强大的提示信息

默认的配置在 /opt/ZSH 中,可以自己做一些微调,比如

vi /opt/ZSH/zshrc.zsh-template
or
vi /root/.zshrc

修改主题

ZSH_THEME="agnoster"

等等。

Tips

如果在使用过程中发现,delete功能异常,比如delete虽然删除了字符但是向右多显示一个空格,而且不显示移动光标 那么可以编辑zsh配置文件

vi ~/.zshrc

在.zshrc里添加

TERM=xterm

保存, 然后执行, 使配置生效

source ~/.zshrc

2019-05-01 qnap , qnap-tutorial , qpkg , linux , shell , login-shell , zsh , oh-my-zsh , bash

Cinnamon alt+f2 命令

很早就开始用 Cinnamon 作为 Linux 的主要桌面环境,还折腾过 Cinnamon 的主题,但是其实一直没怎么关注 Alt + F2 的功能,唯一知道的命令就是 r 用来重启 Cinnamon。所以这里就总结总结 Alt+F2 可以用的命令。

内置命令

-‘r’ - restart Cinnamon

  • ‘rt’ - reload the current Cinnamon theme
  • ‘lg’ - start the Looking Glass debugger (which itself seems not to be documented anywhere)

任何 Xwindows 应用

在 Alt + F2 下运行无界面的命令,比如 ls 可能得不到任何结果,但是可以运行比如 firefox 这样有窗口的命令。该命令需要在 PATH 下。

快速打开文件夹

在 Alt + F2 窗口下输入文件目录可以快速使用默认文件浏览器打开该目录。


2019-04-29 cinnamon , commands

drools 编程例子

关于 Drools 更多的介绍 可以参考之前的文章

这篇文章主要讲解如何在项目中执行 DRL 文件并取得结果。

ERROR

如果遇到这样的错误,大部分情况下是 drl 规则文件所在的文件夹,没有被项目识别为 resources 文件夹,在 IntelliJ IDE 中可以使用设置为资源文件夹来解决。

Exception in thread "main" java.lang.RuntimeException: Unable to get LastModified for ClasspathResource
    at org.drools.core.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:212)
    at org.drools.core.io.impl.ClassPathResource.getInputStream(ClassPathResource.java:149)
    at org.drools.compiler.compiler.DrlParser.parse(DrlParser.java:154)
    at org.drools.compiler.compiler.DrlParser.parse(DrlParser.java:144)
    at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.drlToPackageDescr(KnowledgeBuilderImpl.java:541)
    at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addPackageFromDrl(KnowledgeBuilderImpl.java:529)
    at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addKnowledgeResource(KnowledgeBuilderImpl.java:753)
    at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:2296)
    at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:2285)
    at com.neo.drools.banking.RuleRunner.runRules(RuleRunner.java:32)
    at com.neo.drools.banking.BankingExample1.main(BankingExample1.java:10)
Caused by: java.io.FileNotFoundException: 'Example1.drl' cannot be opened because it does not exist
    at org.drools.core.io.impl.ClassPathResource.getURL(ClassPathResource.java:173)
    at org.drools.core.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:185)
    ... 10 more

2019-04-26 drools , drl , jboss , java , rule-engine

电子书

本站提供服务

最近文章

  • 从 Buffer 消费图学习 CCPM 项目管理方法 CCPM(Critical Chain Project Management)中文叫做关键链项目管理方法,是 Eliyahu M. Goldratt 在其著作 Critical Chain 中踢出来的项目管理方法,它侧重于项目执行所需要的资源,通过识别和管理项目关键链的方法来有效的监控项目工期,以及提高项目交付率。
  • AI Shell 让 AI 在命令行下提供 Shell 命令 AI Shell 是一款在命令行下的 AI 自动补全工具,当你想要实现一个功能,敲一大段命令又记不住的时候,使用自然语言让 AI 给你生成一个可执行的命令,然后确认之后执行。
  • 最棒的 Navidrome 音乐客户端 Sonixd(Feishin) Sonixd 是一款跨平台的音乐播放器,可以使用 [[Subsonic API]],兼容 Jellyfin,[[Navidrome]],Airsonic,Airsonic-Advanced,Gonic,Astiga 等等服务端。 Sonixd 是一款跨平台的音乐播放器,可以使用 [[Subsonic API]],兼容 Jellyfin,[[Navidrome]],Airsonic,Airsonic-Advanced,Gonic,Astiga 等等服务端。
  • 中心化加密货币交易所 Gate 注册以及认证 Gate.io 是一个中心化的加密货币交易所。Gate 中文通常被称为「芝麻开门」,Gate 创立于 2013 年,前身是比特儿,是一家致力于安全、稳定的数字货币交易所,支持超过 1600 种数字货币的交易,提供超过 2700 个交易对。
  • 不重启的情况下重新加载 rTorrent 配置文件 因为我在 Screen 下使用 rTorrent,最近经常调试修改 rtorrent.rc 配置文件,所以想要找一个方法可以在不重启 rTorrent 的情况重新加载配置文件,网上调查了一下之后发现原来挺简单的。