实践来自:https://mp.weixin.qq.com/s/TFRv2wfaNpje_5rrELBEgA

定义
==============================================================================================
502,Bad Gateway,网关错误,它往往表示网关从上游服务器中接收到的响应是无效的,主要是PHP执行时间大于PHP超时,于是给Nginx返回为空引起的。
502并不是指网关本身出了问题,而是
1)从上游接收响应出了问题,比如由于上游服务自身超时导致不能产生响应数据,
2)或者上游不按照协议约定来返回数据导致网关不能正常解析。


情况1:关掉PHP-FPM进程:
"123.115.119.90" "up.levoo.com" "-" "[30/Nov/2018:22:51:52 +0800]" "GET /hello.php HTTP/1.1" "502" "552" "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36" "0.000" "0.000"
2018/11/30 22:51:52 [crit] 29084#0: *124 connect() to unix:/dev/shm/php-fcgi.sock failed (2: No such file or directory) while connecting to upstream, client: 123.115.119.90, server: up.levoo.com, request: "GET /hello.php HTTP/1.1", upstream: "fastcgi://unix:/dev/shm/php-fcgi.sock:", host: "up.levoo.com"

情况2:

php-fpm.conf配置:

request_terminate_timeout=5
nginx配置:
fastcgi_read_timeout 10;

php-fpm.conf设置的最大执行时间是5s,但是php脚本需要的执行时间大于7s,所以php-fpm进程执行5s时就回退出,此时php脚本没有正常执行完,返回给网关Nginx的数据为空,于是导致502。
502日志:
"123.115.119.90" "up.levoo.com" "-" "[30/Nov/2018:22:53:14 +0800]" "GET /hello.php HTTP/1.1" "502" "552" "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36" "5.287" "5.288"
2018/11/30 22:53:14 [error] 29084#0: *188 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 123.115.119.90, server: up.levoo.com, request: "GET /hello.php HTTP/1.1", upstream: "fastcgi://unix:/dev/shm/php-fcgi.sock:", host: "up.levoo.com"

在实际的实践中发现当在EasySwoole里传大于设置的图片也会出现 Nginx的代理机上出现104: Connection reset by peer的情况。

==============================================================================================

504:nginx则以为上游php-fpm没有按照设置时间超过Nginx的等待时间,返回响应数据就会返回504。
504,Gateway Timeout,网关超时。

它表示网关没有从上游及时获取响应数据。注意它和502在超时场景下的区别,502是指上游php-fpm因为超过自身允许的执行时间而不能正常生成响应数据,而504是指在php-fpm还未执行完成的某一时刻,由于超过了nginx自身的超时时间,nginx则以为上游php-fpm没有按照设置时间返回响应数据就会返回504, 此时对于php-fpm而言还会继续执行下去,直到执行完成。

<?php

sleep(7);

echo 'hello world';

error_log("hello", 3, "/tmp/hello.log");

?>

vi php-fpm.d/www.conf
request_terminate_timeout = 30s

vi nginx.conf
fastcgi_read_timeout         5s;


504 Gateway Time-out
nginx

"123.115.119.90" "up.levoo.com" "-" "[30/Nov/2018:23:52:04 +0800]" "GET /hello.php HTTP/1.1" "504" "562" "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36" "5.005" "5.005"
2018/11/30 23:52:0


==============================================================================================
499, Client Closed Request, 客户端主动断开连接。
是指一次http请求在客户端指定的时间内没有返回响应,此时,客户端会主动断开连接,此时表象为客户端无响应返回,而nginx的日志中会status code 为499。

此状态码在浏览器请求时几乎不可见,因为浏览器默认的超时时间会很长。多见于服务之间的调用,在业务架构中常常会分层设计,拆分为不同的子系统或者微服务,这样系统之间就会常常通过http方式来请求,并且会设置每次请求的超时时间,当请求在请求时间内所调用的上游服务无返回,则会主动关闭连接,上游服务日志中会记录一条499。

php代码

<?php

sleep(7);

echo 'hello world';

error_log("hello", 3, "/tmp/hello.log");

?>
php-fpm.conf配置:

request_terminate_timeout=30
nginx配置:

fastcgi_read_timeout 5;
我们在linux终端使用curl命令来请求,-m 表示超时时间,单位为秒

curl -i -m 3 http://127.0.0.1/hello.php
返回为:

curl: (28) Operation timed out after 3004 milliseconds with 0 bytes received
nginx的access日志的code为499,如下:

"HEAD /hello.php HTTP/1.1" 499 0


#curl -I -m 3 http://up.levoo.com/hello.php
curl: (28) Operation timed out after 3022 milliseconds with 0 bytes received
Nginx日志:
"47.94.88.237" "up.levoo.com" "-" "[30/Nov/2018:23:55:38 +0800]" "GET /hello.php HTTP/1.1" "499" "0" "-" "curl/7.55.1" "2.888" "-"

==============================================================================================
500
500, Internal Server Error , 服务器内部错误,服务器遇到了一个未曾预料的状况,导致了它无法完成对请求的处理。

