linux 安装使用supervisor和superlance服务监控

环境:CentOS Linux release 7.4

pip install supervisor

#加载配置,修改如下
echo_supervisord_conf > /etc/supervisord.conf
mkdir /etc/supervisord.d/

vi /etc/supervisord.conf

[include]
files = /etc/supervisord.d/*.ini

#start service
supervisord -c /etc/supervisord.conf

#write a program config
vi /etc/supervisord.d/SimpleHttp.ini

[program:SimpleHttp]
command=python2 -m SimpleHTTPServer 9000
directory=/root ;执行command之前,先切换到工作目录
user=root ;使用oxygen用户来启动该进程
autorestart=true ;程序崩溃时自动重启,重启次数是有限制的,默认为3次
stdout_logfile = /tmp/simple_http.log
loglevel=info

#roload program config, start service
supervisorctl update //配置文件修改后使用该命令加载新的配置
supervisorctl status

#配置服务报警
pip install superlance

#Supervisor 事件发送到飞书
cp feishu-alert/event.conf /etc/supervisord.d/event.ini
supervisorctl update
注意:
1. 更给任何脚本时需执行以下命令,否则更改不生效
supervisorctl reload

参考:
https://www.jianshu.com/p/0b9054b33db3
https://cloud.tencent.com/developer/article/1414822
https://github.com/cmboss/supervisor-event-to-dingtalk-alert

MacOS登入Ubuntu虚拟环境

环境: MacOS,  Ubuntu, Clion

在做C语言开发的时候经常要涉及Linux中的库,因此在MacOS上用VirtualBox安装Ubuntu环境,通过terminal直接登入上去。但有时要用Ubuntu上的Clion,所以安装XQuartz这个支持图形界面的登入工具。使用登入如下:

ssh -Y jerry@192.168.56.101

(注:-Y 代表启用信任的X11 forwarding)

Docker加速

万恶的gfw造成使用docker加载超慢,只好通过国内的阿里云来加速。

打开 https://dev.aliyun.com/search.html

右上角有“管理中心”,点击使用阿里帐户登录。

点击”加速器“

下面有详细的docker加速操作步骤

还有daocloud的加速服务

创建或修改 /etc/docker/daemon.json 文件,修改为如下形式

{
    "registry-mirrors": [
        "加速地址"
    ],
    "insecure-registries": []
}

通过比较daocloud要比aliyun快不少。

另外一种方法是使用http代理:

HTTP_PROXY=proxy-server:8080 docker pull clipper/sklearn_cifar_container

Ubuntu 16

环境:Ubuntu 16,  VirtualBox

安装一个ubuntu 16的虚拟环境,已经启用NAT和host-only,查询网络时却发现host-only没有分配网络地址。

ifconfig -a

编辑interfaces

sudo vi /etc/network/interfaces

添加如下(其中enp0s8是上面查询出的网络标识):

auto enp0s8

iface enp0s8 inet dhcp

然后重启网络

sudo /etc/init.d/networking restart

wordpress使用固定链接

环境:Ubuntu 14.04, wordpress 4.7.1,  Apache/2.4.7

由于wordpress本身的链接方法就是?p=1这种方法,不利于搜索引擎索引,因而使用固定链接方法。步骤如下:

  1. 启用urlrewrite, sudo a2enmode rewrite
  2. vi /etc/apache2/apache2.conf,搜索AllowOverride None,将None修改成All
  3. 重启apache2, sudo service apache2 restart
  4. 登录到wordpress后台,“设置”-》“固定链接”-》“月份和名称型”, 然后在服务器上的目录/var/www/wordpress下创建.htaccess文件,并将后台页面最下面的.htaccess的内容复制的到.htaccess文件内。

到此wordpress的固定链接已经打通。

awk过滤数据

awk -F”\\\\t” ‘$2==”mob” && $6>=1000{print $0}’  /home/hdp-guanggao/huangqiang/tab_stats/load_search_index_alert_daily_stat

2017-01-16 mob 1 NULL NULL 13830 0 0 5609 5743.577000000127 9931.434000000025
2017-01-16 mob 1 100 137 11010 11010 24841 739 955.905000000001 1511.187999999999
2017-01-16 mob 1 100 209 10756 10756 24192 759 890.9829000000002 1451.3469999999988
2017-01-16 mob 1 36 276 174784 27841 47541 1333 1073.7799999999966 1797.8559999999936
2017-01-16 mob 1 99 NULL 1044051 177367 380066 8369 7046.894000000293 11722.183999999928
2017-01-16 mob 1 99 0 63728 10888 23481 497 383.7400000000007 685.7949999999996
2017-01-16 mob 1 99 141 9287 1560 3351 68 49.469999999999985 75.745
2017-01-16 mob 1 99 99 9241 1552 3229 87 74.70999999999997 113.146

 

详细使用参考

http://502245466.blog.51cto.com/7559397/1288472

linux上使用flock来调用程序

在使用linux的crontab定时调用程序时会经常判断程序是否已经启用,之前是直接在程序中判断程序是否启动。后来找到一种比较简洁的方法flock,它是一种文件锁的方式。

[adadmin@s11 ~]$ flock
flock (util-linux-ng 2.17.2)
Usage: flock [-sxun][-w #] fd#
flock [-sxon][-w #] file [-c] command…
flock [-sxon][-w #] directory [-c] command…
-s –shared Get a shared lock
-x –exclusive Get an exclusive lock
-u –unlock Remove a lock
-n –nonblock Fail rather than wait
-w –timeout Wait for a limited amount of time
-o –close Close file descriptor before running command
-c –command Run a single command string through the shell
-h –help Display this text
-V –version Display version

 

使用如下:

先创建一个文件

touch test_flock.lock

调用如下(以python test_flock.py为示例)

flock -nx test_flock.lock python test_flock.py

 

python打包成exe执行文件

环境:windows 7,  python 2.7

写python文件格式.py的程序需要将其打包成可执行的文件形式,可以使用PyInstaller来打包。

下载PyInstaller-3.1文件,使用打包命令如下:

D:\\program\\PyInstaller-3.1>pyinstaller.py -F ../../qs123/s3test.py –upx-dir upx391w

此命令将其打包成一个可执行文件并进行压缩。

 

参数:

-F 指定打包后只生成一个exe格式的文件

-D –onedir 创建一个目录,包含exe文件,但会依赖很多文件(默认选项)

-c –console, –nowindowed 使用控制台,无界面(默认)

-w –windowed, –noconsole 使用窗口,无控制台

-p 添加搜索路径,让其找到对应的库。

-i 改变生成程序的icon图标