Press "Enter" to skip to content

标签: linux

Nginx HTTP Post Method: 405 Method not allowed解决方法

最近维护一台RedHat 5.4 X64系统,环境是Nginx,跑着一个论坛,需要向HTML页面提交POST数据,结果都被拦截下来了,显示错误:“nginx 405 Not Allowed”,是乎没有很好的解决办法,唯一能做的就是重新编译Nginx源码和编辑conf文件。
需要修改Nginx中的C源码文件位于 /nginx源码目录/src/http/modules/ngx_http_static_module.c ,找到如下代码:

    if (r->method == NGX_HTTP_POST) {
        return NGX_HTTP_NOT_ALLOWED;
    }


注释掉如下:

/*if (r->method == NGX_HTTP_POST) {
        return NGX_HTTP_NOT_ALLOWED;
    }
*/


然后再重新编译 make
复制/nginx源码目录/ objs 目录下的 nginx至安装的Nginx目录下,重启Nginx生效。

对于Nginx,可以修改nginc.conf配置文件,改变“405错误”为“200 ok”,并配置location来解决,方法如下:

server
{
    listen       80;
    server_name  www.kiccleaf.com;
    index index.html index.htm index.php;
    root  /data/kiccleaf;  

    if ($host != 'www.kiccleaf.com' ) {
         rewrite ^/(.*)$ http://www.kiccleaf.com/$1 permanent;
    }
    location ~ .*\.(php|php5)?$
    {
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fcgi.conf;
    }
    #添加以下405代码
    error_page   405 =200 @405;
    location @405
    {
        root  /data/kiccleaf;
    }
}


也可以简单的编写成

server
{
    listen       80;
    server_name  www.kiccleaf.com;
    index index.html index.htm index.php;
    root  /data/kiccleaf;  

    if ($host != 'www.kiccleaf.com' ) {
         rewrite ^/(.*)$ http://www.kiccleaf.com/$1 permanent;
    }
    location ~ .*\.(php|php5)?$
    {
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fcgi.conf;
    }
    #添加以下405代码
    error_page 405 =200 $uri;
}
Leave a Comment

Linux下chkconfig命令详解

chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。

使用语法:
chkconfig [–add][–del][–list][系统服务] 或 chkconfig [–level <等级代号>][系统服务][on/off/reset]

chkconfig在没有参数运行时,显示用法。如果加上服务名,那么就检查这个服务是否在当前运行级启动。如果是,返回true,否则返回false。如果在服务名后面指定了on,off或者reset,那么chkconfi 会改变指定服务的启动信息。on和off分别指服务被启动和停止,reset指重置服务的启动信息,无论有问题的初始化脚本指定了什么。on和off开关,系统默认只对运行级3,4,5有效,但是reset可以对所有运行级有效。

参数用法:
–add  增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据。
–del  删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据。
–level<等级代号>  指定读系统服务要在哪一个执行等级中开启或关毕。
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动
需要说明的是,level选项可以指定要查看的运行级而不一定是当前运行级。对于每个运行级,只能有一个启动脚本或者停止脚本。当切换运行级时,init不会重新启动已经启动的服务,也不会再次去停止已经停止的服务。

chkconfig –list [name]:显示所有运行级系统服务的运行状态信息(on或off)。如果指定了name,那么只显示指定的服务在不同运行级的状态。
chkconfig –add name:增加一项新的服务。chkconfig确保每个运行级有一项启动(S)或者杀死(K)入口。如有缺少,则会从缺省的init脚本自动建立。
chkconfig –del name:删除服务,并把相关符号连接从/etc/rc[0-6].d删除。
chkconfig [–level levels] name:设置某一服务在指定的运行级是被启动,停止还是重置。

运行级文件:
每个被chkconfig管理的服务需要在对应的init.d下的脚本加上两行或者更多行的注释。第一行告诉chkconfig缺省启动的运行级以及启动和停止的优先级。如果某服务缺省不在任何运行级启动,那么使用 – 代替运行级。第二行对服务进行描述,可以用\ 跨行注释。
例如,random.init包含三行:
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
# higher quality random number generation.

使用范例:

chkconfig --list        #列出所有的系统服务
chkconfig --add httpd        #增加httpd服务
chkconfig --del httpd        #删除httpd服务
chkconfig --level httpd 2345 on        #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态
chkconfig --list        #列出系统所有的服务启动情况
chkconfig --list mysqld        #列出mysqld服务设置情况
chkconfig --level 35 mysqld on        #设定mysqld在等级3和5为开机运行服务,--level 35表示操作只在等级3和5执行,on表示启动,off表示关闭
chkconfig mysqld on        #设定mysqld在各等级为on,“各等级”包括2、3、4、5等级

如何增加一个服务:
1.服务脚本必须存放在/etc/ini.d/目录下;
2.chkconfig –add servicename
在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了;
3.chkconfig –level 35 mysqld on
修改服务的默认启动等级。

Leave a Comment

利用Linux命令find查找PHP木马

Linux本身相对Win来讲安全点,因为好多人不会命令,这就是优点啊!但网站现在开源的这么多,所以漏洞也相对较多,一不小心网站被上传木马也是常有的事情。
收集和整理了一下利用find命令来查找一下是否网站被种木马了,无非是根据木马的特征代码来配对。

find ./ -name "*.php" |xargs egrep "phpspy|c99sh|milw0rm|eval\(gunerpress|eval\(base64_decode|spider_bc"> /tmp/php.txt

grep -r –include=*.php  '[^a-z]eval($_POST' . > /tmp/eval.txt

grep -r –include=*.php  'file_put_contents(.*$_POST\[.*\]);' . > /tmp/file_put_contents.txt

find ./ -name "*.php" -type f -print0 | xargs -0 egrep "(phpspy|c99sh|milw0rm|eval\(gzuncompress\(base64_decode|eval\(base64_decode|spider_bc|gzinflate)" | awk -F: '{print $1}' | sort | uniq

查找最近一天被修改的PHP文件

find -mtime -1 -type f -name \*.php

修改网站php文件权限,只读

find -type f -name \*.php -exec chmod 444 {} \;

修改网站目录权限

find ./ -type d -exec chmod 555{} \;
Leave a Comment

Nginx 301重定向配置方法

有时候顶级域名不想使用,只想用www域名,那么需要做301重定向,在Nginx下的方法有以下两种我较常用的方法:

第一种方式建立一个kiccleaf.com.conf文件输入以下内容

server {
    listen 80;
    server_name  kiccleaf.com;
    location / {
            rewrite ^(.*) http://www.kiccleaf.com$1 permanent;
    }
}

第二种方式在原有的www.kiccleaf.com.conf文件里添加至server_name下一行(我个人一般采用这种方式,比较方便在一个配置文件中就可以解决了。)

server{
   listen 80;
   server_name www.kiccleaf.com kiccleaf.com ;
   if ($host != 'www.kiccleaf.com' ){
      rewrite ^/(.*)$ http://www.kiccleaf.com/$1 permanent;
   }
  ...
}
Leave a Comment

破解Linux系统Root密码

看到开机画面
1
开机进入如下画面时 ,按下任意键
2
按下e
3
选中上图所示第二项,按下e进入如下画面
4
输入single 或1 ,(没有r)
5
进入下图,按下b
6
出现如下画面时,输入 passwd root
7
进入下面画面,即可输入新密码.
8

Leave a Comment

配置Nginx多核CPU,worker_cpu_affinity方法

由于现今服务器的CPU基本是四核或是八核以上,Nginx默认是没有开启利用多核CPU,我们可以通过增加worker_cpu_affinity配置参数来充分利用多核CPU。实现高性能处理数据和利用CPU资源

1. 2核CPU,开启2个进程

worker_processes     2;
worker_cpu_affinity 01 10;

01表示启用第一个CPU内核,10表示启用第二个CPU内核
worker_cpu_affinity 01 10;表示开启两个进程,第一个进程对应着第一个CPU内核,第二个进程对应着第二个CPU内核。
2. 2核CPU,开启4个进程

worker_processes     4;
worker_cpu_affinity 01 10 01 10;

开启了四个进程,它们分别对应着开启2个CPU内核

3. 4核CPU,开户4个进程

worker_processes     4;
worker_cpu_affinity 0001 0010 0100 1000;