日常开发中500错误几乎都是由于php脚本语法出现错误导致php-fpm无法正常执行。

复现路径
php代码:

<?php
echo 'hello '
echo ' world';
?>
由于php代码语法错误,php-fpm执行失败,然后告诉nginx这一结果,nginx则返回500。
该网页无法正常运作 up.levoo.com 目前无法处理此请求。
HTTP ERROR 500

Nginx错误日志:
"123.115.119.90" "up.levoo.com" "-" "[30/Nov/2018:23:57:42 +0800]" "GET /hello.php HTTP/1.1" "500" "5" "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36" "0.022" "0.022"

php错误日志:
hello.php on line 3
vim ~/.zshrc
# export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=$HOME/.irdcops/shell/tools/location.jackxiang.com:$PATH
export PATH=$HOME/.irdcops/shell/tools/ippbcopy.jackxiang.com:$PATH

Mac终端被自己玩“坏”了,登陆默认是-bash-3.2$,一些命令无法使用,现在记录恢复初始化    [username(你的账户名)@主机名 ~] $   解决的办法。
工具/原料
Mac
终端
方法/步骤1
终端输入以下命令:

export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin

之后输入

cd ~/

3、先输入

touch .bash_profile

之后输入

open .bash_profile

打开文件之后,在文件的最后一行添加

export PS1='[\u@\h \w]\$'



之后按住保存该文件关闭

输入下列命令,刷新终端,ok~

source .bash_profile

补充:关于更改主机名和共享名

主机名

sudo scutil --set HostName rainbird-desk

共享名

sudo scutil --set ComputerName newName


来自:https://jingyan.baidu.com/article/c74d6000c277e80f6a595d8c.html



二)MAC 设置环境变量PATH 和 查看PATH
理论篇
Mac系统的环境变量,加载顺序为:
/etc/profile /etc/paths ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc

#中间用冒号隔开
export PATH=$PATH:<PATH 1>:<PATH 2>:<PATH 3>:------:<PATH N>

实践主要是:ckubectlcmd    ckubectlishow 两个快捷命令,如下:
$cat /Users/jackXiang/.bashrc |grep kube


$cat /Users/jackXiang/.bash_profile

参考自:https://www.jianshu.com/p/acb1f062a925
法一)直接PKG安装:
#pkg install git
Updating FreeBSD repository catalogue...
Fetching meta.txz: 100%    944 B   0.9kB/s    00:01    
Fetching packagesite.txz: 100%    6 MiB 118.7kB/s    00:57    
Processing entries: 100%
FreeBSD repository update completed. 32579 packages processed.
All repositories are up to date.
Updating database digests format: 100%
The following 15 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        git: 2.19.1
        p5-CGI: 4.40
        p5-HTML-Parser: 3.72
        p5-HTML-Tagset: 3.20_1
        perl5.24: 5.24.4
        p5-IO-Socket-SSL: 2.059

法二)Ports源码安装:

cd /usr/ports/devel/git
sudo make install clean BATCH="yes"

https://www.digitalocean.com/community/tutorials/how-to-install-git-on-freebsd-11-0






sudo pkg update
Updating FreeBSD repository catalogue...
pkg: Repository FreeBSD has a wrong packagesite, need to re-create database

Fetching meta.conf: 100%    163 B   0.2kB/s    00:01    
Fetching packagesite.pkg: 100%    7 MiB  73.4kB/s    01:41    
Processing entries:   0%
Newer FreeBSD version for package zziplib:
To ignore this error set IGNORE_OSVERSION=yes
- package: 1302001
- running kernel: 1300139
Ignore the mismatch and continue? [y/N]: pkg: repository FreeBSD contains packages for wrong OS version: FreeBSD:13:amd64
Processing entries: 100%
Unable to update repository FreeBSD
Error updating repositories!
========================================================

根据错误信息,您遇到了一个由于系统版本不匹配而导致的问题。您的系统内核版本是`1300139`,而存储库中的软件包适用于版本`1302001`。以下是解决此问题的步骤:

1. **确认系统版本:**
   使用以下命令确认您的系统版本:

    ```bash
    uname -a
    ```

   如果输出的版本与错误中提到的不匹配,您可能需要更新系统。

2. **更新系统:**
   如果系统版本不匹配,尝试更新系统以匹配存储库中的软件包版本。使用以下命令:

    ```bash
    freebsd-update fetch install
    ```

   这将尝试将您的系统更新到最新的稳定版本。

3. **更新软件包数据库:**
   更新软件包数据库,以确保它与新的系统版本兼容:

    ```bash
    sudo pkg update
    ```

   如果这仍然失败,您可能需要重新创建软件包数据库。

4. **重新创建软件包数据库:**
   执行以下命令来重新创建软件包数据库:

    ```bash
    sudo pkg bootstrap -f
    ```

   然后再次运行更新命令:

    ```bash
    sudo pkg update
    ```

   现在,您应该能够更新软件包并安装Git。

请注意,由于系统版本不匹配可能会导致其他依赖关系问题,如果遇到其他错误,请根据错误消息逐个解决。如果有其他问题或需要更多帮助,请告诉我。
问题: sh: zip: not found

Port安装:
cd /usr/ports/archivers/zip/ && make install clean

安装后位置: /usr/local/bin/zip
#systemctl stop slapd
Error getting authority: Error initializing authority: Could not connect: Connection refused (g-io-error-quark, 39)
解决这个问题:
第一步)主要是重装  polkit,然后重启。
#rpm -qa|grep polkit
polkit-0.112-14.el7.x86_64
polkit-pkla-compat-0.1-4.el7.x86_64
来自:https://blog.csdn.net/wuyezhiyu/article/details/82905661

弟二步)#systemctl start dbus.service
Error getting authority: Error initializing authority: Could not connect: Connection refused (g-io-error-quark, 39)

#ps -ef|grep dbus
root     31670     1  0 09:38 ?        00:00:00 [dbus-daemon] <defunct>

#systemctl list-unit-files|grep dbus.service        #查看systemd管理的所有单元
dbus.service                 static  
systemctl enable dubs.service        

access("/etc/systemd/system/dubs.service", F_OK) = -1 ENOENT (No such file or directory)
access("/run/systemd/system/dubs.service", F_OK) = -1 ENOENT (No such file or directory)
access("/usr/local/lib/systemd/system/dubs.service", F_OK) = -1 ENOENT (No such file or directory)
access("/usr/lib/systemd/system/dubs.service", F_OK) = -1 ENOENT (No such file or directory)
access("/etc/rc.d/init.d/dubs", F_OK)   = -1 ENOENT (No such file or directory)
"static"  尚未被启用,并且单元文件的 "[Install]" 小节中没有可用于 enable 命令的选项
"disabled"  尚未被启用,但是单元文件的 "[Install]" 小节中存在可用于 enable 命令的选项
"enabled"  已经通过 /etc/systemd/system/ 目录下的 Alias= 别名、 .wants/ 或 .requires/ 软连接被永久启用

来自:https://mellowhost.com/billing/index.php?rp=/knowledgebase/71/Error-getting-authority-Error-initializing-authority-Could-not-connect-Connection-refused-g-io-error-quark-39.html


Error getting authority: Error initializing authority: Could not connect: Connection refused (g-io-error-quark, 39)
systemctl stop slapd
Error getting authority: Error initializing authority: Could not connect: Connection refused (g-io-error-quark, 39)

在使用centos7.4 安装服务的时候报错:

Error getting authority: Error initializing authority: Error calling StartServiceByName for org.freedesktop.PolicyKit1: Timeout was reached (g-io-error-quark, 24)
解决方案:


ps -ef |grep polkit

再安装:
pyum reinstall polkit

再重启
reboot

就可以解决

来自:http://www.cnblogs.com/flyfish2012/p/9527810.html
背景:在Docker打包PHP时发现这个命令,于是查了一下。
strip命令用于脱掉文件的衣服, 文件会变小, 其中的符号信息会失去。 那这个strip有什么

用呢? 很有用的! 原来的a.out比较大, 可以执行。 在strip之后, 文件变小了, 也是可以执行, 这就节省了很多空间.

      其实, strip不仅仅可以针对可执行文件, 还能针对目标文件和动态库等. 在实际的开发中, 经常需要对动态库.so进行strip操作, 减少占地空间。 而在调试的时候(比如用addr2line), 就需要符号了。 因此, 通常的做法是: strip前的库用来调试, strip后的库用来实际发布, 他们两者有对应关系。 一旦发布的strip后的库出了问题, 就可以找对应的未strip的库来定位。

      例如某个动态库strip前是50M左右, strip后是20M左右, 可见, 脱脱衣服还是有明显好处的。

      我们在调试过程中, 经常涉及到上传库, 库太大时, 很耗费传输时间, 所以还是先用strip来处理一下比较好。
---------------------
/data/codesdev/testdemo/c/strip]
#tree -l
.
├── strip
└── strip.c

#cat strip.c
#include <stdio.h>  

void main()  
{  
    printf("strip\n");
}

#make strip
cc     strip.c   -o strip

#ls -l strip
-rwxr-xr-x 1 root root 8440 11月  1 17:26 strip

#/usr/bin/file strip
strip: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=ec884c4b45d605867f9319a6d5b3acaea1866798, not stripped

#nm strip
000000000060102c B __bss_start
000000000060102c b completed.6355
0000000000601028 D __data_start
0000000000601028 W data_start
0000000000400460 t deregister_tm_clones

#strip strip

#ls -l strip  #File Size变小
-rwxr-xr-x 1 root root 6296 11月  1 17:28 strip

#file strip
strip: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=ec884c4b45d605867f9319a6d5b3acaea1866798, stripped

#nm strip
nm: strip:无符号


来自:https://blog.csdn.net/qq_37858386/article/details/78559490
实践Ok,如下:

Autofill插件下载:
https://jingyan.baidu.com/article/e73e26c0992c4524adb6a701.html

Chrome浏览器如何自动填写表单提高工作效率?
https://pan.baidu.com/s/1bp2J1pX?errno=0&errmsg=Auth%20Login%20Sucess&&bduss=&ssnerror=0&traceid=
背景:过滤从前端textarea里传过来的字符串里有空行。
如:
1212
2121

1222
测试了一下发现写入文件是:
#cat input.txt
1212
2121

1222
出现多了两个竖线的原因是上面这个空行:
grep -Erin "1212|2121||1222"

那么,想去掉这个串里的空的行,怎么办?



来自:https://zhidao.baidu.com/question/808190628151611092.html

想要的结果是,而不是多一个||,如下:
grep -Erin "1212|2121||1222"
想要:
grep -Erin "1212|2121|1222"





PHP实现ASCII码与字符串相互转换的方法,主要想看换行里是\n还是\r\n,当然也可以在PHP写入文件后sz下来用FlexHEX编辑器看:
31 32 31 32 0A 32 31 32 31 0A 0A 31 32 32 32  <===1212
2121

1222

上面的0A就是10,也就是\n,如下:
php > echo ord(1);
49
php > echo ord(2);
50
php > echo ord(\n);
PHP Fatal error:  Undefined constant 'n' in php shell code on line 1
php > echo ord("\n");
10
用PHP看:

php /tmp/ascii.php
<xmp>&#49;&#50;&#49;&#50;&#10;&#50;&#49;&#50;&#49;&#10;&#10;&#49;&#50;&#50;&#50;</xmp>1212
2121

1222

所以,结论是这个\r其实是没有必要的,下面这一行就行,当然平台可能是\r\n于是得加上:
//$leftContents = preg_replace('/[\r\n]+/', "\n", $leftContents);
$leftContents = preg_replace('/[\n]+/', "\n", $leftContents);    

正则的意思是无论是\r\n\r\n还是\n\n都能被替换为一个斜杠n ,\n:
php > $contents = preg_replace('/\n\n/', "\r\n\r\n", $contents);  
php > echo $contents;
1212
2121

1222
php > $str = preg_replace('/[\r\n]+/', "\n", $contents);
php > echo $str;
1212
2121
1222

一个Window的\r\n和一个unix的\n,这个正则一样能替换,反之一样:
php > $contents = preg_replace('/\n\n/', "\r\n\n", $contents);    
php > echo $contents;
1212
2121

1222
php > $str = preg_replace('/[\r\n]+/', "\n", $contents);
php > echo $str;
1212
2121
1222

反之亦然:
php > $contents=file_get_contents("/tmp/input.txt");
php > echo $contents;
1212
2121

1222
php > $contents = preg_replace('/\n\n/', "\n\r\n", $contents);  
php > echo $contents;
1212
2121

1222
php > $str = preg_replace('/[\r\n]+/', "\n", $contents);
php > echo $str;
1212
2121
1222

对于这个+号,查了一下正则:
man awk
/Regular Expressions

. 任意字符
问家兴:(问加星)
?   0或1次
+  1次或多次    #man awk  Regular Expressions , r+         matches one or more r's.
*   0次或N次

也就是一次或多次,对于\r\n就像[a-z0-9]一个道理,\r和\n分别表示一个字符,可一块,总之一次或多次,于是:
\r\n\r\n  ,\n\n,\r\n\n,\n\r\n都能匹配,长时间不写PHP快忘光了,嗨。

同时,网上还有法二先用换行去转成数组,再用数组里去掉空元素array_filter:
// 该函数把输入数组中的每个键值传给回调函数。如果回调函数返回true,则把输入数组中的当前键值返回结果数组中。数组键名保持不变。若无回调函数,则将TRUE的值返回,即可以使用它来过滤空元素
$arr = array(0, 1, 4, '',null, '0', 23);
$arr = array_filter($arr);// array(1=>1, 2=>4, '6'=>23) 下标不改变,使用array_values(),改变下标
1.去除空行



来自:https://www.cnblogs.com/chenqionghe/p/4293852.html


freebsd-update -r 11.2-RELEASE upgrade
/usr/sbin/freebsd-update install
中间有几次NTP的配置文件确认。
/usr/sbin/freebsd-update install
reboot


FreeBSD 11.2-RELEASE-p4 (GENERIC) #0: Thu Sep 27 08:16:24 UTC 2018
Welcome to jackxiang's Compute Service !

参考:https://blog.csdn.net/joyous/article/details/81990019


升级遇到的问题,出现openssl的动态链接库版本对不上。
最后一次构建FreeBSD镜像::
1)无法再次升级,原因是相关SSHD和Mysqld的动态链接libssl会有问题。

2)FreeBSD升级到11.3还会出sockstat -4l会报错。

3)即使到FreeBSD12.0后Mysql编译好的启动可能也有问题,由于旧的库可能还是涉及到libssl还是有问题。

