pupuk / blog

My New Blog. Record & Share. Focus on PHP, MySQL, Javascript and Golang.
MIT License
9 stars 2 forks source link

Linux 运维 命令行笔记 #7

Open pupuk opened 6 years ago

pupuk commented 6 years ago

1、Linux运行级别 who -r,或者 runlevel,一般是N3 参考

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.3 125500  3192 ?        Ss   Aug07   0:17 /usr/lib/systemd/systemd --switched-root --system --deserialize 22

注意Linux的启动顺序和机制 命令 init 0 = halt 命令 init 6 = reboot

0-停机(千万不要把initdefault设置为0) 1-单用户模式 2-多用户,没有NFS 3-完全多用户模式(标准的运行级) 4-没有用到 5-X11(xwindow) 6-重新启动(千万不要把initdefault设置为6)

pupuk commented 6 years ago

2、SElinux,在初装的系统中,可能经常会遇到权限不够的问题,很有可能就是因为Linux默认开启了SElinux。但是在大部分的云厂商和服务器运维中,经常关闭了SElinux。 查看SELinux状态 getenforce

关闭SELinux: setenforce 0 临时关闭 2、修改配置文件需要重启机器: 修改/etc/selinux/config 文件 将SELINUX=enforcing改为SELINUX=disabled 重启机器即可

pupuk commented 6 years ago

3、yum安装方式系列 yum update yum search OR yum search -C yum clean all yum makecache yum provides /usr/bin/ab #通过可执行文件找repo yum list installed |grep java

pupuk commented 6 years ago

4、权限管理 一般模式 UGO,user,group,other 增强的 ACL(Access Control List) 相关命令 getfacl setfacl

pupuk commented 6 years ago

5、find命令一些点,尽管很熟悉,但温故知新啊

找出2018-05-01之前的文件,并且删掉

find . ! -newermt '2018-05-01' -exec rm -f {} \; find . -type f -name *.log -mtime +180 -exec rm {} \;

https://blog.csdn.net/u011622226/article/details/44087373

pupuk commented 6 years ago

6、DIG常用命令 dig www.baidu.com dig +trace www.baidu.com dig -t soa www.baidu.com

pupuk commented 5 years ago

7、建议的 /etc/ssh/sshd_config配置

UseDNS no
AddressFamily inet
PermitRootLogin yes
SyslogFacility AUTHPRIV
PasswordAuthentication yes
pupuk commented 5 years ago

8、PING命令的 ping www.baidu.com -c 100

count Stop after sending count ECHO_REQUEST packets. With deadline option, ping waits for count ECHO_REPLY packets, until the timeout expires.

rrt = round trip time mdev = Mean Deviation

pupuk commented 4 years ago

让curl支持HTTP2

vim /etc/yum.repos.d/cityfan.repo
[cityfan]
name=cityfan
baseurl=http://www.city-fan.org/ftp/contrib/yum-repo/rhel7/x86_64/
enabled=1
gpgcheck=0

yum upgrade libcurl 或者 yum update curl

curl是新版本以后,可以不用参数--http2

curl -I https://www.tmall.com/

image

如果使用了HTTP2协议来传输数据,有2个重要的特征

pupuk commented 4 years ago

安装cheat代替tldr

一、 安装cheat二进制包 Install cheat binary(这个二进制包本质就是golang编译后的结果,不会产生依赖,直接就可以运行,这其实也算golang的优点)

cd /usr/bin/
wget https://github.com/cheat/cheat/releases/download/3.2.0/cheat-linux-amd64
mv cheat-linux-amd64 cheat && chmod +x cheat
cheat -v 
#如果有显示版本号,说明cheat二进制文件已经能运行了

二、 配置cheat的配置文件

#初始化配置文件
mkdir -p ~/.config/cheat && cheat --init > ~/.config/cheat/conf.yml

