tar 分卷压缩以及排除某目录文件实例

测试环境目录结构:
/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 : 无法向此文章发送引用

今天儿子给我背了三字经...

儿子出生后,老婆曾经很热衷国文教育,反复读诗经,三字经,论语什么的给儿子听,儿子3岁多的时候曾经三字经能背到"亲师友,习礼仪",后来我们没有坚持下去,一年时间没温习了....昨天老婆让儿子背下三字经,儿子大声开始背: "高露洁,有高钙,把纯净,刷出来,好妈妈,要知道,全家用,一起来"..........

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 : 无法向此文章发送引用

四周三个月的Owen

自从在幼儿园上了画画兴趣班,就对画画产生了浓厚兴趣,幸手就来两张,不过都是抽象派。要经过他的解释,我们才能看懂他画想表达的意思。色彩搭配倒是进步不少。

上周五得了腮腺炎,还好没有很大的难受,没有发烧,去医院检查,血象很多项偏高,诊断是化脓性腮腺炎。挂了两天瓶,打了两天针。医生说要观察,因为腮腺炎潜伏期长,很多时候在第10-15会引起并发症。所以,Owen就得在家里呆上至少半个月。他也高兴,就是画画班不能上了。。。

Posted by microsea


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

Trackbacks List

  1. Jesus Loves Porn

    Tracked from Jesus Loves Porn July 25, 2008 12:23 Delete

    Teen Sex Video <a href="http://jakesytubituga1872008.blogspot.com/">Teen Sex Video</a> College Girls Flashing <a href="http://uiryuuvataposot1442008.blogspot.com/">College Girls Flashing</a>

Comments List

  1. bozena porn star 2008/May/23-03:25 # M/D Reply

    나는 배웠다 매우…

  2. betting casino gamb 2008/May/23-03:57 # M/D Reply

    뉴스를 위한 감사합니다…

  3. cat machine scan 2008/May/23-04:28 # M/D Reply

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

  4. beautiful tall bust 2008/May/23-04:34 # M/D Reply

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

  5. nude african women 2008/May/23-06:07 # M/D Reply

    너는 아름다운 웹사이트가 있는다!

  6. sell self into bond 2008/May/23-06:22 # M/D Reply

    저에서 유사한 역사는 이었다.

  7. sexy back justin t 2008/May/23-06:49 # M/D Reply

    나는 합의한다 너에 이다. 그것은 이렇게 이다.

  8. fellation profonde 2008/May/24-00:17 # M/D Reply

    걸출한 위치! 많은 감사.

  9. apt 9 mitchell stri 2008/May/24-00:25 # M/D Reply

    걸출한 위치! 많은 감사.

  10. chicas gratis porn 2008/May/24-00:29 # M/D Reply

    좋은 위치는 찾아본 그것 즐겼다!

  11. big booty latina sc 2008/May/24-00:40 # M/D Reply

    걸출한 블로그!

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

BlogImage

Microsea,Fiona & Owen's family BLOG

- microsea

Statistics Graph

Calendar

«   Feb 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            

闽ICP备06003076号