最终,无法升级,做了一些域名应用快捷方面的优化以及完善了PHP扩展,得出这个版本是一个最后的ISO版本FreeBSD11.2。

pkg info -r security/openssl
openssl-1.0.2l,1:
        libarchive-3.3.1,1
        mysql80-client-8.0.0_3
        bind-tools-9.11.1P3
pkg auto remove
pkg upgrade -y
rm -rf /var/db/freebsd-update/files  #记得删掉。


一些其它命令:
> pkg-add -r openssh-portable
> cd /usr/ports / security / openssh&& make install clean


> portupgrade security / openssh-portable
> makeworld / buildworld过程的一部分
> freebsd-upgrade
cat a.txt
jack 1
tianjin 2
old5 3




sh read.sh
jack 1
tianjin 2
old5 3


加上模拟输出:
insert into t set name='xxx', id=N;

sh read.sh  
insert into t set name='jack',id=1;
insert into t set name='tianjin',id=2;
insert into t set name='old5',id=3;

行内有空格换行的原因:
如果输入文本每行中没有空格,则line在输入文本中按换行符分隔符循环取值.
如果输入文本中包括空格或制表符,则不是换行读取,line在输入文本中按空格分隔符或制表符或换行符特环取值.
可以通过把IFS设置为换行符来达到逐行读取的功能.
demo:
假设现需要读取如下的文件rollback_config.txt:
ROLLBACK_SERVICES:upserv  checkserv
ROLLBACK_VERSION:v1.1
使用   for line in `cat rollback_config.txt`; do echo "${line}"; done  读取的结果会是:
ROLLBACK_SERVICES:upserv
checkserv
ROLLBACK_VERSION:v1.1
显然不是我们想要的。

解决方法:
IFS_old=$IFS
IFS=$'\n'
for line in  `cat  rollback_config`;do
echo "$line"
done;
IFS=$IFS_old
这样一来就可以了!



IFS的默认值为:空白(包括:空格,制表符,换行符).

---------------------

本文来自 潼潼水势向江东 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/zhongjling/article/details/52859055?utm_source=copy

二)用AWK就很方便处理,如下,注意下单引号是三个单引号,中间那个被转义,才输出一个单引号     '\''  :

insert into t set name='jack',id=1;
insert into t set name='tianjin',id=2;
insert into t set name='old5',id=3;
对于变量可以把整个变量用花括号括起来,也可括一部分,如:
整个:{$name}
把$放外面:${name}
-----------------------------------------------------------------------------------
php 使用phpize 安装扩展readline , 安装后可以进入命令行交互模式:


Shell也一样:
1.CURL批量:

输出(注意那个双引号里加一个单引号引起来,输出单引号,还是那个双引号为匹配,里面单引号原样输出,这点得记住!):
/usr/bin/curl -I 'baidu.com'
/usr/bin/curl -I '360.cn'
/usr/bin/curl -I 'souhu.com'
/usr/bin/curl -I 'sina.com.cn'

for i in $(cat url.txt);do echo /usr/bin/curl -I "''$i'''";done;  #双引号里加一个单引号引起来,输出单引号,还是那个双引号为匹配
/usr/bin/curl -I ''baidu.com'''
/usr/bin/curl -I ''360.cn'''
/usr/bin/curl -I ''souhu.com'''
/usr/bin/curl -I ''sina.com.cn'''

Curl命令实战:

;done;    
curl: (6) Couldn't resolve host ''baidu.com''
curl: (6) Couldn't resolve host ''360.cn''
curl: (6) Couldn't resolve host ''souhu.com''
curl: (6) Couldn't resolve host ''sina.com.cn''

2.Nc批量:

nc -w 1 -z -v 10.71.182.175 80
nc -w 1 -z -v 192.168.111.43 80

for i in $(cat ip.txt);do  nc -w 1 -z -v $i 80;done;  
Connection to 10.71.182.175 80 port [tcp/http] succeeded!
Connection to 192.168.111.43 80 port [tcp/http] succeeded!
strings
ldd
autoconf
yum groupinstall "Development Tools"
sudo fstat -p 42477 | grep my.cnf 打开后关掉了,无法找到。
cat /usr/local/etc/rc.d/mysql-server |grep my.cnf
#                       ${mysql_confdir}/my.cnf if it exists.
if [ -f "${mysql_confdir}/my.cnf" ]; then
: ${mysql_optfile="${mysql_confdir}/my.cnf"}
elif [ -f "${mysql_dbdir}/my.cnf" ]; then
: ${mysql_optfile="${mysql_dbdir}/my.cnf"}

sh  -x /usr/local/etc/rc.d/mysql-server  start //于是直接-x找my.cnf
+ : /usr/local/etc/mysql
+ [ -f /usr/local/etc/mysql/my.cnf ]
+ [ -f /var/db/mysql/my.cnf ]
ls /etc/mysql/my.cnf /etc/my.cnf /usr/local/mysql/my.cnf /usr/local/etc/my.cnf /usr/local/etc/mysql/my.cnf /var/db/mysql/my.cnf