#为community目录下载cheatsheets文件(就是plain text文件)
mkdir -p ~/.dotfiles/cheat/ && cd ~/.dotfiles/cheat/
git clone https://github.com/cheat/cheatsheets community #需要这个cheat的配合,才能正常使用
mkdir -p ~/.dotfiles/cheat/work
mkdir -p ~/.dotfiles/cheat/personal

三、Test and Use

# To view the configured cheatpaths:
cheat -d
# To list all available cheatsheets:
cheat -l

cheat tar
cheat tar |grep 'exclude'
cheat find |grep 'mtime'
pupuk commented 3 years ago

强大的xargs

有一个文件 test.txt里面记录是 姓名(tab)身份证,我们需要用linux命令统计一下年龄分布。 head test.txt image

cut -f2 test.txt |cut -c 7-10 |xargs -n1 echo 2020 - |bc |sort|uniq -c |sort -nr |head -10 image

其中xargs -n1是一个最重要的东西,表示每一个结果变成一行,逐行作为参数供xargs使用。 image

需要注意的是:如果stdout是多行,传入xargs,默认会变成一行结果,给xargs。 我们如果要逐行的话,需要加参数-n1

如果有这样一个文件,我们需要对所有数字去重,正好可以利用xargs

1
2 2 3
3 4 5 6 9 10 12
4 5 3 7 8 5 3 1 2 3

如图: image

pupuk commented 3 years ago
临时设置,重启失效

ulimit -n 65535

vim /etc/security/limits.conf

找出内存占用最多的10个进程

ps auxw|sort -rn -k4|head -10 ps -eo pid,user,group,euser,egroup,cmd ps -T -p ##### 查看进程中的线程,MYSQLJ就是多线程的软件 top -H -p ##### 查看线程 top -H ##### 看所有线程 ps -T ##### 查看所有线程

ab压力测试报错 压测 ab -r on\'t exit on socket receive errors. apr_socket_recv: Connection reset by peer ab -k Use HTTP KeepAlive feature

ab -n10000 -c100 http://www.test.api.com/?gid=2 ab -n10000 -c100 -p 'post.txt' -T 'application/x-www-form-urlencoded' 'http://test.api.com/ttk/auth/info/'

nginx php-fpm socket 链接 https://blog.csdn.net/zrp1992/article/details/73251013 https://blog.csdn.net/qq624202120/article/details/60957634

生成指定大小的文件 1M*1024=1G

truncate -s 1G test.data head -c 13MB /dev/urandom > test.data

fallocate -l 13000000 test.data

dd if=/dev/urandom of=test.data bs=1M count=1024 或者dev/zero head -c 1024MB /dev/urandom > test.data truncate -s 1024M test.data

好在Linux支持Sparse(稀疏)文件

磁盘性能测试 fio-3.1-2.el7.x86_64 : Multithreaded IO generation tool https://help.aliyun.com/document_detail/25382.html?spm=a2c4g.11186623.6.571.254aa27dj48aQH

修改hostname hostnamectl set-hostname xxx

循环,间隔一秒钟

while true; do curl https://www.baidu.com/ -I; sleep 1; done; while true; do curl "https://www.baidu.com/"; sleep 1; done;

curl curl -v -v, --verbose Make the operation more talkative curl -I -I, --head Show document info only curl https://www.baidu.com/ -X POST -d "title=comewords&content=articleContent" curl https://www.baidu.com/ -X POST -H "Content-Type:application/json" -d '"title":"comewords","content":"articleContent"' curl --user-agent "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16C50" //iphone 8p curl -H "Content-Type:application/x-www-form-urlencoded; charset=utf-8" -H "Proxy-Connection:close" -H "Cookie:_ga=GA1.2.1770944792.1558341689; _gid=GA1.2.1931370908.1558341689" -H "Accept-Encoding:gzip" -H "Connection:close"

抓取每T质押

curl -s 'https://filfox.info/zh' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3888.0 Safari/537.36' | grep -oPi '\d.\d{4}\sFIL/32GiB' --line-buffered |awk '{print $1}'|xargs echo 32 * |bc

