menu Chancel's Blog
rss_feed lightbulb_outline

我的笔记

Linux - 利用Curl操作WebDAV文件服务器

在命令行模式下通常我们需要拷贝日志或SQL文件用于日志分析数据分析,这个时候通常的做法是使用SCP或基于SCP的扩展软件如Winscp等工具

也有不少第三方的SSH工具自带文件管理,通常足够满足我们对于服务器文件的管理,但也有特殊情况

如PVE或者堡垒机等在网页上操作服务器,这个时候我们无法使用常规手段获取到服务器的文件,在网页的命令行中分析文件是在是一件要命的事情

恰好手头有一个能用的WebDAV服务器(通常家庭NAS/服务器文件管理器Web服务都会带),那就可以利用CURL来上传/下载文件

获取服务器dav文件列表,理论上应该会返回文件列表,但我的WebDAV服务器仅返回“Not Found”

❯ curl --user "username:password" 'https://www.chancel.ltd/dav/'
Not Found

上传文件

❯ curl --user "username:password" -T '/root/codes/route_restart/demo.log' 'https://www.chancel.ltd/dav/demo.log'

读取文件

❯ curl --user "username:password" 'https://www.chancel.ltd/dav/demo.log'

删除文件

❯ curl -X DELETE --user "username:password" 'https://www.chancel.ltd/dav/demo.log'

Develop Base Linux 2021-04-20 03:35:41 location_on

Haproxy - http代理的负载均衡配置文件

在封闭内网,有多个HTTP代理服务器做正向代理访问外网,使用Haproxy做简单的配置

global
    # 最大并发2000
    maxconn 2000
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

    # Default SSL material locations
    ca-base /etc/ssl/certs
    crt-base /etc/ssl/private

       # 日志配置,需要搭配rsyslog实现,日志等级local2
    log 127.0.0.1 local2

    # Default ciphers to use on SSL-enabled listening sockets.
    # For more information, see ciphers(1SSL). This list is from:
    #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
    # An alternative list with additional directives can be obtained from
    #  https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy
    ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
    ssl-default-bind-options no-sslv3

defaults
    log global
    mode    http
    option  httplog
    option  dontlognull
        timeout connect 30s
        timeout client  30s
        timeout server  30s
    maxconn 2000

frontend http-proxy
    bind *:33128
    mode http
    # 以下3句只允许172.16.1.2访问,不允许其他来源ip访问
    acl allow_host src 172.16.1.2
    tcp-request content accept if allow_host
    tcp-request content reject
    default_backend http-proxy-backend

backend http-proxy-backend
    mode http
    balance roundrobin
    option  redispatch
    # 超出最大请求数则排队30秒
    timeout queue 30s
    default-server check inter 1000 rise 1 fall 1 maxconn 2000
    server  http-proxy-1   172.16.1.11:3128 
    server  http-proxy-2   172.16.1.12:3128
    server  http-proxy-3   172.16.1.13:3128

# 监控面板,访问8404
listen stats
    bind *:8404
    stats enable
    stats uri /monitor
    stats refresh 5s

如果需要将访问信息输出到 /var/log/haproxy.log,则需要修改/etc/rsyslog.conf,在文件尾添加如下配置

...

$ModLoad imudp
$UDPServerRun 514

local2.* /var/log/haproxy.log

Network 2021-04-13 03:41:52 location_on

如何测试程序的并发量支持?

对于Web服务程序来讲,衡量并发性能通常会用到2个概念

QPS(Queries Per Second)

  • 每秒请求数,一般情况下指1秒内处理完成多少个流量请求

TPS(Transactions Per Second)

  • 每秒事务数,与QPS相比,TPS一般指1秒内能处理完成多少个原子操作请求

对于并发测试,通常可以写异步请求代码来做测试,更方便的方法可以使用apache的ab工具来做测试

使用 ab 指令来确认系统是否有安装,如无,则可以尝试安装apache

sudo apt install apache

使用ab来测试并发性,-n表示请求总数,-c表示请求并发数

ab -n 1000 -c 100 http://www.baidu.com/

例子:使用10个并发数请求1000次 http://www.baidu.com/ 如下

❯ ab -n 1000 -c 10 http://www.baidu.com/
                                                                                       ~
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking v.hao123.baidu.com [through 10.0.0.155:3128] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache
Server Hostname:        v.hao123.baidu.com
Server Port:            80

Document Path:          /dongman/
Document Length:        28430 bytes

# 并发数
Concurrency Level:      10
# 总请求时间
Time taken for tests:   32.629 seconds
# 完成的请求(包含失败)
Complete requests:      1000
# 失败的请求
Failed requests:        13
   (Connect: 0, Receive: 0, Length: 13, Exceptions: 0)
Non-2xx responses:      11
Total transferred:      28799265 bytes
HTML transferred:       28109801 bytes
# 每秒请求数(系统吞吐量)
Requests per second:    30.65 [#/sec] (mean)
# 请求平均等待时间(毫秒)
Time per request:       326.287 [ms] (mean)
# 服务器平均处理时间
Time per request:       32.629 [ms] (mean, across all concurrent requests)
Transfer rate:          861.95 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       1
Processing:     1  323 672.7    224    7378
Waiting:        1  205 588.6    119    7201
Total:          2  323 672.7    224    7378

Percentage of the requests served within a certain time (ms)
  50%    224
  66%    267
  75%    305
  80%    343
 # 90%的请求在447毫秒内返回
  90%    447
  95%    620
  98%    927
  99%   3514
 100%   7378 (longest request)

ab压力测试HTTPS通常会有不支持证书等问题,所以也可以使用siege来做压力测试

sudo apt install siege

使用siege来测试并发数,-c表示并发数,-r表示重复次数

siege -c 20 -r 10 https://www.baidu.com

举例如下

❯ siege -c 20 -r 10 https://www.baidu.com
{   
       "transactions":                  4217,
    "availability":                93.03,
    "elapsed_time":               185.07,
    "data_transferred":            55.28,
    "response_time":                0.35,
    "transaction_rate":            22.79,
    "throughput":                   0.30,
    "concurrency":                  7.90,
    "successful_transactions":          4250,
    "failed_transactions":               316,
    "longest_transaction":             14.54,
    "shortest_transaction":             0.07
}

其参数含义如下

参数 解释
transactions 请求总次数
availability 请求成功百分比
elapsed_time 请求所耗费总时间
data_transferred 请求总数据量大小
response_time 请求的响应时间
transaction_rate 请求的处理请求频率
throughput 系统吞吐量(网络传输速度)
concurrency 请求并发连接数
successful_transactions 请求成功次数
failed_transactions 请求失败次数
longest_transaction 请求最大耗时
shortest_transaction 请求最短耗时

Network 2021-04-08 07:56:23 location_on

Android - 国外第三方原生Rom

资料来源

备份下以便日后查询

  • Pixel Experience
  • LineageOS
  • Evolution X
  • Corvus OS
  • Revenge OS
  • Havoc-OS
  • Arrow OS
  • Bliss ROM
  • Project Sakura
  • MSM Extended
  • crDroid
  • Paranoid Android

Operating System 2021-04-06 04:01:37 location_on

Python3 - logging 以yaml形式配置项目日志

logging 支持YAML格式的日志配置文件,在项目入口main文件同一层添加logging.yaml文件,内容如下

version: 1
formatters:
  common:
    format: "%(asctime)s - %(levelname)s - %(threadName)s - %(message)s"
    datefmt: "%Y/%m/%d %H:%M:%S"
  console:
    format: "%(asctime)s - %(levelname)s - %(pathname)s - %(message)s"
    datefmt: "%Y/%m/%d %H:%M:%S"
handlers:
  # 不同会输出大于等于此级别的信息。
  common:
    class: logging.handlers.TimedRotatingFileHandler
    formatter: common
    level: INFO
    when: D
    interval: 1
    encoding: utf8
    filename: "logs/running.log"
    # suffix: "%Y-%m-%d.log"
    # 日志保留个数
    backupCount: 7
  console:
    class : logging.StreamHandler
    formatter: console
    level   : INFO
    stream  : ext://sys.stdout
loggers:
  main.common:
    level: INFO
    handlers: [common]
# 如果模块中没有使用 如logging.getLogger('main.common') 这样的配置来获取loggers中对应的配置,则默认会使用下面的root配置
root:
  level: DEBUG
  handlers: [console]

在main文件配置logging模块

import os
import yaml
import logging
import logging.config

os.chdir(os.path.abspath(os.path.dirname(os.path.abspath(__file__))))

# Logger config
if not os.path.exists('logs'):
    os.mkdir('logs')
# 日志配置
with open('logging.yaml', 'r', encoding='utf-8') as f:
    config = yaml.load(f, Loader=yaml.FullLoader)
    logging.config.dictConfig(config)
logger = logging.getLogger('main.common')

Develop Technology Python 2021-04-06 02:09:28 location_on

PVE - 关机并休眠PVE的所有虚拟机

关机并休眠所有虚拟机

qm list | grep running | awk -F'[^0-9]*' '$0=$2' | while read -r vm_id; do qm suspend $vm_id --todisk 1; done; shutdown -h now

核心点在于如何休眠单台机器

qm suspend 100 --todisk 1

参考资料

Virtualization Technology Linux 2021-03-26 16:07:30 location_on

Markdown - 代码块语言标注支持名称列表(Python3)

经常使用Markdown语法,但对于代码块开头的三个分号```后面注解的语言类型一直属于想到什么写什么

使用Markdown解析器之后发现这一部分是有明确规范的写法的,于是从Python的pygments lexers 中提取这一部分解析列表出来,应该覆盖了绝大部分的语言缩写了

编程语言 支持的缩写
ABAP abap
AMDGPU amdgpu
APL apl
ABNF abnf
ActionScript 3 as3, actionscript3
ActionScript as, actionscript
Ada ada, ada95, ada2005
ADL adl
Agda agda
Aheui aheui
Alloy alloy
AmbientTalk at, ambienttalk, ambienttalk/2
Ampl ampl
HTML + Angular2 html+ng2
Angular2 ng2
ANTLR With ActionScript Target antlr-as, antlr-actionscript
ANTLR With C# Target antlr-csharp, antlr-c#
ANTLR With CPP Target antlr-cpp
ANTLR With Java Target antlr-java
ANTLR antlr
ANTLR With ObjectiveC Target antlr-objc
ANTLR With Perl Target antlr-perl
ANTLR With Python Target antlr-python
ANTLR With Ruby Target antlr-ruby, antlr-rb
ApacheConf apacheconf, aconf, apache
AppleScript applescript
Arduino arduino
Arrow arrow
AspectJ aspectj
Asymptote asy, asymptote
Augeas augeas
AutoIt autoit
autohotkey ahk, autohotkey
Awk awk, gawk, mawk, nawk
BBC Basic bbcbasic
BBCode bbcode
BC bc
BST bst, bst-pybtex
BARE bare
Base Makefile basemake
Bash bash, sh, ksh, zsh, shell
Bash Session console, shell-session
Batchfile bat, batch, dosbatch, winbatch
Befunge befunge
BibTeX bib, bibtex
BlitzBasic blitzbasic, b3d, bplus
BlitzMax blitzmax, bmax
BNF bnf
Boa boa
Boo boo
Boogie boogie
Brainfuck brainfuck, bf
BUGS bugs, winbugs, openbugs
CAmkES camkes, idl4
C c
CMake cmake
c-objdump c-objdump
CPSA cpsa
aspx-cs aspx-cs
C# csharp, c#
ca65 assembler ca65
cADL cadl
CapDL capdl
Cap'n Proto capnp
CBM BASIC V2 cbmbas
CDDL cddl
Ceylon ceylon
CFEngine3 cfengine3, cf3
ChaiScript chai, chaiscript
Chapel chapel, chpl
Charmci charmci
HTML+Cheetah html+cheetah, html+spitfire, htmlcheetah
JavaScript+Cheetah js+cheetah, javascript+cheetah, js+spitfire, javascript+spitfire
Cheetah cheetah, spitfire
XML+Cheetah xml+cheetah, xml+spitfire
Cirru cirru
Clay clay
Clean clean
Clojure clojure, clj
ClojureScript clojurescript, cljs
COBOLFree cobolfree
COBOL cobol
CoffeeScript coffee-script, coffeescript, coffee
Coldfusion CFC cfc
Coldfusion HTML cfm
cfstatement cfs
Common Lisp common-lisp, cl, lisp
Component Pascal componentpascal, cp
Coq coq
C++ cpp, c++
cpp-objdump cpp-objdump, c++-objdumb, cxx-objdump
Crmsh crmsh, pcmk
Croc croc
Cryptol cryptol, cry
Crystal cr, crystal
Csound Document csound-document, csound-csd
Csound Orchestra csound, csound-orc
Csound Score csound-score, csound-sco
CSS+Django/Jinja css+django, css+jinja
CSS+Ruby css+erb, css+ruby
CSS+Genshi Text css+genshitext, css+genshi
CSS css
CSS+PHP css+php
CSS+Smarty css+smarty
CUDA cuda, cu
Cypher cypher
Cython cython, pyx, pyrex
D d
d-objdump d-objdump
Darcs Patch dpatch
Dart dart
DASM16 dasm16
Debian Control file control, debcontrol
Delphi delphi, pas, pascal, objectpascal
Devicetree devicetree, dts
dg dg
Diff diff, udiff
Django/Jinja django, jinja
Docker docker, dockerfile
DTD dtd
Duel duel, jbst, jsonml+bst
Dylan session dylan-console, dylan-repl
Dylan dylan
DylanLID dylan-lid, lid
ECL ecl
eC ec
Earl Grey earl-grey, earlgrey, eg
Easytrieve easytrieve
EBNF ebnf
Eiffel eiffel
Elixir iex session iex
Elixir elixir, ex, exs
Elm elm
EmacsLisp emacs, elisp, emacs-lisp
E-mail email, eml
ERB erb
Erlang erlang
Erlang erl session erl
HTML+Evoque html+evoque
Evoque evoque
XML+Evoque xml+evoque
execline execline
Ezhil ezhil
F# fsharp, f#
FStar fstar
Factor factor
Fancy fancy, fy
Fantom fan
Felix felix, flx
Fennel fennel, fnl
Fish fish, fishshell
Flatline flatline
FloScript floscript, flo
Forth forth
FortranFixed fortranfixed
Fortran fortran
FoxPro foxpro, vfp, clipper, xbase
Freefem freefem
Futhark futhark
GAP gap
GDScript gdscript, gd
GLSL glsl
GAS gas, asm
Genshi genshi, kid, xml+genshi, xml+kid
Genshi Text genshitext
Gettext Catalog pot, po
Gherkin cucumber, gherkin
Gnuplot gnuplot
Go go
Golo golo
GoodData-CL gooddata-cl
Gosu gosu
Gosu Template gst
Graphviz graphviz, dot
Groff groff, nroff, man
Groovy groovy
HLSL hlsl
Haml haml
HTML+Handlebars html+handlebars
Handlebars handlebars
Haskell haskell, hs
Haxe hx, haxe, hxsl
Hexdump hexdump
HSAIL hsail, hsa
Hspec hspec
HTML+Django/Jinja html+django, html+jinja, htmldjango
HTML+Genshi html+genshi, html+kid
HTML html
HTML+PHP html+php
HTML+Smarty html+smarty
HTTP http
Hxml haxeml, hxml
Hy hylang
Hybris hybris, hy
IDL idl
Icon icon
Idris idris, idr
Igor igor, igorpro
Inform 6 inform6, i6
Inform 6 template i6t
Inform 7 inform7, i7
INI ini, cfg, dosini
Io io
Ioke ioke, ik
IRC logs irc
Isabelle isabelle
J j
JAGS jags
Jasmin jasmin, jasminxt
Java java
JavaScript+Django/Jinja js+django, javascript+django, js+jinja, javascript+jinja
JavaScript+Ruby js+erb, javascript+erb, js+ruby, javascript+ruby
JavaScript+Genshi Text js+genshitext, js+genshi, javascript+genshitext, javascript+genshi
JavaScript js, javascript
JavaScript+PHP js+php, javascript+php
JavaScript+Smarty js+smarty, javascript+smarty
JCL jcl
JSGF jsgf
JSONBareObject
JSON-LD jsonld, json-ld
JSON json, json-object
Java Server Page jsp
Julia console jlcon
Julia julia, jl
Juttle juttle
Kal kal
Kconfig kconfig, menuconfig, linux-config, kernel-config
Kernel log kmsg, dmesg
Koka koka
Kotlin kotlin
LSL lsl
CSS+Lasso css+lasso
HTML+Lasso html+lasso
JavaScript+Lasso js+lasso, javascript+lasso
Lasso lasso, lassoscript
XML+Lasso xml+lasso
Lean lean
LessCss less
Lighttpd configuration file lighty, lighttpd
Limbo limbo
liquid liquid
Literate Agda lagda, literate-agda
Literate Cryptol lcry, literate-cryptol, lcryptol
Literate Haskell lhs, literate-haskell, lhaskell
Literate Idris lidr, literate-idris, lidris
LiveScript live-script, livescript
LLVM llvm
LLVM-MIR Body llvm-mir-body
LLVM-MIR llvm-mir
Logos logos
Logtalk logtalk
Lua lua
MIME mime
MOOCode moocode, moo
MSDOS Session doscon
Makefile make, makefile, mf, bsdmake
CSS+Mako css+mako
HTML+Mako html+mako
JavaScript+Mako js+mako, javascript+mako
Mako mako
XML+Mako xml+mako
MAQL maql
markdown md, markdown
Mask mask
Mason mason
Mathematica mathematica, mma, nb
Matlab matlab
Matlab session matlabsession
MiniD minid
MiniScript ms, miniscript
Modelica modelica
Modula-2 modula2, m2
MoinMoin/Trac Wiki markup trac-wiki, moin
Monkey monkey
Monte monte
MoonScript moon, moonscript
Mosel mosel
CSS+mozpreproc css+mozpreproc
mozhashpreproc mozhashpreproc
Javascript+mozpreproc javascript+mozpreproc
mozpercentpreproc mozpercentpreproc
XUL+mozpreproc xul+mozpreproc
MQL mql, mq4, mq5, mql4, mql5
Mscgen mscgen, msc
MuPAD mupad
MXML mxml
MySQL mysql
CSS+Myghty css+myghty
HTML+Myghty html+myghty
JavaScript+Myghty js+myghty, javascript+myghty
Myghty myghty
XML+Myghty xml+myghty
NCL ncl
NSIS nsis, nsi, nsh
NASM nasm
objdump-nasm objdump-nasm
Nemerle nemerle
nesC nesc
NewLisp newlisp
Newspeak newspeak
Nginx configuration file nginx
Nimrod nim, nimrod
Nit nit
Nix nixos, nix
Notmuch notmuch
NuSMV nusmv
NumPy numpy
objdump objdump
Objective-C objective-c, objectivec, obj-c, objc
Objective-C++ objective-c++, objectivec++, obj-c++, objc++
Objective-J objective-j, objectivej, obj-j, objj
OCaml ocaml
Octave octave
ODIN odin
Ooc ooc
Opa opa
OpenEdge ABL openedge, abl, progress
PacmanConf pacmanconf
Pan pan
ParaSail parasail
Pawn pawn
PEG peg
Perl6 perl6, pl6, raku
Perl perl, pl
PHP php, php3, php4, php5
Pig pig
Pike pike
PkgConfig pkgconfig
PL/pgSQL plpgsql
Pointless pointless
Pony pony
PostScript postscript, postscr
PostgreSQL console (psql) psql, postgresql-console, postgres-console
PostgreSQL SQL dialect postgresql, postgres
POVRay pov
PowerShell powershell, posh, ps1, psm1
PowerShell Session ps1con
Praat praat
Prolog prolog
PromQL promql
Properties properties, jproperties
Protocol Buffer protobuf, proto
PsySH console session for PHP psysh
Pug pug, jade
Puppet puppet
PyPy Log pypylog, pypy
Python 2.x python2, py2
Python 2.x Traceback py2tb
Python console session pycon
Python python, py, sage, python3, py3
Python Traceback pytb, py3tb
QBasic qbasic, basic
QVTO qvto, qvt
QML qml, qbs
RConsole rconsole, rout
Relax-NG Compact rnc, rng-compact
RPMSpec spec
Racket racket, rkt
Ragel in C Host ragel-c
Ragel in CPP Host ragel-cpp
Ragel in D Host ragel-d
Embedded Ragel ragel-em
Ragel in Java Host ragel-java
Ragel ragel
Ragel in Objective C Host ragel-objc
Ragel in Ruby Host ragel-ruby, ragel-rb
Raw token data
Rd rd
ReasonML reason, reasonml
REBOL rebol
Red red, red/system
Redcode redcode
reg registry
ResourceBundle resource, resourcebundle
Rexx rexx, arexx
RHTML rhtml, html+erb, html+ruby
Ride ride
Roboconf Graph roboconf-graph
Roboconf Instances roboconf-instances
RobotFramework robotframework
RQL rql
RSL rsl
reStructuredText rst, rest, restructuredtext
TrafficScript rts, trafficscript
Ruby irb session rbcon, irb
Ruby rb, ruby, duby
Rust rust, rs
SAS sas
S splus, s, r
Standard ML sml
SARL sarl
Sass sass
Scala scala
Scaml scaml
scdoc scdoc, scd
Scheme scheme, scm
Scilab scilab
SCSS scss
ShExC shexc, shex
Shen shen
Sieve sieve
Silver silver
Singularity singularity
Slash slash
Slim slim
Slurm slurm, sbatch
Smali smali
Smalltalk smalltalk, squeak, st
SmartGameFormat sgf
Smarty smarty
Snobol snobol
Snowball snowball
Solidity solidity
SourcePawn sp
Debian Sourcelist sourceslist, sources.list, debsources
SPARQL sparql
SQL sql
sqlite3con sqlite3
SquidConf squidconf, squid.conf, squid
Scalate Server Page ssp
Stan stan
Stata stata, do
SuperCollider sc, supercollider
Swift swift
SWIG swig
systemverilog systemverilog, sv
TAP tap
Typographic Number Theory tnt
TOML toml
TADS 3 tads3
TASM tasm
Tcl tcl
Tcsh tcsh, csh
Tcsh Session tcshcon
Tea tea
Tera Term macro ttl, teraterm, teratermmacro
Termcap termcap
Terminfo terminfo
Terraform terraform, tf
TeX tex, latex
Text only text
Thrift thrift
tiddler tid
Todotxt todotxt
Transact-SQL tsql, t-sql
Treetop treetop
Turtle turtle
HTML+Twig html+twig
Twig twig
TypeScript ts, typescript
TypoScriptCssData typoscriptcssdata
TypoScriptHtmlData typoscripthtmldata
TypoScript typoscript
ucode ucode
Unicon unicon
UrbiScript urbiscript
USD usd, usda
VBScript vbscript
VCL vcl
VCLSnippets vclsnippets, vclsnippet
VCTreeStatus vctreestatus
VGL vgl
Vala vala, vapi
aspx-vb aspx-vb
VB.net vb.net, vbnet
HTML+Velocity html+velocity
Velocity velocity
XML+Velocity xml+velocity
verilog verilog, v
vhdl vhdl
VimL vim
WDiff wdiff
Web IDL webidl
Whiley whiley
X10 x10, xten
XQuery xquery, xqy, xq, xql, xqm
XML+Django/Jinja xml+django, xml+jinja
XML+Ruby xml+erb, xml+ruby
XML xml
XML+PHP xml+php
XML+Smarty xml+smarty
Xorg xorg.conf
XSLT xslt
Xtend xtend
xtlang extempore
YAML+Jinja yaml+jinja, salt, sls
YAML yaml
YANG yang
Zeek zeek, bro
Zephir zephir
Zig zig

Develop Base 2021-03-25 05:25:25 location_on

Python3 - 让脚本支持绝对路径启动

对于Python的写成YAML配置文件导入Logging模块应用来说,通常会导致在当前运行目录下生成logs文件夹

但我们运行项目通常是希望在项目目录下生成logs文件夹的,无论在哪一个目录启动Python项目,我们都更希望默认启动路径是项目的绝对路径

使用下面的代码放在入口方法处可以切换全局的Python项目启动路径为项目的绝对路径

import os

os.chdir(os.path.abspath(os.path.dirname(os.path.abspath(__file__))))

Develop Technology Python 2021-03-23 03:01:59 location_on

Docker - 如何备份已运行的容器(迁移/导出)

在NAS上运行的Docker容器PhotoPrism需要备份以防万一(当然备份原始照片数据更重要)

备份步骤

  1. commit container
  2. save container to tar file

恢复步骤

  1. load container by tar file

全部步骤指令

# 打印当前所有容器
❯ docker ps
CONTAINER ID   IMAGE                          COMMAND                  CREATED       STATUS       PORTS                     NAMES
a48bc98b4a21   photoprism/photoprism:latest   "/entrypoint.sh phot…"   2 weeks ago   Up 5 hours   0.0.0.0:32342->2342/tcp   chancel_photoprism_1
f1d7d5ac091f   mariadb:10.5                   "docker-entrypoint.s…"   2 weeks ago   Up 5 hours   3306/tcp                  chancel_mariadb_1

# 提交需要备份的容器
❯ docker commit -p a48bc98b4a21 photoprism-container-backup

# 查看镜像列表
❯ docker images
REPOSITORY                    TAG       IMAGE ID       CREATED         SIZE
photoprism-container-backup   latest    cc71161fb644   4 minutes ago   14.3GB
hello-world                   latest    d1165f221234   2 weeks ago     13.3kB
mariadb                       10.5      e27cf5bc24fe   2 weeks ago     401MB
photoprism/photoprism         latest    f81f7b1e47a4   3 weeks ago     1.3GB

# 导出已保存的镜像备份为tar压缩文件
❯ docker save -o ~/photoprism-container-backup.tar photoprism-container-backup

# 导入已保存的镜像备份tar文件
❯ docker load -i ~/photoprism-container-backup.tar

# 重新使用镜像运行容器
docker run -d -p 32342:2342 container-backup photoprism-container-backup

Virtualization Technology 2021-03-22 15:53:05 location_on

Gnome3 - 改变切换工作台(多桌面)快捷键

Gnome的切换桌面默认快捷键是 Ctrl + Alt + Left/Right,与Windows10的多桌面切换快捷键(Ctrl + Super + Left/Right)不同。

经常在两个操作系统之间切换不一样的桌面切换快捷键还是很烦的,尤其是QQ音乐的默认切歌快捷键与Gnome桌面切换一致导致我莫名其妙的切歌了

修改Gnome快捷键需要安装 dconf-editor 工具,不同系统安装方法不一样,我用的是Manjaro,安装如下

sudo pacman -S dconf-editor

之后在终端运行 dconf-editor 命令呼出修改界面,依次选择 org - gnome - desktop - vm -keybindings ,然后找到switch-to-workspace修改即可

或者直接右上角搜索,输入“org.gnome.desktop.wm.keybindings”也可以直接定位到修改界面

如图,自行修改switch-to-workspace按键即可

Operating System Linux 2021-03-22 07:58:17 location_on

1 of 13 | A total of 124