ps -eo pid,ppid,pgrp,session,comm --forest|less      # Linux上使用,Macbook: brew install pstree ,用pstree

ps -eo pid,ppid,pgrp,session,comm|grep -E '(Google\ Chrome|chrome)'

一)基础命令:删目录前看是否有进程打开了目录里的文件之lsof命令。
lsof -c abc 显示abc进程现在打开的文件
lsof -p  列出进程号为1234的进程所打开的文件
lsof -c java  #实践成功
lsof  -p  51640  #实践成功
lsof -g gid 显示归属gid的进程情况
lsof -g 0|grep zcms-0103
lsof  app-2020-08-05.log    #lsof abc.txt 显示开启文件abc.txt的进程
lsof  -d 4 #lsof -d 4 显示使用fd为4的进程,每个进程PID里都是从0,1,2,3,4开始的,出来的有4的所有进程列表。
lsof abc.txt 显示开启文件abc.txt的进程
来自:https://blog.csdn.net/weixin_34019929/article/details/92364579

二)常用想删目录时查看进程是否打开并在访问:
lsof +d /usr/local/ 显示目录下被进程开启的文件
lsof +D /usr/local/ 同上,但是会搜索目录下的目录,时间较长

lsof +d /data/www/zcms3x/zcms-0103
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
oosplash  49169 root  cwd    DIR 253,17     4096 5245406 /data/www/zcms3x/zcms-0103
soffice.b 49188 root  cwd    DIR 253,17     4096 5245406 /data/www/zcms3x/zcms-0103

lsof +D /data/www/zcms3x/zcms-0103
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
oosplash  49169 root  cwd    DIR 253,17     4096 5245406 /data/www/zcms3x/zcms-0103
soffice.b 49188 root  cwd    DIR 253,17     4096 5245406 /data/www/zcms3x/zcms-0103


kubectl exec stress-pod -- ps -o "rss,vsz,comm"|grep -v VSZ
2576 6256 stress-ng
3628 6900 stress-ng-cpu
  64 6256 stress-ng-vm
135m 262m stress-ng-vm
   4 1504 ps

rss: 物理
vsz: 虚拟
VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)

背景:在多进程时,用那个叫物理内存、虚拟内存的,怎么看?https://blog.csdn.net/i_am_jojo/article/details/7862362

ps -eo pid,ppid,gid,sid,tty,cmd --forest|less


  -e     Select all processes.  Identical to -A.
  -o format
              User-defined format.  format is a single argument in the form of a blank-separated or comma-separated
              list, which offers a way to specify individual output columns.  The recognized keywords are described
              in the STANDARD FORMAT SPECIFIERS section below.  Headers may be renamed (ps -o pid,ruser=RealUser -o
              comm=Command) as desired.  If all column headers are empty (ps -o pid= -o comm=) then the header line
              will not be output.  Column width will increase as needed for wide headers; this may be used to widen
              up columns such as WCHAN (ps -o pid,wchan=WIDE-WCHAN-COLUMN -o comm).  Explicit width control (ps opid,
              wchan:42,cmd) is offered too.  The behavior of ps -o pid=X,comm=Y varies with personality; output may
              be one column named "X,comm=Y" or two columns named "X" and "Y".  Use multiple -o options when in
              doubt.  Use the PS_FORMAT environment variable to specify a default as desired; DefSysV and DefBSD are
              macros that may be used to choose the default UNIX or BSD columns.

       -C cmdlist
              Select by command name.  This selects the processes whose executable name is given in cmdlist.
       --forest
              ASCII art process tree.

#ps -eo 'pid,ppid,gid,sid,tty,cmd' |grep Easy
26721 62388     0 62388 pts/4    EasySwoole
26722 26721     0 62388 pts/4    EasySwoole
26744 26722     0 62388 pts/4    EasySwoole.Crontab
31311 26722     0 62388 pts/4    EasySwoole.Worker.0
31312 26722     0 62388 pts/4    EasySwoole.Worker.1
31313 26722     0 62388 pts/4    EasySwoole.Worker.2
31314 26722     0 62388 pts/4    EasySwoole.Worker.3
31315 26722     0 62388 pts/4    EasySwoole.Worker.4
31316 26722     0 62388 pts/4    EasySwoole.Worker.5
31317 26722     0 62388 pts/4    EasySwoole.Worker.6
31318 26722     0 62388 pts/4    EasySwoole.Worker.7
31319 26722     0 62388 pts/4    EasySwoole.TaskWorker.8
31320 26722     0 62388 pts/4    EasySwoole.TaskWorker.9
31321 26722     0 62388 pts/4    EasySwoole.TaskWorker.10
31322 26722     0 62388 pts/4    EasySwoole.TaskWorker.11
31323 26722     0 62388 pts/4    EasySwoole.TaskWorker.12
31324 26722     0 62388 pts/4    EasySwoole.TaskWorker.13
31325 26722     0 62388 pts/4    EasySwoole.TaskWorker.14
31326 26722     0 62388 pts/4    EasySwoole.TaskWorker.15