让curl支持HTTP2

vim /etc/yum.repos.d/cityfan.repo [cityfan] name=cityfan baseurl=http://www.city-fan.org/ftp/contrib/yum-repo/rhel7/x86_64/ enabled=1 gpgcheck=0

yum upgrade libcurl 或者 yum update curl

curl是新版本以后,可以不用参数--http2

curl -I https://www.tmall.com/

网络
扫描常见的100个端口

nmap -F -sT 47.97.42.13 nmap 47.97.42.13 -p443

-F Fast mode - Scan fewer ports than the default scan -sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans

我们再回到touch利用touch修改文件时间:

  1. M,C time touch -d "2010-05-31 08:10:30" install.log
  2. mtime touch -m -d "2010-05-31 08:10:30" install.log
  3. 只修改文件的访问时间 touch -a -d "2010-05-31 08:10:30" install.log

下面再给一个rootkit木马常用的伎俩。把b的时间设置成跟a一致 touch -acmr /bin/ls/a /etc/b

另外touch还支持像date命令一样参数修改文件时间:

[root@web10 ~]##### touch -d "2 days ago" install.log ; ll install.log -rw-r--r-- 1 root root 33386 07-11 16:35 install.log

Linux內核版本

cat /proc/version uname -a

Linux系統版本

lsb_release -a cat /etc/redhat-release

几句话看懂awk命令

echo -e "A line 1\nline 2" | awk 'BEGIN{ print "Start" } { print } END{ print "End" }' echo '1\n2\n3' | awk '{ var1="v1"; var2="v2"; var3="v3"; print var1,var2,var3; }'

特别注意: 用uniq命令可以删除相邻的重复行: uniq [file] 但如果一文本中有重复却不相邻的行则无法删除,需要结合sort命令: sort [file]|uniq 等效的sort命令是: sort -u [file]

curl https://www.tmall.com/ | grep -oP "(http|https)://[a-zA-Z0-9.]{1,26}+[.a-zA-Z0-9]{0,26}" | sort | uniq curl https://www.tmall.com/ | grep -oP "^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+" | sort | uniq -o, --only-matching show only the part of a line matching PATTERN -P, --perl-regexp PATTERN is a Perl regular expression

curl http://api.ygmb2b.com/ |grep -oP "((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+.com?"

效果最好的匹配域名的

curl https://www.pornpics.com/blowbang/ |grep -oP "[a-zA-Z0-9-.]+.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)" |sort |uniq

curl -i -X HEAD "http://outofmemory.cn/"

用grep -c "xxx字符"得到的是行数,如果一行中有多个匹配到的字符,只会算作一个 使用grep -o "xxx字符"按行显示出所有的匹配结果,匹配结果会自动换行 grep -o "xxx" |wc

reboot 需要等一段时间

立刻重启

shutdown -r now

cut -b cut -b1 -n cut -d: -f1,2-5

转义输出tab

sed -n l

同时把x和z替换成y,下面2条命令等价

sed -e 's/x/y/g' -e 's/z/y/g' sed -e 's/x/y/g; s/z/y/g'

多行求和

cat /tmp/1.log |awk '{sum+=$1} END {print sum}'

多行求平均值

cat /tmp/1.log |awk '{sum+=$1} END {print "Avg = ", sum/NR}'

例如每秒执行一次top命令,把结果输出到某个文件中保存,现在需要统计这段时间内某个进程的平均CPU占用率,可使用以下命令

cat top.log.201805101154 | grep "GameServer_r" | awk '{sum+=$9} END {print "Avg =", sum/NR}'

tail -f in.log | awk '{print $0; fflush() }' >> out

ping的毫秒结果,记录成日志

nohup ping 47.57.5.106 |grep -oP 'time=.*ms' --line-buffered |sed -e 's/time=//g; s/ ms//g;' -u |awk '{print $0;fflush()}' >> ping.log & 2>&1

批量计算

