linux 常用命令

来源:互联网 发布:数据列表测试用例 编辑:程序博客网 时间:2024/05/17 01:15
1、iptables


   iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT;


   service iptables save; 保存配置


   iptables -L -n       ;查看已开放的端口


   iptables -I INPUT -s 120.25.205.228 -j DROP 添加ip地址到限制名单上


   iptables -D INPUT -s ***.***.***.*** -j DROP 接触ip地址到限制名单上


2、查看当前进程链接(awk,ps ,grep)


  ps -ef | grep httpd | wc -l 查看当前进程链接数


  ps aux | grep apache 能查看apache 使用的cpu比率跟使用内存情况


  netstat -anlp | grep :21 根据端口找服务


  ps aux | grep httpd   根据服务找位置    


  ps aux | grep apache | grep -v grep (grep -v grep 当前查询所占有的不显示在列表)


  ps aux | grep apache | grep -v grep | awk '{print $4}'  awk +后面 代表只显示第四列(第四列是内存,第三列是cpu)


  ps aux | grep httpd | grep -v grep |awk 'BEGIN{sum=0;} {sum+=$4;}END{print sum}' 统计httpd占有多少内存


  ps aux | grep httpd | grep -v grep |awk 'BEGIN{sum=0;} {sum+=$3;}END{print sum}' 统计httpd占有多少cpu


3、授权


   chmod +x filename x可执行,r可阅读


4、文件命令


    vi 文件名 新建文件
    rm 删除文件


5、php常用命令


   php -m查看扩展


6、mysql grant命令


grant all privileges on oneinstack.* to 68shop_xjd@'%'


grant all privileges on oneinstack.* to linuxeye@'%' identified by 'Sxwh9988!@#$%';


grant all on * to "68shop_xjd"@"%" identified by 'Sxwh9988^&*()'


grant all  on *.* to 68shop_xjd@'%' identified by 'Sxwh9988^&*()';


grant all on *.* to "68shop_xjd"@"%" identified by "Sxwh9988^&*()";




grant all on *.* to "test"@"%" identified by "123456";  新建立了一个数据表




7、端口找服务


netstat -anlp | grep :21       端口找服务


列出服务和他们对应的端口:


netstat -tulpn


ps aux | grep  pure-ftpd      服务找位置


ps aux | grep ftpd 这个试下


ping 是走的ICMP协议 没有端口




8、source /etc/profile


   让环境变量直接有用,而不直接重启




9、日志


   看 /var/log/cron.log这个文件就可以,可以用tail -f /var/log/cron.log观察
   /var/log/cron只会记录是否执行了某些计划的脚本,但是具体执行是否正确以及脚本执行过程中的一些信息则linux会每次都发邮件到该用户下。
   在 /var/spool/mail/root 文件中,有crontab执行日志的记录,用tail -f /var/spool/mail/root 即可查看最近的   crontab执行情况。




10、查看流量


 yum install iftop -y 安装


 1、服务器内部安装 iftop 流量监控工具:


  yum install iftop -y


 2、.服务器外网带宽被占满时,如果通过远程无法登陆,可通过阿里云终端管理进入到服务器内部,运行下面命令查看 流量占用情况:


 iftop -i eth1 -P 
 注:-P 参数会将请求服务的端口显示出来,也就是说是通过服务器哪个端口建立的连接,看内网流量执行 iftop -i  eth0 -P 命令。 








11、ps aux|grep -v grep|awk '/httpd/{sum+=$6;n++};END{print sum/n}' 查看使用内存