对Crontab进行查看:
lsof -nPp 26744|grep swoole.log
php     26744 root   11u      REG              253,0  39874179 100744037 /data/logs/php/swoole.lo

#lsof -nPp 26721 |grep LISTEN
php     26721 root    3u     IPv4             763966       0t0       TCP *:8080 (LISTEN)
php     26721 root   10u     IPv4             762762       0t0       TCP 127.0.0.1:9000 (LISTEN)


26721 62388     0 62388 pts/4         \_ EasySwoole
26722 26721     0 62388 pts/4             \_ EasySwoole
26742 26722     0 62388 pts/4                 \_ HotReload
26743 26722     0 62388 pts/4                 \_ KafkaAddFormId
26744 26722     0 62388 pts/4                 \_ EasySwoole.Crontab
31311 26722     0 62388 pts/4                 \_ EasySwoole.Worker.0
31312 26722     0 62388 pts/4                 \_ EasySwoole.Worker.1
31313 26722     0 62388 pts/4                 \_ EasySwoole.Worker.2
31314 26722     0 62388 pts/4                 \_ EasySwoole.Worker.3
31315 26722     0 62388 pts/4                 \_ EasySwoole.Worker.4
31316 26722     0 62388 pts/4                 \_ EasySwoole.Worker.5
31317 26722     0 62388 pts/4                 \_ EasySwoole.Worker.6
31318 26722     0 62388 pts/4                 \_ EasySwoole.Worker.7
31319 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.8
31320 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.9
31321 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.10
31322 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.11
31323 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.12
31324 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.13
31325 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.14
31326 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.15

ps --headers -eo pid,ppid,GID,tty,sid,vsz,rss,cmd -C EasySwoole


To see every process with a user-defined format:
          ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm

Print only the process IDs of syslogd:
          ps -C syslogd -o pid=

相查看树,能看到进程的继承关系:
ps -eo 'pid,ppid,vsz,rss,cmd' --forest
3078  1214  48620  3032  \_ sshd: xiangdong [priv]
3084  3078  48752  1680      \_ sshd: xiangdong@pts/0,pts/1,pts/2
3085  3084 108352  1788          \_ -bash
3644  3085 189592  2940          |   \_ sudo su -
3645  3644 163756  1964          |       \_ su -
3646  3645 108476  1908          |           \_ -bash
5416  3646 108412  1200          |               \_ ps -eo pid,ppid,vsz,rss,cmd --forest
5417  3646 105460   816          |               \_ less

1481     1  55604  1460 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
1484  1481  76816 22864  \_ nginx: worker process                                          
1485  1481  76816 22936  \_ nginx: worker process                                          
1486  1481  76816 22936  \_ nginx: worker process                                          
1487  1481  76816 22936  \_ nginx: worker process  


cat pod-test.yml    