0001表示启用第一个CPU内核,0010表示启用第二个CPU内核,依此类推

4. 4核CPU,开启2个进程

worker_processes     2;
worker_cpu_affinity 0101 1010;

0101表示开启第一个和第三个内核,1010表示开启第二个和第四个内核

2个进程对应着四个内核

worker_cpu_affinity配置是写在/etc/nginx/nginx.conf里面的。

2核是 01,四核是0001,8核是00000001,有多少个核,就有几位数,1表示该内核开启,0表示该内核关闭。

5. 8核CPU,开户8个进程

worker_processes     8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

0001表示启用第一个CPU内核,0010表示启用第二个CPU内核,依此类推

worker_processes最多开启8个,8个以上性能提升不会再提升了,而且稳定性变得更低,所以8个进程够用了。

配置完毕后,重启nginx ,执行/etc/init.d/nginx restart 或是安装目录下:/nginx/sbin/nginx -s reload 重新加载

输入:top 命令后按 1 进行查看

Leave a Comment

Linux下c读取MysqL中文乱码解决方案

在编写接口API时,发现中文字utf8输入的在linux下采用c读取显示为”??”问号,这是由于编码造成的。很简单的两个地方做修改就搞定。
1.先找到mysql的my.cnf配置文件/etc/my.cnf编辑添加
[mysqld]
default-character-set=utf8

2.在程序中添加 mysql_set_character_set(&db,”utf8″); 语句
例子:kiccleaf.c 文件

#include <stdio.h>
//这里需要找到相应地址不知道可以用“ find / -name mysql.h ”查询
#include "/usr/include/mysql/mysql.h"
int main()
{
    MYSQL db;/*connector*/
    MYSQL_RES* result;/*result buffer*/
    MYSQL_ROW row;/*one row of the result*/
    int i;
    if(mysql_init(&db) ==NULL)
    {
      fprintf(stderr,"Fail to initialize the db.\n");
      return -1;
    }
    if(!mysql_real_connect(&db,"localhost","root","password","kiccleaf",3306,NULL,0))
    {
      fprintf(stderr,"Fail to connect to the server");
      return -1;
    }
    //添加字符集防止乱码
    mysql_set_character_set(&db,"utf8");
    if(mysql_query(&db,"SELECT * FROM user") != 0)
    {
      fprintf(stderr,"Fail to query the db for information.\n");
      return -1;
    }
    if ((result = mysql_store_result(&db)) == NULL)
    {
      fprintf(stderr,"Fail to get the result.\n");
      return -1;
    }

    while((row=mysql_fetch_row(result)) != NULL)/*fetching each row*/
    {
      puts("================================================");
      printf("id: %s\n",row[0]);
      printf("name: %s\n",row[1]);
      printf("pwd: %s\n",row[2]);
      printf("flag: %s\n",row[3]);
      puts("================================================");
    }

    mysql_free_result(result);
    mysql_close(&db);
    return 0;
}

编译时也会出现问题,可以添加参数 “-lz /usr/lib/mysql/libmysqlclient.so.15.0.0”

gcc -o kiccleaf -g kiccleaf.c -lz /usr/lib/mysql/libmysqlclient.so.15.0.0

原来乱码的情况

[root@kiccleaf c]# ./kiccleaf
================================================
id: 0000000001
name: ???
pwd: 123456
flag: 0
================================================
================================================
id: 0000000002
name: ???
pwd: 654123
flag: 0
================================================
================================================
id: 0000000003
name: ???
pwd: 789456
flag: 0
================================================
================================================
id: 0000000004
name: ???
pwd: 456321
flag: 0
================================================

添加字符集后输出结果:

[root@kiccleaf c]# ./kiccleaf
================================================
id: 0000000001
name: 测试1
pwd: 123456
flag: 0
================================================
================================================
id: 0000000002
name: 测试2
pwd: 654123
flag: 0
================================================
================================================
id: 0000000003
name: 测试3
pwd: 789456
flag: 0
================================================
================================================
id: 0000000004
name: 测试4
pwd: 456321
flag: 0
================================================
Leave a Comment

Linux X64下Nginx1.0.4无缝升级到新版本1.3.0版本操作方法[原创]

