502 Bad Gateway

解决过程:第一次遇到修改 php  问题解决 memory_limit

后面再次遇到502 报错:编辑 /etc/security/limits.conf

加入:

* soft noproc 11000
* hard noproc 11000
* soft nofile 32768
* hard nofile 65535

然后重启服务器 问题依旧会出现,继续排查

原来是我后台执行命令 php -v 就会把php-fpm全干了,果断把xcache 卸载了

用dmidecode命令查看内存型号

#dmidecode -t memory
结果如下:
我这台服务器是2个单根4G的内存,最大支持384G,12个插槽

# dmidecode 3.1
Getting SMBIOS data from sysfs.
SMBIOS 2.7 present.

Handle 0x1000, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: Multi-bit ECC
Maximum Capacity: 384 GB  (最大支持384G)
Error Information Handle: Not Provided
Number Of Devices: 12   (12个槽 不少吧)

Handle 0x1100, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: 4096 MB    (4G 的)
Form Factor: DIMM
Set: 1
Locator: DIMM_A1
Bank Locator: Not Specified
Type: DDR3 (型号)
Type Detail: Synchronous Registered (Buffered)
Speed: 1333 MT/s  (频率)
Manufacturer: 00AD00B300AD
Serial Number: 20B1991B
Asset Tag: 01093461
Part Number: HMT151R7BFR4C-H9
Rank: 2
Configured Clock Speed: 1067 MT/s

Handle 0x1101, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: No Module Installed
Form Factor: DIMM
Set: 1
Locator: DIMM_A2
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: Unknown
Manufacturer:
Serial Number:
Asset Tag:
Part Number:
Rank: Unknown
Configured Clock Speed: Unknown

Handle 0x1102, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: No Module Installed
Form Factor: DIMM
Set: 2
Locator: DIMM_A3
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: Unknown
Manufacturer:
Serial Number:
Asset Tag:
Part Number:
Rank: Unknown
Configured Clock Speed: Unknown

Handle 0x1103, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: No Module Installed
Form Factor: DIMM
Set: 2
Locator: DIMM_A4
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: Unknown
Manufacturer:
Serial Number:
Asset Tag:
Part Number:
Rank: Unknown
Configured Clock Speed: Unknown

Handle 0x1104, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: No Module Installed
Form Factor: DIMM
Set: 3
Locator: DIMM_A5
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: Unknown
Manufacturer:
Serial Number:
Asset Tag:
Part Number:
Rank: Unknown
Configured Clock Speed: Unknown

Handle 0x1105, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: No Module Installed
Form Factor: DIMM
Set: 3
Locator: DIMM_A6
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: Unknown
Manufacturer:
Serial Number:
Asset Tag:
Part Number:
Rank: Unknown
Configured Clock Speed: Unknown

Handle 0x1106, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: 4096 MB
Form Factor: DIMM
Set: 4
Locator: DIMM_B1
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous Registered (Buffered)
Speed: 1333 MT/s
Manufacturer: 00AD00B300AD
Serial Number: 24303F6E
Asset Tag: 01093461
Part Number: HMT151R7BFR4C-H9
Rank: 2
Configured Clock Speed: 1067 MT/s

Handle 0x1107, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: No Module Installed
Form Factor: DIMM
Set: 4
Locator: DIMM_B2
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: Unknown
Manufacturer:
Serial Number:
Asset Tag:
Part Number:
Rank: Unknown
Configured Clock Speed: Unknown

Handle 0x1108, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: No Module Installed
Form Factor: DIMM
Set: 5
Locator: DIMM_B3
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: Unknown
Manufacturer:
Serial Number:
Asset Tag:
Part Number:
Rank: Unknown
Configured Clock Speed: Unknown

Handle 0x1109, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: No Module Installed
Form Factor: DIMM
Set: 5
Locator: DIMM_B4
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: Unknown
Manufacturer:
Serial Number:
Asset Tag:
Part Number:
Rank: Unknown
Configured Clock Speed: Unknown