echo "1\n2\n3\n4\n5\n6" |xargs -n1 echo 1 + |bc

yum update不升级内核 vim /etc/yum.conf,在 [main] 的最后添加 确认无效 exclude=kernel exclude=centos-release

yum update -x "kernel*" -y

getconf LONG_BIT uname -a uname -m cat /etc/redhat-release

服务启动,停止等 Centos6,CentOs7

service SERVICE start|stop|restart|reload|status systemctl start|stop|restart|reload|status SERVICE

开机启动

chkconfig SERVICE on|off systemctl enable|disable SERVICE

查看启动项

chkconfig --list |grep SERVICE systemctl list-unit-files | grep php-fpm systemctl is-enabled php-fpm.service

查看当前服务使用的底层参数

systemctl show nginx.service |grep -i restart

当前使用的shell

echo $SHELL

ctrl + C ##### 强制终止当前命令 ctrl + D ##### 退出当前shell ctrl + L ##### 清屏 ctrl + A ##### 光标移动到命令行首 ctrl + E ##### 光标移动到行尾 ctrl + U ##### 从光标所在位置删除到行首 ctrl + Z ##### 把命令放入后台 ctrl + R ##### 在历史命令中搜索

校准服务器时间 ntpdate ntp2.aliyun.com

Windows time.pool.aliyun.com

PHP-FPM添加慢日志: vim /etc/php-fpm.d/www.conf slowlog = /var/log/php-fpm/www-slow.log request_slowlog_timeout = 3

pm = dynamic pm.max_children = 100 pm.start_servers = 20 pm.min_spare_servers = 20 pm.max_spare_servers = 50

PHP记录错误日志 vim /etc/php.ini display_errors = Off [Off = Do not display any errors | stderr = Display errors to STDERR (affects only CGI/CLI binaries!) | On or stdout = Display errors to STDOUT] log_errors = On error_log = /var/log/php-error.log

如果没有生成日志: vim /etc/php-fpm.d/www.conf catch_workers_output = yes 将worker进程的,stdout和stderr转到main error log。 no「default」的值是转到 /dev/null

查看php.ini的生效结果 php -i|grep error

检查 apache用户是否有操作 /www/mine/MMM/的权限

sudo -u apache stat /www/mine/MMM/

同时修改用户和组 chown -R root:root dir

关闭Selinux

查看状态

getenforce sestatus -v

vim /etc/sysconfig/selinux SELINUX=disabled

shutdown -r now

scp -P 6080 privacy.html root@47.97.42.13:/home/www/RRMOversea/trunk/official/dist [能正常使用] scp -r /dir/a/b/ -P 6080 root@121.41.128.83:/remote_dir/a/b/

查询域名的mx ns cname记录 -q = -query = -querytype

nslookup -q=ns bhpadvance.com nslookup -q=mx bhpadvance.com nslookup -q=a bhpadvance.com nslookup -q=cname www.bhpadvance.com

type可能改值:A, AAAA, A+AAAA, ANY, CNAME, MX, NS, PTR, TXT, SOA, or SRV as the record type

nslookup -tpye=any mhtyc.moyuntv.com nslookup -tpye=any bhpadvance.com

命令行模式 ~ nslookup

set q=mx bhpadvance.com

nslookup -type=any bhpadvance.com

查找特定类型文件,里面的文本

find . -type f -name ".php" |xargs grep "TIMESTAMP" -i find . -path ./data/upload -prune -o -name '.php' |xargs grep '170605000037590' find . -type f |xargs grep 'https://rpms.remirepo.net/' -l|xargs sed -i "s/rpms.remirepo.net/mirrors.aliyun.com\/remi/g" ##### remi前面的是转义字符

du -h -x --max-depth=1 -x参数会让du命令不统计不在同一个磁盘分区上目录,或换句话说,忽略其他的磁盘挂载点。 du -s * | sort -nr |head -20 ll -hS 将文件以从大到小顺序展现

