测试环境目录结构:
/root/test/
/root/test/567/
/root/test/hello.txt
/root/test/123/
/root/test/456/
/root/test/456/wooooo.txt
/root/test/456/adfasdf.txt

现排除/root/test/456/目录下文件不进行压缩:
1. tar czvf test.tar.gz  /root/test/ --exclude /root/test/456/*
2.创建list文件,将/root/test/456写入该文件,如果还有其他目录一行条
tar czvf test.tar.gz  /root/test/ --exclude-from list

分卷压缩:
tar cvf test.tar.gz  /root/test/  --multi-volume --tape-length=10240 --file=1.tar --file=2.tar --file=3.tar
不能加z参数,分卷压缩不支持gzip.--file=的个数根据需要备份的容量来决定,比如需要打包的有450MB,每个包为100MB的话,就要有5个--file

Posted by microsea


Trackback URL : 无法向此文章发送引用

nginx用fastcgi方式运行perl脚本(转)

 

一、制作perl的fast cgi 接口文件

先在/bin目录下放置一个perl写的分发器,取名叫perl-fcgi

cat >>perl-fcgi<<'EOF'
 
#!/usr/bin/perl -w
use FCGI;
use Socket;
use FCGI::ProcManager;
sub shutdown { FCGI::CloseSocket($socket); exit; }
sub restart  { FCGI::CloseSocket($socket); &main; }
use sigtrap 'handler', \&shutdown, 'normal-signals';
use sigtrap 'handler', \&restart,  'HUP';
require 'syscall.ph';
use POSIX qw(setsid);
 
#&daemonize; we don't daemonize when running under runsv
#this keeps the program alive or something after exec'ing perl scripts
END()   { }
BEGIN() { }
{
    no warnings;
    *CORE::GLOBAL::exit = sub { die "fakeexit\nrc=" . shift() . "\n"; };
};
eval q{exit};
if ($@) {
    exit unless $@ =~ /^fakeexit/;
}
&main;
 
sub daemonize() {
    chdir '/' or die "Can't chdir to /: $!";
    defined( my $pid = fork ) or die "Can't fork: $!";
    exit if $pid;
    setsid() or die "Can't start a new session: $!";
    umask 0;
}
 
sub main {
 
     $socket = FCGI::OpenSocket( "127.0.0.1:10081", 10 ); #use IP sockets
    #$socket = FCGI::OpenSocket( "/var/run/nginx/perl_cgi-dispatch.sock", 10 ); 
    #use UNIX sockets - user running this script must have w access to the 'nginx' folder!!
    #foreach $item (keys %ENV) { delete $ENV{$item}; }
    $proc_manager = FCGI::ProcManager->new( {n_processes => 5} );
    #$socket = FCGI::OpenSocket( "/opt/nginx/fcgi/cgi.sock", 10 )
        ; #use UNIX sockets - user running this script must have w access to the 'nginx' folder!!
    $request =
        FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%req_params, $socket,
        &FCGI::FAIL_ACCEPT_ON_INTR );
    $proc_manager->pm_manage();
    if ($request) { request_loop() }
    FCGI::CloseSocket($socket);
}
 
sub request_loop {
    while ( $request->Accept() >= 0 ) {
        $proc_manager->pm_pre_dispatch();
 
        #processing any STDIN input from WebServer (for CGI-POST actions)
        $stdin_passthrough = '';
        { no warnings; $req_len = 0 + $req_params{'CONTENT_LENGTH'}; };
        if ( ( $req_params{'REQUEST_METHOD'} eq 'POST' ) && ( $req_len != 0 ) )
        {
            my $bytes_read = 0;
            while ( $bytes_read < $req_len ) {
                my $data = '';
                my $bytes = read( STDIN, $data, ( $req_len - $bytes_read ) );
                last if ( $bytes == 0 || !defined($bytes) );
                $stdin_passthrough .= $data;
                $bytes_read += $bytes;
            }
        }
 
        #running the cgi app
        if (
            ( -x $req_params{SCRIPT_FILENAME} ) &&    #can I execute this?
            ( -s $req_params{SCRIPT_FILENAME} ) &&    #Is this file empty?
            ( -r $req_params{SCRIPT_FILENAME} )       #can I read this file?
            )
        {
            pipe( CHILD_RD,   PARENT_WR );
            pipe( PARENT_ERR, CHILD_ERR );
            my $pid = open( CHILD_O, "-|" );
            unless ( defined($pid) ) {
                print("Content-type: text/plain\r\n\r\n");
                print
"Error: CGI app returned no output - Executing $req_params{SCRIPT_FILENAME} failed !\n";
                next;
            }
            $oldfh = select(PARENT_ERR);
            $|     = 1;
            select(CHILD_O);
            $| = 1;
            select($oldfh);
            if ( $pid > 0 ) {
                close(CHILD_RD);
                close(CHILD_ERR);
                print PARENT_WR $stdin_passthrough;
                close(PARENT_WR);
                $rin = $rout = $ein = $eout = '';
                vec( $rin, fileno(CHILD_O),    1 ) = 1;
                vec( $rin, fileno(PARENT_ERR), 1 ) = 1;
                $ein    = $rin;
                $nfound = 0;
 
                while ( $nfound =
                    select( $rout = $rin, undef, $ein = $eout, 10 ) )
                {
                    die "$!" unless $nfound != -1;
                    $r1 = vec( $rout, fileno(PARENT_ERR), 1 ) == 1;
                    $r2 = vec( $rout, fileno(CHILD_O),    1 ) == 1;
                    $e1 = vec( $eout, fileno(PARENT_ERR), 1 ) == 1;
                    $e2 = vec( $eout, fileno(CHILD_O),    1 ) == 1;
 
                    if ($r1) {
                        while ( $bytes = read( PARENT_ERR, $errbytes, 4096 ) ) {
                            print STDERR $errbytes;
                        }
                        if ($!) {
                            $err = $!;
                            die $!;
                            vec( $rin, fileno(PARENT_ERR), 1 ) = 0
                                unless ( $err == EINTR or $err == EAGAIN );
                        }
                    }
                    if ($r2) {
                        while ( $bytes = read( CHILD_O, $s, 4096 ) ) {
                            print $s;
                        }
                        if ( !defined($bytes) ) {
                            $err = $!;
                            die $!;
                            vec( $rin, fileno(CHILD_O), 1 ) = 0
                                unless ( $err == EINTR or $err == EAGAIN );
                        }
                    }
                    last if ( $e1 || $e2 );
                }
                close CHILD_RD;
                close PARENT_ERR;
                waitpid( $pid, 0 );
            } else {
                foreach $key ( keys %req_params ) {
                    $ENV{$key} = $req_params{$key};
                }
 
                # cd to the script's local directory
                if ( $req_params{SCRIPT_FILENAME} =~ /^(.*)\/[^\/]+$/ ) {
                    chdir $1;
                }
                close(PARENT_WR);
 
                #close(PARENT_ERR);
                close(STDIN);
                close(STDERR);
 
                #fcntl(CHILD_RD, F_DUPFD, 0);
                syscall( &SYS_dup2, fileno(CHILD_RD),  0 );
                syscall( &SYS_dup2, fileno(CHILD_ERR), 2 );
 
                #open(STDIN, "<&CHILD_RD");
                exec( $req_params{SCRIPT_FILENAME} );
                die("exec failed");
            }
        } else {
            print("Content-type: text/plain\r\n\r\n");
            print
"Error: No such CGI app - $req_params{SCRIPT_FILENAME} may not exist or is not executable by this process.\n";
        }
    }
}
 
EOF

给这个脚本执行权限

chmod +x  /bin/perl-fcgi

然后试试看能否启动

/bin/perl-fcgi &

如果遇到错误Can’t locate FCGI.pm,那么执行下面的命令

perl -MCPAN -e 'install FCGI'
perl -MCPAN -e 'install FCGI::ProcManager'
cd /usr/include; h2ph *.h */*.h