Handle 0x110A, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: No Module Installed
Form Factor: DIMM
Set: 6
Locator: DIMM_B5
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: Unknown
Manufacturer:
Serial Number:
Asset Tag:
Part Number:
Rank: Unknown
Configured Clock Speed: Unknown

Handle 0x110B, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: No Module Installed
Form Factor: DIMM
Set: 6
Locator: DIMM_B6
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: Unknown
Manufacturer:
Serial Number:
Asset Tag:
Part Number:
Rank: Unknown
Configured Clock Speed: Unknown

1.内存条数:
dmidecode|grep -P -A5 “Memory\s+Device”|grep Size|grep -v Range

2.内存最大容量:
dmidecode|grep -P ‘Maximum\s+Capacity’

3.内存频率:
dmidecode|grep -A16 “Memory Device”|grep Speed

Linux下统计文件个数和目录个数

统计当前文件夹下文件的个数,包括子文件夹里的

ls -lR|grep “^-“|wc -l
统计文件夹下目录的个数,包括子文件夹里的

ls -lR|grep “^d”|wc -l
统计当前文件夹下文件的个数

ls -l |grep “^-“|wc -l
统计当前文件夹下目录的个数

ls -l |grep “^d”|wc -l
附:
统计输出信息的行数

wc -l
将长列表输出信息过滤一部分,只保留一般文件,如果只保留目录就是 ^d

grep “^-“

grep常用方法

1.将/etc/passwd,有出现 root 的行取出来
# grep root /etc/passwd

2.将/etc/passwd,有出现 root 的行取出来,同时显示这些行在/etc/passwd的行号
# grep -n root /etc/passwd

3.将/etc/passwd,将没有出现 root 的行取出来
# grep -v root /etc/passwd

4.将/etc/passwd,将没有出现 root 和nologin的行取出来
# grep -v root /etc/passwd | grep -v nologin

5.用dmesg 列出核心信息,再以 grep 找出内含 eth 那行,要将捉到的关键字显色,且加上行号来表示:
[root@www ~]# dmesg | grep -n –color=auto ‘eth’

6.用dmesg 列出核心信息,再以 grep 找出内含 eth 那行,在关键字所在行的前两行与后三行也一起捉出来显示
[root@www ~]# dmesg | grep -n -A3 -B2 –color=auto ‘eth’

7.根据文件内容递归查找目录
# grep ‘maxianwei.cn’ *      #在当前目录搜索带’maxianwei.cn’行的文件
# grep -r ‘maxianwei.cn’ *     #在当前目录及其子目录下搜索”行的文件
# grep -l -r ‘maxianwei.cn’ *    #在当前目录及其子目录下搜索’maxianwei.cn’行的文件,但是不显示匹配的行,只显示匹配的文件

具体grep相关参数可以参考:https://www.runoob.com/linux/linux-comm-grep.html

linux sed 批量替换字符串

sed是一种流编编器,它是文本处理中非常中的工具,能够完美的配合正则表达式便用,功物能不同凡响。详细的功能网上很多,这里就不多说了,项目中我要批量替换静态文件的一个域名具体操作如下:

命令如下:

sed -i "s/原字符串/新字符串/g" `grep 原字符串 -rl 所在目录`

例如:我要把 www.maixianwei.cn 替换为 cdn.maxianwei.cn,执行命令:

sed -i "s/www.maxianwei.cn/cnd.maxianwei.cn/g" `grep www.maxianwei.cn -rl /www`

-i 表示inplace edit,就地修改文件

-r 表示搜索子目录

-l 表示输出匹配的文件名

修改前,要注意备份文件。

如果文件太多 可以分批进行 比如:

[root@localhost html]# sed -i “s/maxianwei.cn\/upload/maxianwei.c\/upload/g” `grep admin.maxianwei.cn -rl ./12*.html`