查看删除的文件(已经用文件系统中unlink,但是因为被进程占用,space还有release出来)是否被占用,如果发现,可以重启相应的进程

lsof | grep deleted lsof | grep delete | awk -F ' ' '{ print $2}' | xargs kill -9

journalctl --disk-usage journalctl --vacuum-size=512M

find . ! -newermt '2019-08-10' -exec rm -rf {} \; find . -mtime +5 -type f -name "" -exec rm -f {} \; ##### 只找文件 find . -mtime +5 -type d -name "" -exec rm -f {} \; ##### 只找目录 find . -mtime +5 -name "" -exec rm -f {} \; ##### 不限制,但是会把当前目录找出来并删掉 find ./ -mtime +5 -name "*" -exec rm -f {} \; ##### 不限制,不会把当前目录找出

找到的文件可以rm,也可以echo '' >

那就是一个文件被彻底删除需要满足的条件; 一是这个文件的硬链接数为0 二是进程占用数为0

cd /proc/$pid

当文件被rm,在操作系统内部其实是调用了unlink操作,其目录项被删除(du统计时就会忽略),如果其对应的inode节点的引用计数为0,则删除对应的inode节点和清除inode节点位图中对应的位,其对应磁盘可被再申请;但如果此文件被其他进程打开,则其对应的inode节点的引用计数不为0,则不会删除对应的inode节点和清除inode节点位图中对应的位,其对应磁盘不能被再申请,也就是在lsof下可以看到deleted句柄;当前文件被所有使用进程close后,系统删除对应的inode节点和清除inode节点位图中对应的位,其对应磁盘可被再申请。

一个被进程打开的文件被rm后,其目录项被删除了,在du命令下是不能被统计到,而其inode没有被删除,在df命令下是可以被统计到的,这就是在du和df存在较大差别的原因。


版权声明:本文为CSDN博主「jasonliu1919」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/ljp1919/article/details/69666426

---------------------磁盘满的常见情况----------------- 小文件太多,inode被耗尽 磁盘真实空间被好耗尽 僵尸文件:已删除文件因句柄被占用未释放导致相应空间未释放 挂载点覆盖:在原有文件系统的相应目录下已经存在大量文件。挂载了新磁盘后,导致使用 df 命令能统计到相关空间使用,而使用 su 命令统计不到。

find /home/www/MALL/data/log -mtime +90 -type f -name "" -exec rm -f {} \; find /home/www/MGZY/data/log -mtime +90 -type f -name "" -exec rm -f {} \; find /media/sql_bak/mgzy/ -mtime +3 -name "" -exec rm -rf {} \; ##### 这个不会删除mgzy目录

查看os系统块(block)的大小 1block = 8*sector(s) = 4096 Bytes 建议大文件用大block

tune2fs -l /dev/sda1

查看os系统(内存)页的大小

getconf PAGESIZE

整理github的issue列表链接,后续配合sublime,excel可以顺利处理

curl https://github.com/pupuk/blog/issues |grep "data-hovercard-type=\"issue\"" |grep "href." -o curl https://github.com/pupuk/mysql/issues |grep "data-hovercard-type=\"issue\"" |grep "href." -o

curl -s --silent Silent or quiet mode. Don\'t show progress meter or error messages. Makes Curl mute. It will still output the data you ask for, potentially even to the terminal/stdout unless you redirect it.

curl -o /dev/null -s -w '%{time_connect} %{time_starttransfer} %{time_total}\n' -d 'uid=32592&token=151e3dca00d8516e2e6e32716ff9bdd1&page=1&coin_type=BTC&sign=2502eb4f412f569575e422b2da064332&timestamp=1567764042&merchant_id=10005' https://rrmiappapiv1.hulatu.cn/machine/list/

打包排除目录 排除的目录后面不能加斜杠

tar -zcvf dirname.tar.gz --exclude=dirname/logs --exclude=dirname/libs dirname

复制到远程目录 或 文件

