分类 默认分类 下的文章

linux 任务控制软件 supervisor配置详解(转)
https://www.cnblogs.com/ajianbeyourself/p/5534737.html
http://lixcto.blog.51cto.com/4834175/1539136

安装
yum install supervisor

echo_supervisord_conf > /etc/supervisord.conf

编辑 : /etc/supervisord.conf 去掉下面的注释符

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

启动supersord服务程序
supervisord -c /etc/supervisord.conf

当你修改了supervisord.conf时,要让配置立即生效,键入:
supervisorctl reload

启动某个任务
supervisorctl start xxx

stop某个任务
supervisorctl stop xxx

子进程配置例子:

[program:notify]
command=php /data/xkx/api/shell/notify.php
directory=/data/xkx/api/shell
user=root
autostart=true
autorestart=true
startretries=3
stdout_logfile=/data/xkx/data/supervisor/%(program_name)s_%(process_num)02d.log
stderr_logfile=/data/xkx/data/supervisor/err_%(program_name)s_%(process_num)02d.log

;stdout_logfile=/a/path ; 子进程的stdout的日志路径,可以指定路径,AUTO,none等三个选项。

                             设置为none的话,将没有日志产生。设置为AUTO的话,将随机找一个地方
                             生成日志文件,而且当supervisord重新启动的时候,以前的日志文件会被
                             清空。当 redirect_stderr=true的时候,sterr也会写进这个日志文件

;stdout_logfile_maxbytes=1MB ; 日志文件最大大小,和[supervisord]中定义的一样。默认为50
;stdout_logfile_backups=10 ; 和[supervisord]定义的一样。默认10
;stdout_capture_maxbytes=1MB ; 这个东西是设定capture管道的大小,当值不为0的时候,子进程可以从stdout

                             发送信息,而supervisor可以根据信息,发送相应的event。
                             默认为0,为0的时候表达关闭管道。。。非必须项

;stdout_events_enabled=false ; 当设置为ture的时候,当子进程由stdout向文件描述符中写日志的时候,将

                             触发supervisord发送PROCESS_LOG_STDOUT类型的event
                             默认为false。。。非必须设置

;stderr_logfile=/a/path ; 这个东西是设置stderr写的日志路径,当redirect_stderr=true。这个就不用

                             设置了,设置了也是白搭。因为它会被写入stdout_logfile的同一个文件中
                             默认为AUTO,也就是随便找个地存,supervisord重启被清空。。非必须设置

;stderr_logfile_maxbytes=1MB ; 这个出现好几次了,就不重复了
;stderr_logfile_backups=10 ; 这个也是
;stderr_capture_maxbytes=1MB ; 这个一样,和stdout_capture一样。 默认为0,关闭状态
;stderr_events_enabled=false ; 这个也是一样,默认为false
;environment=A="1",B="2" ; 这个是该子进程的环境变量,和别的子进程是不共享的
;serverurl=AUTO ;

我们在使用redis的时候可能一般都是用于缓存等服务。

要查询现在redis的服务是什么状态,可以用以下方式:

redis-cli 命令:
redis-cli [-h localhost] [-p 6379] monitor

Dump all the received requests in real time;
监控host为localhost,端口为6380,redis的连接及读写操作

使用这个命令会输出如下信息(实时请求):
+OK
+1289800615.808225 "monitor"
+1289800615.839079 "GET" "name"
+1289800615.853694 "PING"
+1289800615.853783 "PING"
+1289800615.854646 "PING"
+1289800615.854974 "PING"
+1289800615.857693 "PING"
+1289800615.866862 "PING"
+1289800615.871944 "PING"

redis-cli info 命令:
redis-cli info

此命令打印出当前REIDS服务的全部状态信息

三、 showlog功能
Redis 有一个实用的slowlog功能,正如你可以猜到的,可以让你检查运行缓慢的查询。

Slowlog 将会记录运行时间超过Y微秒的最后X条查询. X 和 Y 可以在 redis.conf 或者在运行时通过 CONFIG 命令:

CONFIG SET slowlog-log-slower-than 5000
CONFIG SET slowlog-max-len 25
slowlog-log-slower-than 是用来设置微秒数的, 因此上面的设置将记录执行时间超过5秒的查询. 要获取记录的日志,你可以使用 SLOWLOG GET X 命令, 这里 X 是你想要获取的记录条数:

SLOWLOG GET 10
四、Redis中统计各种数据大小的方法
Redis 内存比较大的话,我们就不太容易查出是哪些(种)键占用的空间。

有一些工具能够提供必要的帮助,比如 redis-rdb-tools 可以直接分析 RDB 文件来生成报告

五、超强、超详细Redis数据库入门教程
http://www.jb51.net/article/56448.htm

http://www.yiibai.com/redis/

六、 Redis操作命令总结
http://www.jb51.net/article/61793.htm

你可以像node npm 工具那样 使用 Composer 提供的包,放到项目中直接使用,这个工具会管理你项目中使用的各种包代码。

安装
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"

要全局使用的话,再执行这个命令
sudo mv composer.phar /usr/local/bin/composer

Windows 系统:
找到并进入 PHP 的安装目录(和你在命令行中执行的 php 指令应该是同一套 PHP)。
将 composer.phar 复制到 PHP 的安装目录下面,也就是和 php.exe 在同一级目录。
在 PHP 安装目录下新建一个 composer.bat 文件,并将下列代码保存到此文件中。

@php "%~dp0composer.phar" %*

由于包的管理服务是在国外,国内用户推荐使用国内镜像,用法
https://pkg.phpcomposer.com/#how-to-use-packagist-mirror

以微信overtrue/wechat包为例:
composer.json:
{
"config": {

"vendor-dir": "packages",
"bin-dir": "packages/bin",
"preferred-install": "dist"

},
"require": {

"overtrue/wechat": "~4.0"

},
"repositories": {

"packagist": {
  "type": "composer",
  "url": "https://packagist.phpcomposer.com"
}

}
}

执行:
php composer.phar install
或者
composer install

1.分割 -- split命令

可以指定按行数分割和按字节大小分割两种模式。

(1) 按行数分割

$ split -l 300 large_file.txt new_file_prefix
加上-d,使用数字后缀;加上--verbose,显示分割进度:

$ split -l50000 -d large_file.txt part_ --verbose
(2) 按字节大小分割

$ split -b 10m large_file.log new_file_prefix

2.合并 -- cat命令

$ cat part_* > merge_file.txt

[注] split命令语法:

复制代码
$ split --h
Usage: split [OPTION]... [FILE [PREFIX]]
Output pieces of FILE to PREFIXaa, PREFIXab, ...;
default size is 1000 lines, and default PREFIX is 'x'.

With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
-a, --suffix-length=N generate suffixes of length N (default 2) 后缀名称的长度 (默认为2)

  --additional-suffix=SUFFIX  append an additional SUFFIX to file names

-b, --bytes=SIZE put SIZE bytes per output file 每个输出文件的字节大小
-C, --line-bytes=SIZE put at most SIZE bytes of records per output file 每个输出文件每行的最大字节大小
-d use numeric suffixes starting at 0, not alphabetic 使用数字后缀代替字母后缀

  --numeric-suffixes[=FROM]  same as -d, but allow setting the start value

-e, --elide-empty-files do not generate empty output files with '-n' 不产生空的输出文件

  --filter=COMMAND    write to shell COMMAND; file name is $FILE           写入到shell命令行

-l, --lines=NUMBER put NUMBER lines/records per output file 设定每个输出文件的行数,默认行数是1000行
-n, --number=CHUNKS generate CHUNKS output files; see explanation below 产生chunks文件
-t, --separator=SEP use SEP instead of newline as the record separator; 使用新字符分割

                        '\0' (zero) specifies the NUL character

-u, --unbuffered immediately copy input to output with '-n r/...' 无需缓存

  --verbose           print a diagnostic just before each                  显示分割进度
                        output file is opened
  --help     display this help and exit                                    显示帮助信息
  --version  output version information and exit                           显示版本信息

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