服务器近一年没有更新Nginx版本了,为了提高性能和稳定,采用了最新的Nginx版本。可以到http://nginx.org/en/download.html 进行下载。升级仅花了几分钟时间就搞定了。
注:以下代码是真实环境直接配置复制进来,可以根据代码从上至下进行操作配置。

[root@kiccleaf leaf]# wget http://nginx.org/download/nginx-1.3.0.tar.gz
[root@kiccleaf leaf]# tar -zxvf nginx-1.3.0.tar.gz
[root@kiccleaf leaf]# cd nginx-1.3.0
#如果需要服务器个性化名称可以修改
[root@kiccleaf nginx-1.3.0]# vi src/core/nginx.h
/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) Nginx, Inc.
 */


#ifndef _NGINX_H_INCLUDED_
#define _NGINX_H_INCLUDED_


#define nginx_version      1003000
#define NGINX_VERSION      "1.3.0"  #可修改成自己需要的版本
#define NGINX_VER          "Nginx/" NGINX_VERSION #可修改成自己需要服务的名称

#define NGINX_VAR          "NGINX"  #可修改成自己需要服务的名称
#define NGX_OLDPID_EXT     ".oldbin"


#endif /* _NGINX_H_INCLUDED_ */

#进行配置操作,根据自己的实际配置来,以下是我简单的配置

[root@kiccleaf nginx-1.3.0]# ./configure --user=www --group=www --add-module=../ngx_cache_purge-1.3 --prefix=/usr/local/nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
checking for OS
 + Linux 2.6.18-274.12.1.el5 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.1.2 20080704 (Red Hat 4.1.2-51)
…………………………编译代码省略………………
  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
[root@kiccleaf nginx-1.3.0]# make  #看清咯,只make,而不是make install,这里升级不需要install操作
make -f objs/Makefile
make[1]: Entering directory `/home/leaf/nginx-1.3.0'
…………………………编译代码省略………………
make[1]: Leaving directory `/home/leaf/nginx-1.3.0'
make -f objs/Makefile manpage
make[1]: Entering directory `/home/leaf/nginx-1.3.0'
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
		-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
		-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
		-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
		< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/home/leaf/nginx-1.3.0'

检查配置是否正确,这里出现了警告,因为从低版本升级至高版本产生了配置的问题

[root@kiccleaf nginx-1.3.0]# ./objs/nginx -t
nginx: [warn] the "log_format" directive may be used only on "http" level in /usr/local/nginx/conf/conf.d/www.kiccleaf.com.conf:22
nginx: [warn] the "log_format" directive may be used only on "http" level in /usr/local/nginx/conf/conf.d/www.qimutian.com.conf:22
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#升级后出现配置文件conf有错误,如果有其的虚拟主机开启了日志,也按要求移出server段放在server段的前面即可。
[root@kiccleaf nginx-1.3.0]# vi /usr/local/nginx/conf/conf.d/www.kiccleaf.com.conf
#把server里面的log_format代码拿到上面来,保存退出
    log_format  www_kiccleaf_com  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
server
{
    listen       80;
    server_name  www.kiccleaf.com;
    index index.html index.htm index.php;
    root  /data/kiccleaf;
    #limit_conn   crawler  20;    
                            
    location ~ .*\.(php|php5)?$
    {      
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fcgi.conf;
    }

#以下代码的问题,升级后需要把以下代码拿到server上面去。这里先注释掉
#    log_format  www_kiccleaf_com  '$remote_addr - $remote_user [$time_local] "$request" '
#             '$status $body_bytes_sent "$http_referer" '
#              '"$http_user_agent" $http_x_forwarded_for';
    access_log  /data/logs/www_kiccleaf_com.log www_kiccleaf_com;

}
[root@kiccleaf nginx-1.3.0]# /usr/local/nginx/sbin/nginx -t  #再检查,没有warn警告信息了
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

操作升级,出错误不管它

[root@kiccleaf nginx-1.3.0]# make upgrade #出现错误,就先不管它
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
cat: /usr/local/nginx/logs/nginx.pid: No such file or directory
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
make: *** [upgrade] Error 1

备份老的Nginx程序,复制新的过去

[root@kiccleaf nginx-1.3.0]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
mv: overwrite `/usr/local/nginx/sbin/nginx.old'? y
[root@kiccleaf nginx-1.3.0]# cp objs/nginx /usr/local/nginx/sbin/nginx
[root@kiccleaf nginx-1.3.0]# /usr/local/nginx/sbin/nginx -t #查看复制过去配置是否正确
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@kiccleaf nginx-1.3.0]# /usr/local/nginx/sbin/nginx -v  #再查看一下新版本,老的是1.0.4版本
nginx version: Nginx/1.3.0  #已经是新版本