scp -r /dir/a/b/ -P 6080 root@121.41.128.83:/remote_dir/a/b/

复制的文件检查完整性

md5sum file.tar.gz sha1sum file.tar.gz

删除包含很多文件「50w+」的目录 mv或rename 重命名也是一种思路 但是事后还是需要慢慢删除 本目录我也写的有相关的word文档

rsync -a --delete blank/ need_del/

然后再重命名 blank目录
循环创建文件

for i in $(seq 1 500000);do echo text >$i.txt;done

查看某个端口的使用情况

lsof -i:端口号 lsof -i:9000

id nginx 查看nginx用户的uid, gid uid=997(nginx) gid=995(nginx) groups=995(nginx)

查看用户登录日志

last last | tail -20

查看系统所有用户

cut -d: -f1 /etc/passwd

查看php-fpm的一些关键参数

grep '(max_|_server|timeout)' /etc/php-fpm.conf -n

子目录 特定类型文件 字符匹配

grep -r --include="*.php" '58.32.246.70' /moyun/www/Myshop/

测试硬盘的读写速度

dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file dd if=/root/1Gb.file bs=64k | dd of=/dev/null

销毁磁盘数据 注意:利用随机的数据填充硬盘,在某些必要的场合可以用来销毁数据。

dd if=/dev/urandom of=/dev/hda1

lsof指令常用的的用法如下:

lsof abc.txt 显示开启文件abc.txt的进程 lsof 目录名 查找谁在使用文件目录系统 lsof -i :22 知道22端口被哪个进程占用 lsof -c abc 显示abc进程现在打开的文件 lsof -g gid 显示归属gid的进程情况 lsof -n 不将IP转换为hostname,缺省是不加上-n参数 lsof -p 12 看进程号为12的进程打开了哪些文件 lsof -u username 查看用户打开哪些文件 lsof -i @192.168.1.111 查看远程已打开的网络连接(连接到192.168.1.111)

批量改动子文件.shell

cd /moyun/www/Myshop/data/upload/shop/store/goods rename _480. _360. / rename _480. _360. // rename _480. _360. /// rename _480. _360. //// rename _480. _360. ///// rename _480. _360. ////// rename _480. _360. /////// rename _480. _360. ///////

环境变量相关知识

思考:php -v 为什么会执行成:/usr/bin/php -v

永久修改

vim /etc/profile export CLASSPATH=./JAVA_HOME/lib;$JAVA_HOME/jre/lib source /etc/profile [想马上生效],否者只能等重启生效

临时

使用export命令声明即可,变量在关闭shell时失效。 export PATH=$PATH:/home/cc/path1:/home/cc/path2

查看

echo $PATH env 环境变量生效的一个重要特征是:命令可以任何目录,执行成功

系统级别 -- /etc/environment (一般不做修改) -- /etc/profile (一般修改这个文件)

用户级 -- ~/.profile -- ~/.bashrc

yum install ImageMagick

安装是否成功

convert --version yum install php-pecl-imagick

修改gitignore文件,对于已经追踪的文件,不生效, 理解了git的[workspace, index, 版本库,远程仓库]就好理解了

git rm -r --cached . ##### 删除index区里面的文件 git add . git commit -m"update .gitignore"

对工作区中文件的修改分为三种情况: (1)修改,但没有用git add将修改添加到暂存区; (2)修改,已经使用git add将修改添加到暂存区; (3)修改,已经使用git add将修改添加到暂存区,并再次进行修改。 对于第一种情况,直接使用git checkout -- 文件,即可撤销修改,撤销修改就回到和版本库一模一样的样子。 第二种情况,先使用git reset HEAD -- 文件,然后在使用git checkout -- 文件进行修改撤销。 第三种情况 先使用git checkout -- 文件,文件就会变成添加到暂存区后的状态,也就转换成了“第二种情况”,然后,在使用情况(2)中的处理方法,即可将文件恢复到与版本库一致的状态。 总之,记住一点:“git checkout -- 文件”命令,撤销的是工作中文件的修改,而“git reset HEAD -- 文件”命令,撤销的是暂存区中文件的修改。

