Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux常用命令 #8

Open
clms2 opened this issue Jul 24, 2018 · 0 comments
Open

linux常用命令 #8

clms2 opened this issue Jul 24, 2018 · 0 comments

Comments

@clms2
Copy link
Owner

clms2 commented Jul 24, 2018

  1. 跟踪所有php-fpm进程,ps -ef|grep php-fpm|awk '{print " -p " $2" -e trace=file -tt -T -v -f -s 10000 -o /a/strace_"$2".log"}'|xargs strace ; 跟踪指定进程:strace -o output.txt -T -tt -e trace=all -p 33923
  2. 重启php-fpm:service php-fpm restart/etc/init.d/php-fpm {start|stop|force-quit|restart|reload|status}
  3. 删除指定目录下的文件和文件夹:rm -rf xxx/*
  4. 删除.svn目录:find . -type d -name ".svn"|xargs rm -rf
  5. 在windows下上传的shell linux报错bad interpreter: set ff=unix即可。
  6. 服务器之间内网同步文件: scp -r web/ 10.22.11.1:/vdb1/, -r会把包括文件夹在内一起复制过去
  7. 导出error log指定时间段的日志:sed -n '/2018\/10\/02/,/2018\/10\/02/p' /vdb1/nginx_log/error_log > /root/081002.txt 也可以找包含某个具体时间段的数据:sed -n -r '/2021\/12\/29 00:0/p' ./xx.cn.log >22.txt
  8. 平滑重启php-fpm:ps -aux | grep php-fpm , kill -SIGUSR2 process_id
  9. 查看目录的文件夹大小情况: du -sh *
  10. 同步某个文件夹下的文件到其他所有文件夹:
#!/bin/bash

for dir in $(ls ./ -F)
do
	if [[ -d $dir ]] && [[ $dir != "syncDir/" ]];then
		cp -r syncDir/* $dir
	fi
done 
rm syncDir/* -rf
  1. ulimit -n永久设置:
    vi /etc/pam.d/login,添加 session required pam_limits.so
    vi /etc/security/limits.conf添加:
* soft nproc 1048576
* hard nproc 1048576
* soft nofile 1048576
* hard nofile 1048576
vi /etc/rc.local, 添加  ulimit -n 1048576

nginx 需要额外修改:vi /etc/systemd/system/nginx.service 再service下添加 LimitNOFILE=100000

  1. crontab在线测试工具
  2. find ./ -maxdepth 2 -name .env |xargs grep "xxx.com"
  3. ps aux|head -n1;ps aux|grep -v PID|sort -nr -k6|head -n100内存占用量前100
  4. 删除指定名称的所有进程:ps -ef | grep firefox | grep -v grep | cut -c 9-15 | xargs kill -s 9
  5. 定时任务防止重复运行:*/3 * * * * /usr/bin/flock -w 0 /data/cron-minute-lock.lock /data/cron-minute.sh
  6. 匹配vhost所有站:grep -r "server_name" ./ |cut -d " " -f 2,3,4,5,6,7,8 > site.txt
  7. 压缩文件夹:tar -czvf xxx.tar.gz xxx/
  8. nginx https配置
  9. 删除7天前的文件:find ./ -ctime +7 -name \*.xlsx | xargs rm -f
  10. sed正则替换(server_name后追加支持端口访问):sed -i -r "/.*server_name.*/s#(.*);#\1 127.0.0.1:${current_port};#" $dir

更多

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant