Press "Enter" to skip to content

分类: Linux

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

php编译中遇到error解决办法![转]

在编译php的过程中,经常会出现一些错误信息,网络上搜索了一下还是比较有用的,收藏一下!

1) Configure: error: xml2-config not found. Please check your libxml2 installation.
Solutions :
Quote:
#yum install libxml2 libxml2-devel (For Redhat & Fedora)
# aptitude install libxml2-dev      (For ubuntu)

2) Checking for pkg-config… /usr/bin/pkg-config 
configure: error: Cannot find OpenSSL’s <evp.h>
Solutions :
Quote:
#yum install openssl openssl-devel

3) Configure: error: Please reinstall the BZip2 distribution
Solutions :
Quote:
# yum install bzip2 bzip2-devel

4) Configure: error: Please reinstall the libcurl distribution - 
easy.h should be in <curl-dir>/include/curl/
Solutions :
Quote:
# yum install curl curl-devel   (For Redhat & Fedora)
# install libcurl4-gnutls-dev    (For Ubuntu) 

5) Configure: error: libjpeg.(also) not found.
Solutions :
Quote:
# yum install libjpeg libjpeg-devel

6) Configure: error: libpng.(also) not found.
Solutions :
Quote:
# yum install libpng libpng-devel

7) Configure: error: freetype.h not found. 
Solutions :
Quote:
#yum install freetype-devel

8) Configure: error: Unable to locate gmp.h
Solutions :
Quote:
# yum install gmp-devel

9) Configure: error: Cannot find MySQL header files under /usr. 
Note that the MySQL client library is not bundled anymore!
Solutions :
Quote:
# yum install mysql-devel            (For Redhat & Fedora)
# apt-get install libmysql++-dev      (For Ubuntu) 

10) Configure: error: Please reinstall the ncurses distribution
Solutions :
Quote:
# yum install ncurses ncurses-devel

11) Checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!
Solutions :
Quote:
# yum install unixODBC-devel

12) Configure: error: Cannot find pspell
Solutions :
Quote:
# yum install pspell-devel

13) configure: error: mcrypt.h not found. Please reinstall libmcrypt.
Solutions :
Quote:
# yum install libmcrypt libmcrypt-devel    (For Redhat & Fedora)
# apt-get install libmcrypt-dev 

14) Configure: error: snmp.h not found. Check your SNMP installation.
Solutions :
Quote:
# yum install net-snmp net-snmp-devel

15)configure: error: Please reinstall libmhash – I cannot find mhash.h
#yum install mhash-devel
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