linux 多个命令一起用

(cd /media/sf_www/crv/paint/out/420627590466885000 && zip admin_799.zip *.jpg)

sort xxx.txt -u |wc 等同于 sort xxx.txt | uniq |wc

List network connections 列出网络连接

nmcli d

ip route show

MySQL打开请求日志,方便排查应用层的错误

SET GLOBAL general_log=1 show VARIABLES LIKE '%general_log%'

tail -f 相应的日志文件

后台运行命令

nohup --help

run COMMAND, ignoring hangup signals. 此命令产生的进程忽略挂起信号(关闭shell窗口,程序不会中断;但是Ctrl+C当时还中断,因为Ctrl+C发送的是SIGINT信号),同时会把终端输出记录到日志文件,nohup.out

命令后加&,Ctrl+C, 程序照样运行(因为对SIGINT信号免疫); 关闭shelltab,程序停止,&对SIGHUP信号不免疫。

综合: nohup ./exe & nohup COMMAND &

Supervisior

yum install -y supervisior

配置文件是 /etc/supervisord.conf, 如果文件里面有

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

则可以在子目录里面针对每个要守护的进程,单独弄一个配置文件,方便管理,例如:

[program:golang-http-server] command=/home/go/src/otc/main autostart=true autorestart=true startsecs=10

systemctl start[stop][reload][restart][status][enable][disable] supervisord

查看已有yum源

yum repolist

删除yum源,1. /etc/yum.repos.d/, 删除相应文件;2. rpm删除对应包

cd /etc/yum.repos.d/ rm 对应repo文件

rpm -qa |grep getpagespeed rpm -e getpagespeed-extras-release-10-15.noarch

重建

yum clean all yum makecache

PREPARE、确定自己的Centos版本,选下载包或者其他依赖的时候,要找相对应,要兼容的; cat /etc/centos-release

1、 安装编译nginx所需的包 yum install -y zlib zlib-devel pcre prce-devel openssl openssl-devel 【可能这个就已经足够了】

yum groupinstall -y 'Development Tools' 【装的东西有点多,不推荐】

2、

如果下载的包,wget没有完全下载完成,也是可以解压的,但是可能缺失文件,造成编译时
./configure auto/unix: No such file or directory
./configure auto/options: No such file or directory

建议对下载完成的tar.gz文件使用md5sum命令校验其文件的完整性; 如果遇到githhub的下载链接很慢,可以换官网链接,也可以先用浏览器下载下来,再FTP上传到服务器;

cd /usr/local/src/ wget https://github.com/nginx/nginx/archive/release-1.18.0.tar.gz tar zxvf release-1.18.0.tar.gz cd nginx-release-1.18.0/ auto/configure --help 【( You will get help regarding configure such as modules to be installed ) ,没有报错则说明ok】

下载第三方模块 cd /usr/local/src/ wget https://github.com/openresty/echo-nginx-module/archive/v0.61.tar.gz tar zxvf v0.61.tar.gz cd echo-nginx-module-0.61 pwd 获取模块源码的目录:/usr/local/src/echo-nginx-module-0.61


创建nginx用户和组 useradd -s /sbin/nologin nginx useradd -s /sbin/nologin nginx

改nginx源码,可以把nginx伪装成其它Server

vim src/core/nginx.h vim src/http/ngx_http_header_filter_module.c vim src/http/ngx_http_special_response.c

我这里把nginx换成ngxv9

cd /usr/local/src/nginx-release-1.18.0/

auto/configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-stream_ssl_preread_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=/usr/local/src/echo-nginx-module-0.61

如果遇到报错则依次解决

--add-module=/usr/local/src/echo-nginx-module-0.62rc1 $ make -j2 $ make install