第一、二条命令是给perl安装FCGI模块,第三条是注册perl能识别的头文件,然后重新执行/bin/perl-fcgi, 如果正常的话,那么执行:

netstat -tunlp

应该可以看到这样的结果

[root@www Ext]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN      23923/couriertcpd
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      21582/nginx
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      18358/proftpd: (acc
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      14290/sshd
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      23746/master
tcp        0      0 127.0.0.1:10080             0.0.0.0:*                   LISTEN      5602/php-cgi
tcp        0      0 127.0.0.1:10081             0.0.0.0:*                   LISTEN      5640/perl
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      17582/mysqld
[root@www Ext]#

检查无误后用下面的命令正式启动这个分发器

/bin/perl-fcgi > /dev/null 2>&1 &

/dev/null是一个吞噬任何东西的虚设备
0是标准输入,1是标准输出,2是错误信息输出。2>&1是指将错误信息转到标准输出,然后标准输出到/dev/null

上面的方式启动后perl-fcgi是以执行它的用户身份运行的,对于web程序来说这是很不利的。老外用perl写了一个脚本Noah Friedman可以用指定的用户来运行某个程序,源程序在这里,这里也贴出来方便查阅

cat >>/sbin/runas<<'EOF'
 
#!/bin/sh
exec ${PERL-perl} -Swx $0 ${1+"$@"}
#!perl		  [perl will skip all lines in this file before this line]
 
# with --- run program with special properties
 
# Copyright (C) 1995, 2000, 2002 Noah S. Friedman
 
# Author: Noah Friedman <friedman@splode.com>
# Created: 1995-08-14
 
# $Id: with,v 1.12 2004/02/16 22:51:49 friedman Exp $
 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can either send email to this
# program's maintainer or write to: The Free Software Foundation,
# Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
 
# Commentary:
 
# TODO: create optional socket streams for stdin or stdout before invoking
# subprocess.
 
# Code:
 
use Getopt::Long;
use POSIX qw(setsid);
use Symbol;
use strict;
 
(my $progname = $0) =~ s|.*/||;
my $bgfn;
my $bgopt = 0;
 
my $opt_cwd;
my $opt_egid;
my $opt_euid;
my $opt_gid;
my $opt_groups;
my @opt_include;
my $opt_name;
my $opt_pgrp;
my $opt_priority;
my $opt_root;
my $opt_uid;
my $opt_umask;
my $opt_foreground = 0;
 
sub err
{
  my $fh = (ref ($_[0]) ? shift : *STDERR{IO});
  print $fh join (": ", $progname, @_), "\n";
  exit (1);
}
 
sub get_includes
{
  unshift @INC, @_;
  push (@INC,
        "$ENV{HOME}/lib/perl",
        "$ENV{HOME}/lib/perl/include");
 
  eval { require "syscall.ph" } if defined $opt_groups;
}
 
sub numberp
{
  defined $_[0] && $_[0] =~ m/^-?\d+$/o;
}
 
sub group2gid
{
  my $g = shift;
  return $g if numberp ($g);
  my $gid = getgrnam ($g);
  return $gid if defined $gid && numberp ($gid);
  err ($g, "no such group");
}
 
sub user2uid
{
  my $u = shift;
  return $u if numberp ($u);
  my $uid = getpwnam ($u);
  return $uid if defined $uid && numberp ($uid);
  err ($u, "no such user");
}
 
sub set_cwd
{
  my $d = shift;
  chdir ($d) || err ("chdir", $d, $!);
}
 
sub set_egid
{
  my $sgid = group2gid (shift);
  my $egid = $) + 0;
 
  $) = $sgid;
  err ($sgid, "cannot set egid", $!) if ($) == $egid && $egid != $sgid);
}
 
sub set_gid
{
  my $sgid = group2gid (shift);
  my $rgid = $( + 0;
  my $egid = $) + 0;
 
  $( = $sgid;
  $) = $sgid;
  err ($sgid, "cannot set rgid", $!) if ($( == $rgid && $rgid != $sgid);
  err ($sgid, "cannot set egid", $!) if ($) == $egid && $egid != $sgid);
}
 