无缝升级到新版本

[root@kiccleaf nginx-1.3.0]# kill -USR2 `cat /usr/local/nginx/nginx.pid` #
[root@kiccleaf nginx-1.3.0]# ps aux| grep nginx #查看一下进程
root      2169  0.0  0.0 248708  1788 ?        Ss    2011   0:00 nginx: master process /usr/local/nginx/sbin/nginx  #老的进程都是2011年开启的,嘿嘿
www       6891  0.0  0.3 274308 27796 ?        S    Apr20   0:13 nginx: worker process               
www       6892  0.0  0.3 274308 27616 ?        S    Apr20   0:13 nginx: worker process               
www       6893  0.0  0.3 274308 27596 ?        S    Apr20   0:13 nginx: worker process               
www       6894  0.0  0.3 274308 27612 ?        S    Apr20   0:13 nginx: worker process               
www       6895  0.0  0.3 274308 27608 ?        S    Apr20   0:15 nginx: worker process               
www       6896  0.0  0.3 274308 27796 ?        S    Apr20   0:15 nginx: worker process               
www       6897  0.0  0.3 274308 27700 ?        S    Apr20   0:15 nginx: worker process               
www       6898  0.0  0.3 274308 27600 ?        S    Apr20   0:12 nginx: worker process               
www       6899  0.0  0.3 274308 27592 ?        S    Apr20   0:13 nginx: worker process               
www       6900  0.0  0.3 274308 27620 ?        S    Apr20   0:13 nginx: worker process               
www       6901  0.0  0.3 274308 27616 ?        S    Apr20   0:14 nginx: worker process               
www       6902  0.0  0.3 274308 27652 ?        S    Apr20   0:11 nginx: worker process               
www       6903  0.0  0.3 274308 27856 ?        S    Apr20   0:13 nginx: worker process               
www       6904  0.0  0.3 274308 27608 ?        S    Apr20   0:15 nginx: worker process               
www       6905  0.0  0.3 274308 27644 ?        S    Apr20   0:12 nginx: worker process               
www       6906  0.0  0.3 274308 27612 ?        S    Apr20   0:16 nginx: worker process               
www       6907  0.0  0.0 248708  1500 ?        S    Apr20   0:00 nginx: cache manager process        
root     30293  0.0  0.0 248008  3764 ?        S    22:17   0:00 nginx: master process /usr/local/nginx/sbin/nginx
www      30294  0.0  0.3 273968 27524 ?        S    22:17   0:00 nginx: worker process               
www      30295  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30296  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30297  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30298  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30299  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30300  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30301  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30302  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30303  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30304  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30305  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30306  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30307  0.0  0.3 273936 27392 ?        S    22:17   0:00 nginx: worker process               
www      30308  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30309  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30310  0.0  0.0 248188  1396 ?        S    22:17   0:00 nginx: cache manager process        
root     30316  0.0  0.0  61172   800 pts/1    S+   22:36   0:00 grep nginx

原来存放nginx.pid的目录下自动出现了nginx.pid.oldbin。现在新的和旧的一起在提供服务,我们执行一下命令把老的进程给Kill掉就可以了。

[root@kiccleaf nginx-1.3.0]# kill -QUIT `cat /usr/local/nginx/nginx.pid.oldbin` 
[root@kiccleaf nginx-1.3.0]# ps aux| grep nginx #现在查看进程只有新的了
root     30293  0.0  0.0 248720  3924 ?        S    22:17   0:00 nginx: master process /usr/local/nginx/sbin/nginx
www      30332  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30333  0.1  0.3 274320 27552 ?        S    22:43   0:00 nginx: worker process               
www      30334  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30335  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30336  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30337  0.1  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30338  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30339  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30340  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30341  0.1  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30342  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30343  0.1  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30344  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30345  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30346  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30347  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30348  0.0  0.0 248720  1400 ?        S    22:43   0:00 nginx: cache manager process        
root     30418  0.0  0.0  61172   796 pts/1    S+   22:45   0:00 grep nginx

