1、常用的Linux命令
文件及文件夹权限:chmod -R 0644 /home/wwwroot/eonegh/usr/themes
文件及文件夹用户组:chown -R www:www /home/wwwroot/eonegh/usr/themes
解压tar.gz到目录:tar -xzvf typecho.tar.gz /home/wwwroot/eonegh
解压tar到目录:tar -xvf typecho.tar /home/wwwroot/eonegh
tar压缩文件及文件夹到目录(过程不可见、绝对路径):tar -czPf /home/wwwroot/eonegh.tar.gz /home/wwwroot/eonegh
安装zip/unzip命令:apt-get install zip/unzip 或 yum install zip/unzip
zip加密压缩文件及文件夹到目录:zip -qrP password /home/wwwroot/eonegh.zip /home/wwwroot/eonegh
将eonegh.com.zip解压到/home/www目录下:unzip -uv -P password eonegh.com.zip -d /home/www
使文件具有执行权限:chmod +x /root/sh/backup-sql.php
删除“.user.ini”:chattr -i /home/wwwroot/eonegh/.user.ini
自动执行脚本,并输出执行提示到日志中:
crontab -e
0 3 */2 * * /root/backup-sql.sh 2>&1 | tee -a /root/backup_sql.log
注:每隔2天的03:00执行一次,31日-1日会出错
将mysql文件夹压缩成mysql.zip:zip -r mysql.zip mysql
删除目录及其文件:rm -rf /home/wwwroot/default/
删除文件:rm /home/wwwroot/default/install.php
移动目录及其文件:mv -f /home/wwwroot/default/ /home/wwwroot/default/php/php
注:default目录加"/",php/php目录可以不存在
移动文件:mv /home/wwwroot/default/php/php/Json.php /home/wwwroot/default/pHp/
注:pHp目录必须存在,且需要"/",反之就是移动且重命名为pHp文件
复制目录及其文件:cp -af /home/wwwroot/default/php /home/wwwroot/default/php/php
注:php/php目录可以不存在
复制目录及其文件并保持文件结构属性:cp --path -af /www/server/nginx /tmp
等同于:mkdir -p /tmp/www/server/nginx && cp -af /www/server/nginx /tmp/www/server/nginx
复制目录及其文件并保持属性(用户组、读写执行权限):cp -arf /home/wwwroot/default/php /home/wwwroot/default/php/php
注:php/php目录可以不存在
复制文件:cp -f /home/wwwroot/default/install.php /home/wwwroot/default/pHp/
注:pHp目录必须存在,且需要"/",反之就是复制且重命名为pHp文件
更新复制:cp -uaf /www/server/nginx/conf /tmp/www/nginx
显示文件夹大小:du -h --max-depth=1 /tmp/www/nginx
显示文件夹下个文件大小:du -h --max-depth=1 /tmp/www/nginx/*
访问WebDAV(坚果云):cadaver https://dav.jianguoyun.com/dav/Eonegh.com
注:上传:put,下载:get,退出:exit
输出内容到文件中:2>&1 | tee -a /path/cf_realIP_update.sh.log
创建软连接:ln -s /root/SourcePath /root/LinkPath
VMware共享文件创建软连接:sudo ln -s /mnt/hgfs/DataShare4Linux ~/Desktop/Share
通过进程名杀死进程(直接放在cshrc或者bash中):alias killgo “ps -ef |grep $1 |awk '{print $2}' |xargs kill -9”
2、shell命令
清空文件,并输出内容到文件中:echo "#Cloudflare" > $CLOUDFLARE_FILE_PATH
以追加方式输出内容到文件中:echo "" >> $CLOUDFLARE_FILE_PATH;
显示当前时间:
echo
echo `date +"%Y-%m-%d %H:%M:%S"`
带参数执行
if [[ "$1" == "--all" || "$1" == "-a" ]]; then
echo "Purging everything..."
config[data]="{ \"purge_everything\": true }"
elif [ ! -z "$1" ]; then
echo "Command not found: $1"
exit 1
fi
3、宝塔linux面板重启、重置等命令
安装宝塔
Centos 安装脚本
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install.sh && sh install.sh
Ubuntu/Deepin 安装脚本
wget -O install.sh http://download.bt.cn/install/install-ubuntu.sh && sudo bash install.sh
Debian 安装脚本
wget -O install.sh http://download.bt.cn/install/install-ubuntu.sh && bash install.sh
Fedora 安装脚本
wget -O install.sh http://download.bt.cn/install/install.sh && bash install.sh
管理宝塔
停止 /etc/init.d/bt stop
启动 /etc/init.d/bt start
重启 /etc/init.d/bt restart
卸载 /etc/init.d/bt stop && chkconfig --del bt && rm -f /etc/init.d/bt && rm -rf /www/server/panel
查看当前面板端口 cat /www/server/panel/data/port.pl
修改面板端口,如要改成 8881(centos 6 系统)
echo '8881' > /www/server/panel/data/port.pl && /etc/init.d/bt restart
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 8881 -j ACCEPT
service iptables save
service iptables restart
修改面板端口,如要改成 8881(centos 7 系统)
echo '8881' > /www/server/panel/data/port.pl && /etc/init.d/bt restart
firewall-cmd --permanent --zone=public --add-port=8881/tcp
firewall-cmd --reload
强制修改 MySQL 管理(root)密码,如要改成 123456 cd /www/server/panel && python tools.pyc root 123456
修改面板密码,如要改成 123456 cd /www/server/panel && python tools.pyc panel 123456
查看宝塔日志 cat /tmp/panelBoot.pl
查看软件安装日志 cat /tmp/panelExec.log
站点配置文件位置 /www/server/panel/vhost
删除域名绑定面板 rm -f /www/server/panel/data/domain.conf
清理登陆限制 rm -f /www/server/panel/data/*.login
查看面板授权 IP cat /www/server/panel/data/limitip.conf
关闭访问限制 rm -f /www/server/panel/data/limitip.conf
查看许可域名 cat /www/server/panel/data/domain.conf
关闭面板 SSL rm -f /www/server/panel/data/ssl.pl && /etc/init.d/bt restart
查看面板错误日志 cat /tmp/panelBoot
查看数据库错误日志 cat /www/server/data/*.err
站点配置文件目录(nginx) /www/server/panel/vhost/nginx
站点配置文件目录(apache) /www/server/panel/vhost/apache
站点默认目录 /www/wwwroot
数据库备份目录 /www/backup/database
站点备份目录 /www/backup/site
站点日志 /www/wwwlogs
Nginx 服务管理
nginx 安装目录 /www/server/nginx
启动 /etc/init.d/nginx start
停止 /etc/init.d/nginx stop
重启 /etc/init.d/nginx restart
启载 /etc/init.d/nginx reload
nginx 配置文件 /www/server/nginx/conf/nginx.conf
Apache 服务管理
apache 安装目录 /www/server/httpd
启动 /etc/init.d/httpd start
停止 /etc/init.d/httpd stop
重启 /etc/init.d/httpd restart
启载 /etc/init.d/httpd reload
apache 配置文件 /www/server/apache/conf/httpd.conf
MySQL 服务管理
mysql 安装目录 /www/server/mysql
phpmyadmin 安装目录 /www/server/phpmyadmin
数据存储目录 /www/server/data
启动 /etc/init.d/mysqld start
停止 /etc/init.d/mysqld stop
重启 /etc/init.d/mysqld restart
启载 /etc/init.d/mysqld reload
mysql 配置文件 /etc/my.cnf
FTP 服务管理
ftp 安装目录 /www/server/pure-ftpd
启动 /etc/init.d/pure-ftpd start
停止 /etc/init.d/pure-ftpd stop
重启 /etc/init.d/pure-ftpd restart
ftp 配置文件 /www/server/pure-ftpd/etc/pure-ftpd.conf
PHP 服务管理
php 安装目录 /www/server/php
启动(请根据安装 PHP 版本号做更改,例如:/etc/init.d/php-fpm-54 start)
/etc/init.d/php-fpm-{52|53|54|55|56|70|71} start
停止(请根据安装 PHP 版本号做更改,例如:/etc/init.d/php-fpm-54 stop)
/etc/init.d/php-fpm-{52|53|54|55|56|70|71} stop
重启(请根据安装 PHP 版本号做更改,例如:/etc/init.d/php-fpm-54 restart)
/etc/init.d/php-fpm-{52|53|54|55|56|70|71} restart
启载(请根据安装 PHP 版本号做更改,例如:/etc/init.d/php-fpm-54 reload)
/etc/init.d/php-fpm-{52|53|54|55|56|70|71} reload
配置文件(请根据安装 PHP 版本号做更改,例如:/www/server/php/52/etc/php.ini)
/www/server/php/{52|53|54|55|56|70|71}/etc/php.ini
Redis 服务管理
redis 安装目录 /www/server/redis
启动 /etc/init.d/redis start
停止 /etc/init.d/redis stop
redis 配置文件 /www/server/redis/redis.conf
Memcached 服务管理
memcached 安装目录 /usr/local/memcached
启动 /etc/init.d/memcached start
停止 /etc/init.d/memcached stop
重启 /etc/init.d/memcached restart
启载 /etc/init.d/memcached reload
4、Log日志统计分析常用命令
IP相关统计
统计IP访问量,并升序输出
awk '{print $1}' access.log1 |sort |uniq -c|sort -n 2>&1 | tee -a /home/wwwlogs/IP.log
统计IP访问量(独立ip访问数量)
awk '{print $1}' access.log | sort -n | uniq | wc -l
查看某一时间段的IP访问量(4-5点)
grep "07/Apr/2017:0[4-5]" access.log | awk '{print $1}' | sort | uniq -c| sort -nr | wc -l
查看访问最频繁的前100个IP
awk '{print $1}' access.log | sort -n |uniq -c | sort -rn | head -n 100
查看访问100次以上的IP
awk '{print $1}' access.log | sort -n |uniq -c |awk '{if($1 >100) print $0}'|sort -rn
查询某个IP的详细访问情况,按访问频率排序
grep '127.0.01' access.log |awk '{print $7}'|sort |uniq -c |sort -rn |head -n 100
页面访问统计
查看访问最频的页面(TOP100)
awk '{print $7}' access.log | sort |uniq -c | sort -rn | head -n 100
查看访问最频的页面([排除php页面】(TOP100)
grep -v ".php" access.log | awk '{print $7}' | sort |uniq -c | sort -rn | head -n 100
查看页面访问次数超过100次的页面
cat access.log | cut -d ' ' -f 7 | sort |uniq -c | awk '{if ($1 > 100) print $0}' | less
查看最近1000条记录,访问量最高的页面
tail -1000 access.log |awk '{print $7}'|sort|uniq -c|sort -nr|less
请求量统计
每秒请求量统计
统计每秒的请求数,top100的时间点(精确到秒)
awk '{print $4}' access.log |cut -c 14-21|sort|uniq -c|sort -nr|head -n 100
每分钟请求量统计
统计每分钟的请求数,top100的时间点(精确到分钟)
awk '{print $4}' access.log |cut -c 14-18|sort|uniq -c|sort -nr|head -n 100
每小时请求量统计
统计每小时的请求数,top100的时间点(精确到小时)
awk '{print $4}' access.log |cut -c 14-15|sort|uniq -c|sort -nr|head -n 100
性能分析
在nginx log中最后一个字段加入$request_time
列出传输时间超过 3 秒的页面,显示前20条
cat access.log|awk '($NF > 3){print $7}'|sort -n|uniq -c|sort -nr|head -20
列出php页面请求时间超过3秒的页面,并统计其出现的次数,显示前100条
cat access.log|awk '($NF > 1 && $7~/\.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100
蜘蛛抓取统计
统计蜘蛛抓取次数
grep 'Baiduspider' access.log |wc -l
统计蜘蛛抓取404的次数
grep 'Baiduspider' access.log |grep '404' | wc -l
TCP连接统计
查看当前TCP连接数
netstat -tan | grep "ESTABLISHED" | grep ":80" | wc -l
用tcpdump嗅探80端口的访问看看谁最高
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr
5、Nginx 相关配置
https跳转至http
if ($server_port = "443") {
return 302 http://$host$request_uri;
}
或者
if ( $https = "on" ) {
return 301 http://$host$request_uri;
}
www网址跳转至不带www
rewrite ^(.*) $scheme://eonegh.com$1 permanent;
6、Git命令
git clone [email protected]:eonegh/outlook.git
git remote add origin [email protected]:zaxbpc0/outlook.git
git config --global user.name ""
git config --global user.email ""
git add -A
git commit -m "update via Git"
git push