sub big_endian_p
{
  my $x = 1;
  my @y = unpack ("c2", pack ("i", $x));
  return ($y[0] == 1) ? 0 : 1;
}
 
# This function is more complex than it ought to be because perl does not
# export the setgroups function.  It exports the getgroups function by
# making $( and $) return multiple values in the form of a space-separated
# string, but you cannot *set* the group list by assigning those variables.
# There is no portable way to determine what size gid_t is, so we must guess.
sub set_groups
{
  my @glist = sort { $a <=> $b } map { group2gid ($_) } split (/[ ,]/, shift);
 
  my $expected = join (" ", $(+0, reverse @glist);
  my @p = (big_endian_p() ? ("n", "N", "i") : ("v", "V", "i"));
 
  for my $c (@p)
    {
      err ("setgroups", $!)
        if (syscall (&SYS_setgroups, @glist+0, pack ("$c*", @glist)) == -1);
      return if ("$(" eq $expected);
    }
  err ("setgroups", "Could not determine gid_t");
}
 
sub set_pgrp
{
  setpgrp ($$, shift) || err ("setpgrp", $!);
}
 
sub set_priority
{
  my $prio = shift () + 0;
  setpriority (0, 0, $prio) || err ("setpriority", $prio, $!);
}
 
sub set_root
{
  my $d = shift;
  chroot ($d) || err ("chroot", $d, $!);
  chdir ("/");
}
 
sub set_euid
{
  my $suid = user2uid (shift);
  my $euid = $>;
 
  $> = $suid;
  err ($suid, "cannot set euid", $!) if ($> == $euid && $euid != $suid);
}
 
sub set_uid
{
  my $suid = user2uid (shift);
  my $ruid = $<;
  my $euid = $>;
 
  $< = $suid;
  $> = $suid;
  err ($suid, "cannot set ruid", $!) if ($< == $ruid && $ruid != $suid);
  err ($suid, "cannot set euid", $!) if ($> == $euid && $euid != $suid);
}
 

sub background
{
  my $pid = fork;
  die "$@" if $pid < 0;
  if ($pid == 0)
    {
      # Backgrounded programs may expect to be able to read input from the
      # user if stdin is a tty, but we will no longer have any job control
      # management because of the double fork and exit.  This can result in
      # a program either blocking on input (if still associated with a
      # controlling terminal) and stopping, or stealing input from a
      # foreground process (e.g. a shell).  So redirect stdin to /dev/null.
      open (STDIN, "< /dev/null") if (-t STDIN);
      return *STDERR{IO};
    }
 
  exit (0) unless $opt_foreground;
  wait;
  exit ($?);
}
 
sub dosetsid
{
  background ();
  setsid (); # dissociate from controlling terminal
  return *STDERR{IO};
}
 
sub daemon
{
  # Don't allow any file descriptors, including stdin, stdout, or
  # stderr to be propagated to children.
  $^F = -1;
  dosetsid ();
  # Duped in case we've closed stderr but can't exec anything.
  my $saved_stderr = gensym;
  open ($saved_stderr, ">&STDERR");
  close (STDERR);
  close (STDOUT);
  close (STDIN);
  return $saved_stderr;
}
 
sub notty
{
  # Don't allow any file descriptors other than stdin, stdout, or stderr to
  # be propagated to children.
  $^F = 2;
  dosetsid ();
  # Duped in case we've closed stderr but can't exec anything.
  my $saved_stderr = gensym;
  open ($saved_stderr, ">&STDERR");
  open (STDIN,  "+</dev/null");
  open (STDERR, "+<&STDIN");
  open (STDOUT, "+<&STDIN");
  return $saved_stderr;
}
 

sub set_bg_option
{
  my %bgfntbl =
    ( 1 => \&background,
      2 => \&daemon,
      4 => \&notty,
      8 => \&dosetsid,
    );
 
  $bgopt = $_[0];
  $bgfn  = $bgfntbl{$bgopt};
}
 
sub parse_options
{
  Getopt::Long::config (qw(bundling autoabbrev require_order));
  my $succ = GetOptions
    ("h|help",          sub { usage () },
     "c|cwd=s",         \$opt_cwd,
     "d|display=s",     \$ENV{DISPLAY},
     "H|home=s",        \$ENV{HOME},
     "G|egid=s",        \$opt_egid,
     "g|gid=s",         \$opt_gid,
     "I|include=s@",    \@opt_include,
     "l|groups=s",      \$opt_groups,
     "m|umask=s",       \$opt_umask,
     "n|name=s",        \$opt_name,
     "P|priority=i",    \$opt_priority,
     "p|pgrp=i",        \$opt_pgrp,
     "r|root=s",        \$opt_root,
     "U|euid=s",        \$opt_euid,
     "u|uid=s",         \$opt_uid,
 
     "f|fg|foreground", \$opt_foreground,
 
     "b|bg|background", sub { set_bg_option (1); $opt_foreground = 0 },
     "a|daemon|demon",  sub { set_bg_option (2) },
     "N|no-tty|notty",  sub { set_bg_option (4) },
     "s|setsid",        sub { set_bg_option (8) },
    );
  usage () unless $succ;
 
  my $n = 0;
  do { $n++ if $bgopt & 1 } while ($bgopt >>= 1);
  err ("Can only specify one of --background, --daemon, --notty, or --setsid")
    if ($n > 1);
}
 
sub usage
{
  print STDERR "$progname: @_\n\n" if @_;
  print STDERR "Usage: $progname {options} [command {args...}]\n
Options are:
-h, --help            You're looking at it.
-D, --debug           Turn on interactive debugging in perl.
-I, --include   DIR   Include DIR in \@INC path for perl.
                      This option may be specified multiple times to append
                      search paths to perl.
 
-d, --display   DISP  Run with DISP as the X server display.
-H, --home      HOME  Set \$HOME.
-n, --name      ARGV0 Set name of running program (argv[0]).
 
-c, --cwd       DIR   Run with DIR as the current working directory.
                      This directory is relative to the root directory as
                      specified by \`--root', or \`/'.
-r, --root      ROOT  Set root directory (via \`chroot' syscall) to ROOT.
 
-G, --egid      EGID  Set \`effective' group ID.
-g, --gid       GID   Set both \`real' and \`effective' group ID.
-l, --groups    GLIST Set group list to comma-separated GLIST.
-U, --euid      EUID  Set \`effective' user ID.
-u, --uid       UID   Set both \`real' and \`effective' user ID.
 
-m, --umask     UMASK Set umask.
-P, --priority  NICE  Set scheduling priority to NICE (-20 to 20).
-p, --pgrp      PGRP  Set process group.
 
The following options cause the resulting process to be backgrounded
automatically but differ in various ways:
 
-b, --background      Run process in background.  This is the default with
                      the --daemon, --no-tty, and --setsid options.
 
-f, --foreground      Do not put process into the background when using
                      the --daemon, --no-tty, and --setsid options.
                      In all other cases the default is to remain in the
                      foreground.
 
-a, --daemon          Run process in \"daemon\" mode.
                      This closes stdin, stdout, and stderr, dissociates
                      the process from any controlling terminal, and
                      backgrounds the process.
 
-N, --no-tty          Run process in background with no controlling
                      terminal and with stdin, stdout, and stderr
                      redirected to /dev/null.
 
-s, --setsid          Dissociate from controlling terminal.
                      This automatically backgrounds the process but
                      does not redirect any file descriptors.\n";
  exit (1);
}
 
sub main
{
  parse_options ();
  usage () unless @ARGV;
 
  get_includes (@opt_include);
 
  umask        (oct ($opt_umask)) if defined $opt_umask;
  set_gid      ($opt_gid)         if defined $opt_gid;
  set_egid     ($opt_egid)        if defined $opt_egid;
  set_groups   ($opt_groups)      if defined $opt_groups;
  set_root     ($opt_root)        if defined $opt_root;
  set_cwd      ($opt_cwd)         if defined $opt_cwd;
  set_priority ($opt_priority)    if defined $opt_priority;
  set_uid      ($opt_uid)         if defined $opt_uid;
  set_euid     ($opt_euid)        if defined $opt_euid;
 
  my $stderr = $bgfn ? &$bgfn () : *STDERR{IO};
 
  my $runprog = $ARGV[0];
  if ($opt_name)
    {
      shift   @ARGV;
      unshift @ARGV, $opt_name;
    }
  local $^W = 0; # avoid implicit warnings from exec
  exec ($runprog @ARGV) || err ($stderr, "exec", $runprog, $!);
}
 
main ();
 
# local variables:
# mode: perl
# eval: (auto-fill-mode 1)
# end:
 
# with ends here
 
EOF

用www用户启动我们的分发器

chmod +x /sbin/runas
runas --daemon -g www -u www /bin/perl-fcgi

二、配置nginx

现在nginx的配置目录下放置这么一个文件fcgi_perl.conf

cat >>/usr/local/nginx/conf/fcgi_perl.conf<<EOF
 
fastcgi_pass    127.0.0.1:10081;
fastcgi_index   index.cgi;
fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING      $query_string;
fastcgi_param REQUEST_METHOD    $request_method;
fastcgi_param CONTENT_TYPE      $content_type;
fastcgi_param CONTENT_LENGTH    $content_length;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE   nginx;
fastcgi_param SCRIPT_NAME       $fastcgi_script_name;
fastcgi_param REQUEST_URI       $request_uri;
fastcgi_param DOCUMENT_URI      $document_uri;
fastcgi_param DOCUMENT_ROOT     $document_root;
fastcgi_param SERVER_PROTOCOL   $server_protocol;
fastcgi_param REMOTE_ADDR       $remote_addr;
fastcgi_param REMOTE_PORT       $remote_port;
fastcgi_param SERVER_ADDR       $server_addr;
fastcgi_param SERVER_PORT       $server_port;
fastcgi_param SERVER_NAME       $server_name;
fastcgi_read_timeout            60;
 
EOF

然后在需要perl功能的虚拟机段做类似这样的配置:
     

cat >>/usr/local/nginx/conf/nginx.conf<<EOF
 
  server {
             listen             80;
             server_name        mail.ashopex.com;
             index              index.cgi
 
             root               /var/www;
 
             location ~  .*\.cgi? {
                  include         fcgi_perl.conf;
             }
     }
 
EOF

Posted by microsea


Trackback URL : 无法向此文章发送引用

nginx系统变量列表

The module ngx_http_core_module supports the built-in variables, whose names correspond with the names of variables in Apache.

First of all, these are the variables, which represent the lines of the title of the client request, for example, $http_user_agent, $http_cookie and so forth.

Furthermore, there are other variables:

$arg_PARAMETER, this variable contains the value of the GET request variable PARAMETER if present in the query string

$args, this variable is equal to arguments in the line of request;

$content_length, this variable is equal to line “Content-Length” in the header of request;

$content_type, this variable is equal to line “Content-Type” in the header of request;

$document_root, this variable is equal to the value of directive root for the current request;

$document_uri, the same as $uri;

$host, this variable is equal to line “Host” in the header of request or name of the server, to whom the request arrived, if there is no this line;

$is_args evaluates to “?” if $args is set, “” otherwise.

$limit_rate, the variable allows to limit connection rate;

$query_string, the same as $args;

$request_method, this variable is equal to the method of request, usually this “GET” or “POST”;

$remote_addr, this variable is equal to the address of client;

$remote_port, this variable is equal to the port of client;

$remote_user, this variable is equal to the name of user, authenticated by ngx_http_auth_basic_module;

$request_filename, this variable is equal to path to the file for the current request, formed from directives root or alias and URI request;

$request_body_file, client request body temporary filename;

$request_uri, this variable is equal to the complete initial URI together with the arguments;

$scheme, the HTTP scheme (http, https). Evaluated only on demand, for example:

rewrite  ^(.+)$  $scheme://example.com$1  redirect;

$server_protocol, this variable is equal to the protocol of request, usually this “HTTP/1.0″ or “HTTP/1.1″;

$server_addr, the variable is equal to the server address, to whom arrived the request. As a rule, for obtaining the value of this variable is done one system call. In order to avoid system call, it is necessary to indicate addresses in directives listen and to use parameter bind;

$server_name, this variable is equal to the name of the server, to whom arrived the request;

$server_port, this variable is equal to the port of the server, to which the request arrived;

$uri, this variable is equal to current URI in the request, it can differ from initial, for example by internal redirects, or with the use of index it is file with internal redirects.

Posted by microsea


Trackback URL : 无法向此文章发送引用

Fedora core 9 网卡问题的解决

/etc/udev/rules.d/70-persistent-net.rules这个文件里面有如下记录

QUOTE:
[root@kevin ~]# cat 70-persistent-net.rules

# This file was automatically generated by the /lib/udev/write_net_rules
# program run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rule written by anaconda)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:d2:3f:2c", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:87:43:18", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:87:43:22", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:c8:3a:15", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"


这是udev在发现网卡mac变更之后,自动将接口改名的结果。将这个/etc/udev/rules.d/70-persistent-net.rules删除,重启,网卡eth0成功启动,并重新生成/etc/udev/rules.d/70-persistent-net.rules文件。

Posted by microsea


Trackback URL : 无法向此文章发送引用

redhat AS4安装yum(摘抄)

redhat AS4安装yum

1、下载下列rpm包
centos-yumconf_4-4.3_noarch.rpm
python-urlgrabber_2.9.6-2_noarch.rpm
python-elementtree_1.2.6-4_i386.rpm
sqlite_3.2.2-1_i386.rpm
python-sqlite_1.1.6-1_i386.rpm
yum_2.4.0-1.centos4_noarch.rpm
可以直接下载地址: http://www.chinalinuxpub.com/yum.tgz得到
2、安装上述rpm包
rpm -ivh *.rpm
3、将原先的centos库去除并添加AS4库

rm -rf /etc/yum.repos.d/CentOS-Base.repo
vi /etc/yum.repos.d/as4-update.repo
加入:
#released updates
[update]
name=Red Hat Enterprise AS release 4 Updates
baseurl=http://ftp.chinalinuxpub.com/redhat/enterprise/updates/4AS/
gpgcheck=1
gpgkey=http://ftp.chinalinuxpub.com/redhat/enterprise/RPM-GPG-KEY-linuxpub

vi /etc/yum.repos.d/as4-base.repo
加入:
#released base
[base]
name=Red Hat Enterprise AS release 4 Updates
baseurl=http://ftp.chinalinuxpub.com/redhat/enterprise/os/i386/RedHat/
gpgcheck=1
gpgkey=http://ftp.chinalinuxpub.com/redhat/enterprise/RPM-GPG-KEY-linuxpub

至此yum便可以用了。

法二

第二种方法:利用CentOS 的yum库升级RHEL AS4
1.下载并安装yum-2.4.0-1.centos4.noarch.rpm文件,下载地址为:
ftp://ftp.pbone.net/mirror/ftp.centos.org/4.2/os/alpha/CentOS/RPMS/yum-2.4.0-1.centos4.noarch.rpm

2.修改或建立/etc/yum.repos.d/CentOS-Base.repo为如下内容:
[base]
name=CentOS-$releasever - Base
baseurl=http://ftp.riken.jp/Linux/caos/centos/4.0/os/$basearch/
gpgcheck=1

#released updates
[update]
name=CentOS-$releasever - Updates
baseurl=http://ftp.riken.jp/Linux/caos/centos/4.0/updates/$basearch/
gpgcheck=1

#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
baseurl=http://ftp.riken.jp/Linux/caos/centos/4.0/addons/$basearch/
gpgcheck=1

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://ftp.riken.jp/Linux/caos/centos/4.0/extras/$basearch/
gpgcheck=1
3.修改或建立/etc/yum.repos.d/dag.repo为如下内容:
[dag]
name=Dag RPM Repository for RHEL4
baseurl=http://ftp.riken.jp/Linux/dag/redhat/el4/en/$basearch/dag/
enabled=1
gpgcheck=1
gpgkey=http://ftp.riken.jp/Linux/dag/packages/RPM-GPG-KEY.dag.txt

参阅文章:http://www.5sai.net.cn/article.asp?id=204

                http://jimmy-shine.javaeye.com/blog/77411

                yum的使用参阅linuxsir

                http://www.linuxsir.org/main/?q=node/31


使用yum安装新软件包及更新linux系统

  解决方案

  Linux上常用的安装和升级工具主要有yum和apt

  其中yum能更好的解决rpm的依存性问题,推荐使用yum

  例如,要在服务器上安装lynx程序

  传统的安装方式,要到linux安装光盘中寻找lynx软件包的RPM

  将其上传到服务器方,并运行rpm -ivh <文件名>的方式来安装

  而使用yum管理,只要运行yum install lynx即可完成安装

  yum会自动连接到互联网上的linux更新源,下载最新版本的包自动安装

  如果lynx已经安装了,现在需要升级到最新版本

  则运行yum upgrade lynx即可完成升级

  可以看到,yum是非常简单易用,绝大部分安装包都可以从网络获得

  而无须手工上传安装了

  在标准的Redhat Enterprise Linux上,默认没有安装yum,需要单独下载并安装。

  此外,Redhat Enterprise Linux的更新是由Redhat提供的收费服务

  但由于Redhat Enterprise Linux和CentOS是基本通用的,所以可用CentOS源来升级redhat

  1. 首先安装yum和相关的rpm包

  注意:本安装包只提供给as4系统之用

  http://www.swsoft.com.cn/downloads/Prima/Tools/yum_forAS4.tar.gz

  下载并解压缩yum包和升级文件

  rpm -ivh *.rpm

  2. 将解压缩后得到的CentOS-Base.repo复制到/etc/yum.repos.d/目录里边

  注意:本CentOS-Base.repo文件只提供给as4系统之用

  3. 执行如下命令导入GPG Key

  rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-4

  现在可以开始使用yum了。yum的主要参数包括search/install/upgrade/remove。

  要安装一个软件,比如安装lynx字符浏览器,则可以执行

  yum install lynx

  注意:

  1. 使用yum的过程中,有些程序包是不能升级的。

  例如Virtuozzo自己提供了tar等程序包,prima提供了php等包

  这些包如果被升级了,可能导致系统出现异常,部分功能无法正常运行

  (细节请查看相关文档)

  2. 如果使用yum对全部系统都进行升级,则会发现升级后系统版本将从redhat变成centos

  这是因为升级使用的是免费centos的yum源,所以升级最好有选择的执行
 
 

Posted by microsea


Trackback URL : 无法向此文章发送引用

Nginx Location基本语法

Nginx Location
基本语法
location [=|~|~*|^~] /uri/ { … }
= 严格匹配。如果这个查询匹配,那么将停止搜索并立即处理此请求。
~ 为区分大小写匹配
~* 为不区分大小写匹配
!~和!~*分别为区分大小写不匹配及不区分大小写不匹配
^~ 如果把这个前缀用于一个常规字符串,那么告诉nginx 如果路径匹配那么不测试正则表达式。

例:
location = / { # 只匹配 / 查询。
location / { # 匹配任何查询,因为所有请求都已 / 开头。但正则表达式规则和长的块规则将被优先和查询匹配。
location ^~ /images/ { # 匹配任何已 /images/ 开头的任何查询并且停止搜索。任何正则表达式将不会被测试。
location ~* \.(gif|jpg|jpeg)$ { # 匹配任何已 gif、jpg 或 jpeg 结尾的请求。

++ 文件及目录匹配
* -f和!-f用来判断是否存在文件
* -d和!-d用来判断是否存在目录
* -e和!-e用来判断是否存在文件或目录
* -x和!-x用来判断文件是否可执行

++ 一些可用的全局变量
$args
$content_length
$content_type
$document_root
$document_uri
$host
$http_user_agent
$http_cookie
$limit_rate
$request_body_file
$request_method
$remote_addr
$remote_port
$remote_user
$request_filename
$request_uri
$query_string
$scheme
$server_protocol
$server_addr
$server_name
$server_port
$uri

Posted by microsea


Trackback URL : 无法向此文章发送引用

将进程放入后台的方法---disown

disown

场景:

我们已经知道,如果事先在命令前加上 nohup 或者 setsid 就可以避免 HUP 信号的影响。但是如果我们未加任何处理就已经提交了命令,该如何补救才能让它避免 HUP 信号的影响呢?

解决方法:

这时想加 nohup 或者 setsid 已经为时已晚,只能通过作业调度和 disown 来解决这个问题了。让我们来看一下 disown 的帮助信息:

disown [-ar] [-h] [jobspec ...]
	Without options, each jobspec is  removed  from  the  table  of
	active  jobs.   If  the -h option is given, each jobspec is not
	removed from the table, but is marked so  that  SIGHUP  is  not
	sent  to the job if the shell receives a SIGHUP.  If no jobspec
	is present, and neither the -a nor the -r option  is  supplied,
	the  current  job  is  used.  If no jobspec is supplied, the -a
	option means to remove or mark all jobs; the -r option  without
	a  jobspec  argument  restricts operation to running jobs.  The
	return value is 0 unless a jobspec does  not  specify  a  valid
	job.

可以看出,我们可以用如下方式来达成我们的目的。

灵活运用 CTRL-z
在我们的日常工作中,我们可以用 CTRL-z 来将当前进程挂起到后台暂停运行,执行一些别的操作,然后再用 fg 来将挂起的进程重新放回前台(也可用 bg 来将挂起的进程放在后台)继续运行。这样我们就可以在一个终端内灵活切换运行多个任务,这一点在调试代码时尤为有用。因为将代码编辑器挂起到后台再重新放回时,光标定位仍然停留在上次挂起时的位置,避免了重新定位的麻烦。
  • disown -h jobspec 来使某个作业忽略HUP信号。
  • disown -ah 来使所有的作业都忽略HUP信号。
  • disown -rh 来使正在运行的作业忽略HUP信号。

需要注意的是,当使用过 disown 之后,会将把目标作业从作业列表中移除,我们将不能再使用jobs来查看它,但是依然能够用ps -ef查找到它。

但是还有一个问题,这种方法的操作对象是作业,如果我们在运行命令时在结尾加了"&"来使它成为一个作业并在后台运行,那么就万事大吉了,我们可以通过jobs命令来得到所有作业的列表。但是如果并没有把当前命令作为作业来运行,如何才能得到它的作业号呢?答案就是用 CTRL-z(按住Ctrl键的同时按住z键)了!

CTRL-z 的用途就是将当前进程挂起(Suspend),然后我们就可以用jobs命令来查询它的作业号,再用bg jobspec 来将它放入后台并继续运行。需要注意的是,如果挂起会影响当前进程的运行结果,请慎用此方法。


disown 示例1(如果提交命令时已经用“&”将命令放入后台运行,则可以直接使用“disown”)
                
[root@pvcent107 build]# cp -r testLargeFile largeFile &
[1] 4825
[root@pvcent107 build]# jobs
[1]+  Running                 cp -i -r testLargeFile largeFile &
[root@pvcent107 build]# disown -h %1
[root@pvcent107 build]# ps -ef |grep largeFile
root      4825   968  1 09:46 pts/4    00:00:00 cp -i -r testLargeFile largeFile
root      4853   968  0 09:46 pts/4    00:00:00 grep largeFile
[root@pvcent107 build]# logout   


disown 示例2(如果提交命令时未使用“&”将命令放入后台运行,可使用 CTRL-z 和“bg”将其放入后台,再使用“disown”)
                
[root@pvcent107 build]# cp -r testLargeFile largeFile2

[1]+  Stopped                 cp -i -r testLargeFile largeFile2
[root@pvcent107 build]# bg %1
[1]+ cp -i -r testLargeFile largeFile2 &
[root@pvcent107 build]# jobs
[1]+  Running                 cp -i -r testLargeFile largeFile2 &
[root@pvcent107 build]# disown -h %1
[root@pvcent107 build]# ps -ef |grep largeFile2
root      5790  5577  1 10:04 pts/3    00:00:00 cp -i -r testLargeFile largeFile2
root      5824  5577  0 10:05 pts/3    00:00:00 grep largeFile2
[root@pvcent107 build]#   

Posted by microsea


Trackback URL : 无法向此文章发送引用

运行perl程序时出现: bad interpreter: No such file or directory 这样的错误提示.

原因:这是在windows下通过写字板或其他编辑工具编写的perl程序,windows环境下每行的结束符是CRLF(Carriage-Return, Line-Feed). 在linux下结束符却是LF,所以每行多了一个CR串.
处理:通过以下脚本对每行结束符进行替换
#!/usr/bin/perl

die "Usage: $0 < files >\n" unless @ARGV;

for $file (@ARGV)
{
    open IN, $file or die "$0: Cannot open $file for input!\n";

    my @lines = <IN>;

    close IN;
    open OUT, "> $file" or die "$0: Cannot open $file for output!\n";

    s/\r$// for @lines;
    print OUT for @lines;
}

Posted by microsea


Trackback URL : 无法向此文章发送引用

Leave a comment
[emerg] (28)No space left on device: Couldn't create accept lock
or
[crit] (28)No space left on device: mod_rewrite: could not create rewrite_log_lock Configuration Failed
or
[error] (28)No space left on device: Cannot create SSLMutex
处理方法:
ipcs -s | grep apache | perl -e 'while (&lt;STDIN&gt;) { @a=split(/\s+/); print `ipcrm sem $a[1]`}'
==============
ipcs -s | grep apache | awk ' { print $2 } ' | xargs ipcrm sem

Posted by microsea


Trackback URL : 无法向此文章发送引用

ImageMagick + magickwand for PHP 安装手记

网上流传的安装方法都有问题,在configure PHP的时候会出错!

还是按自己摸索的方法安装才成功,给大家分享一下.

首先要选择6.2.6以上版本,magickwand INSTALL说的支持6.2.4-1版本似乎有点问题,我编译不过.



1.安装ImageMagick

tar –zxvf ImageMagick-6.2.6-5.tar.gz

cd ImageMagick-6.2.6

./configure LDFLAGS="-L/usr/lib" CPPFLAGS="-I/usr/include" --prefix=/usr/local/ImageMagick --enable-shared --enable-lzw

make

make install

2.安装PHP

tar –zxvf php-4.3.6.tar.gz

cd php-4.3.6

./configure --with-png-dir=/usr --with-gd --enable-gd-native-ttf --with-ttf --with-freetype --without-gdbm --with-gettext --with-ncurses --with-gmp --with-iconv --with-jpeg-dir=/usr  --with-png --enable-ftp --enable-sockets -with-xml --with-dom --with-zlib --enable-track-vars --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache2/bin/apxs

make

make install

说明:不带--with-imagick=/usr/local/ImageMagick参数先安装一下PHP,之后要用到phpize命令.

3.安装magickwand-0.1.8

unzip magickwand-0.1.8.zip

mv magickwand php-4.3.6/ext/

cd php-4.3.6/ext/magickwand

phpize

cd ../../

rm -rf configure

./buildconf –force

export PATH=${PATH}:/usr/local/ImageMagick/bin

#关键一步,否则编译无法通过,会有这样错误误导你:

[CODE].......... checking for ImageMagick / MagickWand in provided path... found in /usr/local/ImageMagick checking for ImageMagick / MagickWand 6.2.4 or greater with /usr/local/ImageMagick/bin/Wand-config... 6.2.6 /usr/local/ImageMagick/bin/Wand-config: line 42: Magick-config: command not found /usr/local/ImageMagick/bin/Wand-config: line 39: Magick-config: command not found ........... ........... checking size of char... configure: error: cannot compute sizeof (char), 77 See `config.log' for more details.[/CODE]

./configure --with-png-dir=/usr --with-gd --enable-gd-native-ttf --with-ttf --with-freetype --without-gdbm --with-gettext --with-ncurses --with-gmp --with-iconv --with-jpeg-dir=/usr  --with-png --enable-ftp --enable-sockets -with-xml --with-dom --with-zlib --enable-track-vars --with-mysql=/usr/local/mysql --with-imagick=/usr/local/ImageMagick --with-apxs2=/usr/local/apache2/bin/apxs

make

make install

补充问题:
如果MagickWand 执行./configure 时,出现checking for MagickSetImageTicksPerSecond in -lWand… NO的错误,可能是您现在安装了两个版本的ImageMagick,且默认的版本低于ImageMagick-6.3.3
可以用Magick-config –version命令查看其版本。
通常是系统安装了rpm包,解决方法是卸载掉libImageMagick包:
rpm -qa | grep 'ImageMagick'
rpm -e ImageMagick*


剩下不多说了的参考PHP+apache的安装文档.

成功后在phpinfo()里可以看到:

Posted by microsea


Trackback URL : 无法向此文章发送引用

Comments List

  1. gay teenboy stories 2008/May/23-03:29 # M/D Reply

    그런 위치를 경이롭 위해 많게의 감사!

  2. sexiest games for t 2008/May/23-04:07 # M/D Reply

    나는 배웠다 매우…

  3. mature movie sex 2008/May/23-04:34 # M/D Reply

    아주 좋은 나는 위치 그것을 감사 좋아한다!

  4. public speaking for 2008/May/23-05:05 # M/D Reply

    좋은 너를 위치! 감사하십시요.

  5. naked old men gallo 2008/May/23-06:14 # M/D Reply

    아주 유용한 정보!

  6. candy loving galler 2008/May/23-23:25 # M/D Reply

    친구는 너의 현재 위치의 팬이 되었다!

  7. sybian story 2008/May/23-23:31 # M/D Reply

    일! 우수한 감사!

  8. girls violet wonka 2008/May/23-23:33 # M/D Reply

    블로그를 위한 감사합니다.

Leave a comment

跟踪进程查看问题所在--strace/truss

APACHE error.log中产生了
[Wed Apr 25 21:13:54 2007] [notice] child pid 3204604 exit signal Segmentation fault (11)


使用以下脚本跟踪一下apache的进程,看是什么页面或程序引起的

#!/bin/sh
while [ "1" == "1" ]; do
        APACHE_LIST=`ps -ef | grep apache |grep -v grep|awk '{ print $2; }'` 
        for i in $APACHE_LIST; do   
                if [ ! -e $i.log ]; then     
                        echo "strace $i"     
                        strace -p $i 2> $i.log &   
                fi 
        done

        echo "wait" 
        sleep 60s
done


出现Segmentation fault信息的时候,打开该PID的log文件,查看含有Segmentation fault信息的前面几行是打开或操作什么文件,再查相应原因.

more..

Posted by microsea


Trackback URL : 无法向此文章发送引用

Leave a comment

AS5 下安装apache 2.0.x时碰到的问题

AS4上安装正常的apache 2.0.5x版本在AS5下编译会出错:
/usr/lib/libexpat.so: could not read symbols: File in wrong format

解决方法:
1. 配置命令:./configure 时加入 LDFLAGS="-L/usr/lib64 -L/lib64"

2. 修改{apache-src-dir}/srclib/apr-util/Makefile:


APRUTIL_LIBS = -lsqlite3 /usr/lib/libexpat.la /root/tar/httpd-2.2.3/srclib/apr/libapr-1.la -luuid -lrt -lcrypt -lpthread -ldl
改为
APRUTIL_LIBS = -lsqlite3 /usr/lib64/libexpat.la /root/tar/httpd-2.2.3/srclib/apr/libapr-1.la -luuid -lrt -lcrypt -lpthread -ldl

3. make; make install

Posted by microsea


Trackback URL : 无法向此文章发送引用

Leave a comment

tar xvzf mod_fastcgi-2.4.2.tar.gz
cd mod_fastcgi-2.4.2
cp Makefile.AP2 Makefile
make
出现:

mod_fastcgi.c: In function `init_module':
mod_fastcgi.c:270: error: `ap_null_cleanup' undeclared (first use in this function)
mod_fastcgi.c:270: error: (Each undeclared identifier is reported only once
mod_fastcgi.c:270: error: for each function it appears in.)
mod_fastcgi.c: In function `process_headers':
............

等错误,
下载附件到mod_fastcgi目录
执行 patch -p1 < patch
再make && make install

备注:fastcgi下载地址: http://www.fastcgi.com/dist/

Posted by microsea


Trackback URL : http://www.givingtree.com.cn/trackback/343

Leave a comment
REDHAT AS4 64位系统下编译安装net-snmp 5.4 by microsea
 
一.安装:
# configure --enable-mfd-rewrites # make; # make install
在64位系统下,如果直接make会出现以下错误:
/bin/sh ../libtool  --mode=link gcc -g -O2 -Dlinux -I/usr/include/rpm  -o snmpd snmpd.lo    libnetsnmpmibs.la libnetsnmpagent.la helpers/libnetsnmphelpers.la  ../snmplib/libnetsnmp.la -ldl -lrpm -lrpmio -lpopt  -lz -lcrypto -lm
gcc -g -O2 -Dlinux -I/usr/include/rpm -o .libs/snmpd snmpd.o  ./.libs/libnetsnmpmibs.so ./.libs/libnetsnmpagent.so helpers/.libs/libnetsnmphelpers.so ../snmplib/.libs/libnetsnmp.so -ldl -lrpm -lrpmio /usr/lib/libpopt.so -lz -lcrypto -lm  -Wl,--rpath -Wl,/usr/local/lib
/usr/lib/libpopt.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make:*** [service:snmpd] Error 1
需要修改以下两个文件:

more..

Posted by microsea


Trackback URL : 无法向此文章发送引用

Comments List

  1. large rubber ducky 2008/May/23-03:43 # M/D Reply

    걸출한 디자인! 좋은 디자인.

  2. skin tight cycling 2008/May/23-04:13 # M/D Reply

    너는 위치가 우수한 있는다!

  3. cheerleader fucked 2008/May/23-04:23 # M/D Reply

    좋은 너를 위치! 감사하십시요.

  4. slavegirls sex 2008/May/23-05:51 # M/D Reply

    여보세요, 좋은 아주 위치!

  5. coyote ugly soundtr 2008/May/23-06:14 # M/D Reply

    걸출한 블로그!

  6. gay sex online 2008/May/23-06:39 # M/D Reply

    나는 배웠다 매우…

Leave a comment

Unix/Linux 工具: Screen 命令使用(转)

前言
screen 是什么

根据其man介绍,screen是个多元化多功能的全屏窗口管理器,每个虚拟终端都可以为你提供DEC VT100 terminal的功能, 也许你会问:DEC VT100 terminal又是什么?如果你登陆过某些字符界面的BBS,或许你会记得在注册时,其要求你输入你的终端机型别,而一般预设就是我们刚刚提到的DEC VT100 termina了.另外screen还附加提供了比如SO 6429 (ECMA 48, ANSI X3.64) and ISO 2022 standards的操作功能.

more..

Posted by microsea


Trackback URL : 无法向此文章发送引用

Leave a comment
« Previous : 1 : 2 : 3 : 4 : 5 : Next »

BlogImage

Microsea,Fiona & Owen's family BLOG

- microsea

Statistics Graph

Calendar

«   Mar 2010   »
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

闽ICP备06003076号