好了进行访问网站,是不是正常不间断切换至最新的Nginx版本了!

Leave a Comment

Linux CentOS系统crontab运行定时任务

一般情况下,系统默认都已经安装好,如果发现不能使用可以用以下命令进行安装
yum install crontabs

说明:
/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置

1,crontab命令

功能说明:设置计时器。

语  法:crontab [-u <用户名称>][配置文件] 或 crontab [-u <用户名称>][-elr]

补充说明:cron是一个常驻服务,它提供计时器的功能,让用户在特定的时间得以执行预设的指令或程序。只要用户会编辑计时器的配置文件,就可以使 用计时器的功能。其配置文件格式如下:
Minute Hour Day Month DayOFWeek Command

参  数:
-e  编辑该用户的计时器设置。
-l  列出该用户的计时器设置。
-r  删除该用户的计时器设置。
-u<用户名称>  指定要设定计时器的用户名称。

2,crontab 格式

基本格式 :
* *  *  *  *  command
分 时 日 月 周  命令

第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列 表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令

# Use the hash sign to prefix a comment
# +---------------- minute (0 - 59)
# |  +------------- hour (0 - 23)
# |  |  +---------- day of month (1 - 31)
# |  |  |  +------- month (1 - 12)
# |  |  |  |  +---- day of week (0 - 7) (Sunday=0 or 7)
# |  |  |  |  |
# *  *  *  *  *  command to be executed

配备自己的任务
crontab -e

然后输入自己执行的Shell文件地址或是可执行文件的地址

查看任务
crontab -l

网络上找的和自己写的一些crontab文件的例子:
每天00:00做nginx日志切割
00 00 * * * /bin/bash /data/cut_nginx_log.sh

59 23 * * * /etc/init.d/nginx restart
每晚的23:59重启 nginx。

45 4 1,10,22 * * /etc/init.d/nginx restart
每月1、 10、22日的4 : 45重启nginx。

10 1 * * 6,0 /etc/init.d/nginx restart
每周六、周日的1 : 10重启nginx。

0,30 18-23 * * * /etc/init.d/nginx restart
每天18 : 00至23 : 00之间每隔30分钟重启nginx。

0 23 * * 6 /etc/init.d/nginx restart
每星期六的11 : 00 pm重启nginx。

* */1 * * * /etc/init.d/nginx restart
每一小时重启nginx

* 23-7/1 * * * /etc/init.d/nginx restart
晚上11点到早上7点之间,每 隔一小时重启nginx

0 11 4 * mon-wed /etc/init.d/nginx restart
每月的4号与每周一到周三 的11点重启nginx

0 4 1 jan * /etc/init.d/nginx restart
一月一号的4点重启nginx

*/30 * * * * /usr/sbin/ntpdate 210.72.145.20
每半小时同步一下时间

Leave a Comment

采用Linux性能监测工具dstat来分析系统资源情况

日常管理中使用需要经常查看服务器状态和性能,比如IO占用情况,及内存使用情况,硬盘,CPU等等。网络上搜罗了一下,这个dstat软件还是比较不错能满足日常分析。本人采用的是X64系统,在CentOS6.2系统下采用yum进行安装dstat软件
默认情况它会收集 cpu、disk、net、paging、system 数据,一秒钟收集一次

[root@kiccleaf ~]# dstat  #运行命令是否已经安装
-bash: dstat: command not found   #没有找到此命令
[root@kiccleaf ~]# yum install dstat   #进行安装
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
base                                            | 3.7 kB     00:00     
extras                                          | 3.5 kB     00:00     
updates                                         | 3.5 kB     00:00     
updates/primary_db                              | 654 kB     00:02     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package dstat.noarch 0:0.7.0-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================
 Package       Arch           Version               Repository    Size
=======================================================================
Installing:
 dstat         noarch         0.7.0-1.el6           base         144 k

Transaction Summary
=======================================================================
Install       1 Package(s)