which nginx ##### nginx ##### 启动Nginx nginx -t ##### 验证配置文件是正确 nginx -s reload ##### 重启Nginx nginx -s stop ##### 停止Nginx nginx -v ##### 查看是否安装成功 nginx -V ##### 查看是否安装成功,看编译参数

创建systemctl服务管理 https://zhuanlan.zhihu.com/p/128579141

vim /usr/lib/systemd/system/nginx.service

[Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target

[Service] Type=forking PIDFile=/run/nginx.pid

Nginx will fail to start if /run/nginx.pid already exists but has the wrong
SELinux context. This might happen when running nginx -t from the cmdline.
https://bugzilla.redhat.com/show_bug.cgi?id=1268621

ExecStartPre=/usr/bin/rm -f /run/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true

[Install] WantedBy=multi-user.target

systemctl start[stop][reload][restart][status][enable][disable][is-enabled] nginx.service

echo 模块文档 https://www.nginx.com/resources/wiki/modules/echo/ https://www.jianshu.com/p/a636ca5fa8fa

nginx 动态模块 https://blog.csdn.net/weixin_33786077/article/details/89767983

act /act?k1=v1&k2=v2 index.php?act=()/op=index?k1=v1&k2=v2 /act/op index.php?act=()/op=()?k1=v1&k2=v2 /act/op?k1=v1&k2=v2 index.php?act=()/op=()?k1=v1&k2=v2

查看linxu所有信号量
https://blog.csdn.net/de_se/article/details/102769731

kill -l kill -l 1 kill -l 2 echo 1 2 3 4 5 6 7 8 9|xargs -n1 kill -l ;

查看 修改 网关

route -n

vim /etc/sysconfig/network-scripts/ifcfg-enp0s3 修改gitway

添加和删除用户, 使用useradd命令创建用户的时候,一般会在以为文件中新增记录

/etc/passwd /etc/group /etc/shadow /etc/gshadow

并创建以下目录

/home/newuser /var/spool/mail/newuser

普通的userdel只会删除上面4个文件中记录,不清删除下面的目录

userdel -r newuser 就可以


useradd -m -s /bin/bash git passwd git su - git mkdir -p /home/git/local

useradd --system --shell /bin/bash --create-home --home-dir /home/gitea gitea

useradd -r -s /bin/bash -c 'Gogs' -U -d /home/git -m git

sudo useradd \ --system \ --shell /bin/bash \ --comment 'Git Version Control' \ --create-home \ --home-dir /home/git \ git

su - git

创建git用户,让gogs以git身份运行,不以root运行,确保安全性

useradd -r -s /bin/bash -c 'Gogs' -U -d /home/git -m git

useradd --system --shell /bin/bash --comment 'Gogs' --user-group --home-dir /home/git -m git

su git cd /home/git

二进制安装

wget ... chmod +x ...

--OR--

编译安装

git clone --depth 1 https://github.com/gogs/gogs.git gogs cd gogs go build -o gogs

运行

./gogs web

查看运行情况

netstat -ntpl |grep 3000 lsof -i:3000

添加到系统服务:

su root cd scripts/systemd cp gogs.service /usr/lib/systemd/system/ systemctl start[stop][reload][restart][status][enable][disable][is-enabled] gogs.service

MySQL临时打开通用日志 set global general_log='ON';

查看

show variables like '%general_log%';

熵池大小

cat /proc/sys/kernel/random/poolsize

当前可用的熵

cat /proc/sys/kernel/random/entropy_avail

生成随机字符

head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 head /dev/urandom|tr -dc '[:alnum:]' | head -c 16 head /dev/urandom|tr -dc '[:alnum:][:punct:]' | head -c 16

https://www.cnblogs.com/bingguoguo/articles/9188703.html?tt_from=copy_link&utm_source=copy_link&utm_medium=toutiao_ios&utm_campaign=client_share
ping记录追加到日志

ping 47.57.5.106 | awk '{ print $0" " strftime("%Y-%m-%d %H:%M:%S",systime()) } ' >> /tmp/jiguang.log &