Press "Enter" to skip to content

Category: Linux运维

Linux,unix,mysql,database,oracle,mysql

使用python在linux终端打印二维码

其实主要就是使用qrcode.QRCode.print_ascii()方法在终端画二维码。接下来介绍使用方法。

准备python环境

sudo pip install qrcode

实际代码

$ python
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import qrcode
>>> 
>>> str = 'https://www.zhukun.net'
>>> qr = qrcode.QRCode()
>>> qr.border = 1
>>> qr.add_data(str)
>>> qr.make()
>>> qr.print_ascii(out=None, tty=False, invert=False)
 ▄▄▄▄▄▄▄  ▄    ▄   ▄▄▄▄▄▄▄ 
 █ ▄▄▄ █ ██ █▄▀▀▄█ █ ▄▄▄ █ 
 █ ███ █ ▀▀▄▀▄█▀ ▄ █ ███ █ 
 █▄▄▄▄▄█ ▄▀█ █▀█ █ █▄▄▄▄▄█ 
 ▄     ▄ █▀▀  ▄▄▀ ▄▄  ▄▄▄  
  ▀▀ ▄ ▄▀█▄ ▀▄███▄█▄███▀█▄ 
  █▀█▀▀▄▀▀▀▄ ▀  ▄▀▀▄▀ ▀  █ 
 █▀ ▀▀ ▄ █▀▀ ▀ ▄█▀█▄█▄▄ █▄ 
 █ ▄▀█▄▄▀▀ ▀ █▄▄ ██▄█▄▀█ ▀ 
 ▄▄▄▄▄▄▄ ▀ █ ▄▄▀ █ ▄ █   ▄ 
 █ ▄▄▄ █  ▀▀█   ██▄▄▄█ ▄▄▄ 
 █ ███ █  ▀▀ ▀██▄▄ ▀  ▄▄▀█ 
 █▄▄▄▄▄█ ▄ █▄██ ▀██ ▀▀▄  █ 
Leave a Comment

Linux下的双向文件同步工具

最近有在2台机器双向同步文件的需求, 于是有了本文. 上网找了一些双向文件同步的工具, 比较典型的有syncthingmirror. 本文介绍mirror的使用方法(不过好像syncthing使用更广泛一些).

  1. 在2台机器上安装好java1.8版本(ubuntu使用sudo apt install openjdk-8-jre命令即可安装);
  2. 在2台机器上安装好Watchman(安装方法);
  3. 在2台机器上安装mirror工具(安装方法见github页面)

假设你的mirror安装在/data/apps/mirror/目录下, 2台机器需要同步/data/sftp/文件夹.

在server端运行mirror程序

写入systemd系统服务

$ vim /etc/systemd/system/mirror.service    #写入如下内容
[Unit]
Description=Mirror (File sync for two sftp servers[10.16.19.21,10.16.19.24])
After=network-online.target
After=network-online.target
Requires=network-online.target

[Service]
Type=simple
ExecStart=/bin/bash -l -c '/data/apps/mirror/mirror server'
Restart=on-failure

[Install]
WantedBy=multi-user.targe

启动程序

$ systemctl daemon-reload
$ systemctl restart mirror.service && systemctl status mirror.service
$ systemctl enable mirror.service
1 Comment

解决df -h命令卡住

通过strace命令判断是在哪个mount point卡住

$ strace df
......
stat("/sys/fs/cgroup/devices", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
stat("/sys/fs/cgroup/pids", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
stat("/sys/fs/cgroup/hugetlb", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
stat("/sys/fs/cgroup/blkio", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
stat("/sys/fs/cgroup/freezer", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
stat("/sys/fs/cgroup/cpuset", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
stat("/sys/fs/cgroup/cpu,cpuacct", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
stat("/sys/fs/cgroup/perf_event", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
stat("/sys/kernel/config", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
stat("/", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0
stat("/proc/sys/fs/binfmt_misc",    #这里卡住了

解决/proc/sys/fs/binfmt_misc被卡住问题(以下方法任选其一)

1. 执行systemctl restart proc-sys-fs-binfmt_misc.automount;

2. 升级到最新 systemd-219-57 版本;

3. 按照红帽知识库的步骤对 proc-sys-fs-binfmt_misc.automount 进行 mask 操作, 只进行静态的 mount 操作;

Leave a Comment

Prometheus中rate和irate的区别

rate()

rate(v range-vector) calculates the per-second average rate of increase of the time series in the range vector.

rate()函数计算某个时间序列范围内的每秒平均增长率。

Breaks in monotonicity (such as counter resets due to target restarts) are automatically adjusted for.

自适应单调性中断(比如target重启导致的计数器重置).

Also, the calculation extrapolates to the ends of the time range, allowing for missed scrapes or imperfect alignment of scrape cycles with the range’s time period.

计算结果是推算到每个时间范围的最后而得出, 允许漏抓和抓取周期与时间范围的不完美结合.

The following example expression returns the per-second rate of HTTP requests as measured over the last 5 minutes, per time series in the range vector:

以下示例返回最后五分钟HTTP请求每秒增长率

rate(http_requests_total{job="api-server"}[5m])

rate should only be used with counters. It is best suited for alerting, and for graphing of slow-moving counters.

rate应该只和计数器一起使用。最适合告警和缓慢计数器的绘图。

Leave a Comment