Total download size: 144 k
Installed size: 660 k
Is this ok [y/N]: y  #输入y进行安装
Downloading Packages:
dstat-0.7.0-1.el6.noarch.rpm                    | 144 kB     00:01     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : dstat-0.7.0-1.el6.noarch                            1/1 

Installed:
  dstat.noarch 0:0.7.0-1.el6                                           

Complete!
[root@kiccleaf ~]# dstat -d   #查看硬盘IO操作
-dsk/total-
 read  writ
 861k   90k
   0     0 
   0    68k
4096B 1216k
   0   112k
[root@kiccleaf ~]# dstat -h   #查看帮助文档
Usage: dstat [-afv] [options..] [delay [count]]
Versatile tool for generating system resource statistics

Dstat options:
  -c, --cpu              enable cpu stats 显示CPU情况
     -C 0,3,total           include cpu0, cpu3 and total
  -d, --disk             enable disk stats 显示磁盘情况
     -D total,hda           include hda and total
  -g, --page             enable page stats
  -i, --int              enable interrupt stats
     -I 5,eth2              include int5 and interrupt used by eth2
  -l, --load             enable load stats
  -m, --mem              enable memory stats 显示内存情况
  -n, --net              enable network stats 显示网络情况
     -N eth1,total          include eth1 and total 可以指定网络接口
  -p, --proc             enable process stats
  -r, --io               enable io stats (I/O requests completed)
  -s, --swap             enable swap stats 显示swap情况
     -S swap1,total         include swap1 and total 可以指定多个swap
  -t, --time             enable time/date output
  -T, --epoch            enable time counter (seconds since epoch)
  -y, --sys              enable system stats

  --aio                  enable aio stats
  --fs, --filesystem     enable fs stats
  --ipc                  enable ipc stats 报告IPC消息队列和信号量的使用情况
  --lock                 enable lock stats
  --raw                  enable raw stats
  --socket               enable socket stats
  --tcp                  enable tcp stats
  --udp                  enable udp stats
  --unix                 enable unix stats
  --vm                   enable vm stats

  --plugin-name          enable plugins by plugin name (see manual)
  --list                 list all available plugins

  -a, --all              equals -cdngy (default) 使用-cdngy 缺省的就是这样显示
  -f, --full             automatically expand -C, -D, -I, -N and -S lists 使用 -C, -D, -I, -N and -S 显示
  -v, --vmstat           equals -pmgdsc -D total 使用-pmgdsc -D 显示

  --bw, --blackonwhite   change colors for white background terminal
  --float                force float values on screen
  --integer              force integer values on screen
  --nocolor              disable colors (implies --noupdate)
  --noheaders            disable repetitive headers 只显示一次表头以后就不显示了,使用重定向写入文件时很有用
  --noupdate             disable intermediate updates
  --output file          write CSV output to file

delay is the delay in seconds between each update (default: 1)
count is the number of updates to display before exiting (default: unlimited)

较为长用的命令,来观察系统运行情况
#如果你想10秒收集一次,就输入: dstat -cdlmnpsy 10

[root@kiccleaf ~]# dstat -cdlmnpsy
----total-cpu-usage---- -dsk/total- ---load-avg--- ------memory-usage----- -net/total- ---procs--- ----swap--- ---system--
usr sys idl wai hiq siq| read  writ| 1m   5m  15m | used  buff  cach  free| recv  send|run blk new| used  free| int   csw 
  0   0  99   0   0   0| 104k   14k|   0    0    0|66.9M 8332k 81.5M  837M|   0     0 |  0   0 1.3|   0  2016M|  65    44 
  0   0 100   0   0   0|   0     0 |   0    0    0|66.9M 8332k 81.5M  837M|  60B 1354B|  0   0   0|   0  2016M|  28    17 
  0   0 100   0   0   0|   0     0 |   0    0    0|66.9M 8332k 81.5M  837M|  60B  522B|  0   0   0|   0  2016M|  24    17 
  0   0 100   0   0   0|   0     0 |   0    0    0|66.9M 8332k 81.5M  837M|  60B  522B|  0   0   0|   0  2016M|  27    18 
  0   0 100   0   0   0|   0     0 |   0    0    0|66.9M 8332k 81.5M  837M| 552B  522B|  0   0   0|   0  2016M|  28    23 
  0   0 100   0   0   0|   0     0 |   0    0    0|66.9M 8332k 81.5M  837M|  60B  522B|  0   0   0|   0  2016M|  26    17 
  0   0 100   0   0   0|   0     0 |   0    0    0|66.9M 8332k 81.5M  837M| 491B  522B|  0   0   0|   0  2016M|  31    17