PHP连接未释放之lsof -d 5|grep 2654实现反debug程序PID里的fd对应的tcp连接句柄:
原文,以下是学习到的点:php curl连接未释放,strace结果:poll([{fd=5, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 1000) = 0 (Timeout)
https://www.jianshu.com/p/8a247cae629a
Nc服务端:
[root@golang_server_10_10_0_44:/usr/local/src/go-sftp]
#nc -l 1234
GET / HTTP/1.1
User-Agent: curl/7.29.0
Host: 10.10.0.44:1234
Accept: */*

Client连接端:
[root@swoole_server_10_10_0_45:~]
#ps -ef|grep curl
root      9055  9012  0 03:57 pts/1    00:00:00 curl 10.10.0.44:1234
#curl 10.10.0.44:1234
#ls /proc/9055/fd
0  1  2  3

[root@swoole_server_10_10_0_45:~]
#lsof  -d 3|grep 9055
curl       9055      root    3u     IPv4           23202662      0t0       TCP wx.levoo.com:41490->localhost:search-agent (ESTABLISHED)

#strace -f -p 9055
strace: Process 9055 attached
restart_syscall(<... resuming interrupted poll ...>) = 0
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000


设置超时后呢?
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 987)   = 0 (Timeout)会提示:
curl: (28) Operation timed out after 20001 milliseconds with 0 out of -1 bytes received


#curl 10.10.0.44:1234 --connect-timeout 10 -m 20
curl: (28) Operation timed out after 20001 milliseconds with 0 out of -1 bytes received



man lsof
       -d s     specifies a list of file descriptors (FDs) to exclude from or include in the output listing.  The file descriptors are  specified  in
                the comma-separated set s - e.g., ``cwd,1,3'', ``^6,^2''.  (There should be no spaces in the set.)
lsof  -nPp 57700|grep cwd
nginx   57700 root  cwd    DIR             253,16     4096   47185921 /data/www
lsof  -nPp 33441|grep cwd
java    33441 root  cwd    DIR              104,3     4096  2757893 /data/xxxxrsync
ls /proc/33441/cwd/  #/data/xxxxrsync的目录的东西
函数说明:chdir()用户将当前的工作目录改变成以参数路径所指的目录。


连接超时时间用 --connect-timeout 参数来指定,数据传输的最大允许时间用 -m 参数来指定。

一直Poll的解决办法:php curl调用时设置超时
libcurl中同一时候封装了select以及poll这两种I/O机制。
代码中使用宏HAVE_POLL_FINE对这两者进行分离。假设定义了这个宏,则使用poll,否则使用select。
libcurl中同一时候封装了select以及poll这两种I/O机制。
代码中使用宏HAVE_POLL_FINE对这两者进行分离。假设定义了这个宏,则使用poll,否则使用select。
这两者的使用代码都位于函数curl_poll()中,而此函数定义在文件lib/select.c中。我看默认是poll的模式。

Curl不设置超时,对nc -l 1234进行访问会一直不退出的,一直 poll的,刚才实践的确如此,一般都要加上超时参数,如:curl 10.10.0.44:1234 --connect-timeout 10 -m 20
来自:https://blog.csdn.net/weixin_30340745/article/details/98854529
执行一下命令安装以后就可以locate XXX了

yum install mlocate

sudo updatedb

locate  *.doc

实践如下:
零)用unset来撤销数组,可用unset array_name[i]来删除里面的元素:
declare -A DATABASES

# mail
DATABASES['10.70.62.5-3306']='postfix_mail'
用unset来撤销数组,可用unset array_name[i]来删除里面的元素
#cat  arrayunset.sh  

#sh  arrayunset.sh
echo bai manage postfix_mail



一)${#array_name[@]} 或者 ${#array_name[*]}都可以用来求数组的长度
#cat ping3times.sh  






#sh  arrayloop.sh
jerry
alice
david
wendy


二)${array_name[@]} 或者 ${array_name[*]} 都可以全部显示数组中的元素


#sh arraylist.sh
jerry
alice
david
wendy
jerry alice david wendy


来自:https://blog.csdn.net/Jerry_1126/article/details/52027539
在linux下搞软件开发的朋友, 几乎没有不知道strings命令的。我们先用man strings来看看:

strings - print the strings of printable characters in files.  

意思是, 打印文件中可打印的字符。  我来补充一下吧, 这个文件可以是文本文件(test.c), 可执行文件(test),  动态链接库(test.o), 静态链接库(test.a)


脱离代码地长篇大论而不去实际验证, 不是我的风格。 还是搞点代码下菜吧(代码存在test.c中):

cat test.c



我们来看看strings test.c的结果:
strings test.c


可以看到, 确实打印出了test.c中的很多字符。
下面, 我们对可执行文件用strings试试, 如下:
gcc test.c
strings a.out
/lib64/ld-linux-x86-64.so.2
__gmon_start__
libc.so.6
printf
__libc_start_main
GLIBC_2.2.5
fff.
fffff.
l$ L
t$(L
|$0H
oh, my dear, c isd

可以看到, 打印出了a.out中很多字符。
实际上, 如果有目标文件、静态库或动态库,, 也是可以用strings命令进行打印操作的。 我们来看看:
xxx.h文件:

xxx.c文件:
cat  xxx.c


然后, 我们来看看怎么制作静态、动态库吧(在后续博文中会继续详细介绍):
gcc -shared -fPIC -c xxx.c  #-fPI得加上,否则会报relocation R_X86_64_32 against `.rodata'
gcc -shared -fPIC -o libxxx.so xxx.o

问题:
gcc -shared -fPIC -o libxxx.so xxx.o
/usr/bin/ld: xxx.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
解决办法:
gcc默认没加-fPIC参数,得手工加上即可。
strings xxx.o
rainy days

strings libxxx.a


strings libxxx.so

trings命令很简单, 看起来好像没什么, 但实际有很多用途。 下面, 我来举一个例子。  在大型的软件开发中, 假设有100个.c/.cpp文件, 这个.cpp文件最终生成10个.so库, 那么怎样才能快速知道某个.c/.cpp文件编译到那个.so库中去了呢? 当然, 你可能要说, 看makefile不就知道了。 对, 看makefile肯定可以, 但如下方法更好, 直接用命令:
      strings -f "*.so" | grep "xxxxxx"

      如果还不明白, 那就就以上面的小程序为例为说明, 不过, 此处我们考虑所有的文件, 如下:

strings -f * | grep "my dear"
a.out: oh, my dear, c isd
test.c:         printf("oh, my dear, c isd\n", c);

可以看到, 源文件test.c和可执行文件中皆有"my dear"串, 一下子就找到了对应的文件,清楚了吧。如果某.c/.cpp文件编译进了.so库, 那么,strings -f * | grep "my dear"必定可以找到对应的.so文件, 其中"my dear"为该.c/.cpp文件中的某个日志串(比如以printf为打印)。

来自:https://blog.csdn.net/stpeace/article/details/46641069
分页: 17/339 第一页 上页 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 下页 最后页 [ 显示模式: 摘要 | 列表 ]