CHUNKS may be:
N split into N files based on size of input
K/N output Kth of N to stdout
l/N split into N files without splitting lines/records
l/K/N output Kth of N to stdout without splitting lines/records
r/N like 'l' but use round robin distribution
r/K/N likewise but only output Kth of N to stdout

GNU coreutils online help: http://www.gnu.org/software/coreutils/
Full documentation at: http://www.gnu.org/software/coreutils/split
or available locally via: info '(coreutils) split invocation'
复制代码

cat命令语法:

复制代码
$ cat --h
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s) to standard output.

With no FILE, or when FILE is -, read standard input.

-A, --show-all equivalent to -vET
-b, --number-nonblank number nonempty output lines, overrides -n
-e equivalent to -vE
-E, --show-ends display $ at end of each line
-n, --number number all output lines
-s, --squeeze-blank suppress repeated empty output lines
-t equivalent to -vT
-T, --show-tabs display TAB characters as ^I
-u (ignored)
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB

  --help     display this help and exit
  --version  output version information and exit

Examples:
cat f - g Output f's contents, then standard input, then g's contents.
cat Copy standard input to standard output.

GNU coreutils online help: http://www.gnu.org/software/coreutils/
Full documentation at: http://www.gnu.org/software/coreutils/cat
or available locally via: info '(coreutils) cat invocation'
复制代码

git 操作方法笔记

自动补全
git --version
下载对应版本的文件:
https://raw.githubusercontent.com/git/git/v2.22.0/contrib/completion/git-completion.bash

如果你用的是 Bash shell,可以试试看 Git 提供的自动补全脚本。下载 Git 的源代码,进入 contrib/completion 目录,会看到一个 git-completion.bash 文件。将此文件复制到你自己的用户主目录中(译注:按照下面的示例,还应改名加上点:cp git-completion.bash ~/.git-completion.bash),并把下面一行内容添加到你的 .bashrc 文件中:

source ~/.git-completion.bash

保存账号密码
git config --global credential.helper store

忽略本地文件权限修改
git config core.fileMode false

tag标签
git tag xxxx [-m xxxxx]
git show xxxx
git push origin xxxx
推送本地所有标签到远程仓库
git push origin [--tags]

删除本地仓库中的文件
git rm与git rm --cached

当我们需要删除暂存区或分支上的文件, 同时工作区也不需要这个文件了, 可以使用
1 git rm file_path
2 git commit -m 'delete somefile'
3 git push
当我们需要删除暂存区或分支上的文件, 但本地又需要使用, 只是不希望这个文件被版本控制, 可以使用
git rm --cached file_path
git commit -m 'delete remote somefile'
git push

本地修改不提交到远程仓库

git update-index --assume-unchanged index.jsp
取消本地忽略
git update-index --no-assume-unchanged index.jsp
查看本地仓库哪些文件被加入忽略列表

恢复跟踪

git update-index --no-assume-unchanged   sp_edaijia/protected/controllers/ApiController.php  //恢复跟踪

#或者
git update-index --skip-worktree xx.php
git update-index --no-skip-worktree xx.php

如果不生效,查看是不是已经被add到暂存区,是的话需要移除暂存区再次执行以上忽略命令

git restore --staged xx.php

如果忽略的文件多了,可以使用以下命令查看忽略列表

git ls-files -v | grep '^h\ '

#查看当前标记状态:
# Windows
git ls-files -v | findstr index.jsp
# Linux/macOS
git ls-files -v | grep index.jsp

#输出以 h 开头:assume-unchanged 生效
#输出以 S 开头:skip-worktree 生效

提取文件路径,方法如下

git ls-files -v | grep '^h\ ' | awk '{print $2}'

所有被忽略的文件,取消忽略的方法,如下

git ls-files -v | grep '^h' | awk '{print $2}' |xargs git update-index --no-assume-unchanged  

查找历史代码片段

git log -G 正则 -p
git log -s 文件名