统计CPU,IO ,network,system load

[root@kiccleaf ~]# dstat -cndymlp -N total -D total 5 25
----total-cpu-usage---- -net/total- -dsk/total- ---system-- ------memory-usage----- ---load-avg--- ---procs---
usr sys idl wai hiq siq| recv  send| read  writ| int   csw | used  buff  cach  free| 1m   5m  15m |run blk new
  0   0  99   0   0   0|   0     0 |  96k   13k|  62    42 |66.8M 8332k 81.5M  837M|   0    0    0|  0   0 1.2
  0   0 100   0   0   0| 218B  636B|   0     0 |  27    19 |66.9M 8332k 81.5M  837M|   0    0    0|  0   0   0
  0   0 100   0   0   0| 242B  477B|   0     0 |  29    18 |66.9M 8332k 81.5M  837M|   0    0    0|  0   0   0
  0   0 100   0   0   0| 324B  479B|   0     0 |  28    18 |66.9M 8332k 81.5M  837M|   0    0    0|  0   0   0

统计网卡1的信息

[root@kiccleaf ~]# dstat -cdnsil -D hda -N eth1
Module dstat_disk24old failed to load. (No suitable block devices found to monitor)
Module dstat_net failed to load. (No suitable network interfaces found to monitor)
----total-cpu-usage---- ----swap--- ----interrupts--- ---load-avg---
usr sys idl wai hiq siq| used  free|  17    18    19 | 1m   5m  15m 
  0   0  99   0   0   0|   0  2016M|   4     0     3 |   0    0    0
  0   0 100   0   0   0|   0  2016M|   0     0     3 |   0    0    0
  0   0 100   0   0   0|   0  2016M|   0     0     4 |   0    0    0
  0   0 100   0   0   0|   0  2016M|   0     0     3 |   0    0    0
  0   0 100   0   0   0|   0  2016M|   0     0     4 |   0    0    0

内存使用情况

[root@kiccleaf ~]# dstat -vmstat
Terminal width too small, trimming output.
---procs--- ------memory-usage----- ---paging-- -dsk/total- ---system-- ----total-cpu-usage---- ------memory-usage----- ----swap--- ----system---- ----total-cpu-usage---->
run blk new| used  buff  cach  free|  in   out | read  writ| int   csw |usr sys idl wai hiq siq| used  buff  cach  free| used  free|  date/time   |usr sys idl wai hiq siq>
0.0   0 1.1|66.8M 8332k 81.5M  837M|   0     0 |  88k   12k|  59    40 |  0   0  99   0   0   0|66.8M 8332k 81.5M  837M|   0  2016M|05-01 21:52:57|  0   0  99   0   0   0>
  0   0   0|66.8M 8340k 81.5M  837M|   0     0 |   0    12k|  40    27 |  0   0 100   0   0   0|66.8M 8340k 81.5M  837M|   0  2016M|05-01 21:52:58|  0   0 100   0   0   0>
  0   0   0|66.8M 8340k 81.5M  837M|   0     0 |   0     0 |  31    21 |  0   0 100   0   0   0|66.8M 8340k 81.5M  837M|   0  2016M|05-01 21:52:59|  0   0 100   0   0   0>
  0   0   0|66.8M 8340k 81.5M  837M|   0     0 |   0     0 |  28    16 |  0   0 100   0   0   0|66.8M 8340k 81.5M  837M|   0  2016M|05-01 21:53:00|  0   0 100   0   0   0>
  0   0   0|66.8M 8340k 81.5M  837M|   0     0 |   0     0 |  36    19 |  0   0 100   0   0   0|66.8M 8340k 81.5M  837M|   0  2016M|05-01 21:53:01|  0   0 100   0   0   0>

Leave a Comment