<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Life - WeiG &#187; server</title>
	<atom:link href="http://www.weigblog.com/tag/server/feed" rel="self" type="application/rss+xml" />
	<link>http://www.weigblog.com</link>
	<description>Yet another Life</description>
	<lastBuildDate>Thu, 05 Jan 2012 03:13:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Migrate Single Disk to RAID5 in QNAP 409 Pro</title>
		<link>http://www.weigblog.com/2010/04/11/migrate-single-disk-to-raid5-in-qnap-409-pro.html</link>
		<comments>http://www.weigblog.com/2010/04/11/migrate-single-disk-to-raid5-in-qnap-409-pro.html#comments</comments>
		<pubDate>Sun, 11 Apr 2010 07:40:12 +0000</pubDate>
		<dc:creator>Wei</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[nas]]></category>
		<category><![CDATA[qnap]]></category>
		<category><![CDATA[raid]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ts-409-pro]]></category>

		<guid isPermaLink="false">http://www.weigblog.com/?p=539</guid>
		<description><![CDATA[由于NAS上的硬盘即将告急，又赶上近期硬盘稍有降价。就趁机添置了2块1TB的硬盘，准备添加到NAS上使用。目前的情况是，当硬盘容量超过1TB时，一个好的灾难恢复机制就显得非常重要了。3块硬盘正好组建RAID5，可以容许1块硬盘损坏，但总容量则变为：最小单块容量×（硬盘数－1）。 QNAP 409 Pro号称有Online RAID Migration功能，我的理解就是，所谓Online，就是所有的服务都不需要停止，也不会在此过程中出现中断。然而，QNAP的RAID迁移过程，还是让我受了不少罪的。 Day 1：直接在Web管理界面上选择Single Disk，然后迁移到RAID5。迁移过程开始后，进度基本按照每半小时1%的速度进行着。在将近48小时的时候，未知原因，迁移过程中断。没有错误提示，没有日志，没有数据丢失。 Day 3：经过搜索论坛后，发现有人与我有类似的经历，解决的的方法是关掉所有的后台服务。依此进行，关掉全部AFP、SAMBA、MySQL等服务。仍然是在50%的位置中断。在SSH查看过程时，发现前10%有个mke2fs的进程；从11%到50%，则有一个cp -a的进程。 Day 5：重新启动NAS，确保kill掉所有的无关进程，重新迁移。从11%起，硬盘进入Read Only模式。但在50%时，再次中断。此时却发现_httpd_进程没有了，web管理页面自然也就没有了，重启后仍然没有。 Day 7：准备采取最后的方案，备份数据，然后重新设置服务器。在备份数据的时候，突然想到其他的方案。采用其他的迂回方案。首先remove以前的Single Disk，插入新的2块硬盘。在Web页面（经过换盘重启后不知道什么原因恢复了），创建新的RAID1（镜像）。然后在线插入以前的硬盘，识别后，通过SSH，将全部数据复制到新的Volume里面。接下来重新从Web管理页面将RAID1迁移到RAID5。然而，我却发现，这个迁移过程和之前的过程如出一辙，仍然是将RAID1的一块硬盘，与新硬盘组成一个新的Volume，然后把旧的数据复制进去。再进行迁移。可这次居然再50%之后没有停下来，Web页面能够看到迁移过程，提示剩余600分钟。。在此经过大约8小时，迁移完成，数据也没有丢失。 Single Disk to RAID 5的迁移过程 这个迁移的过程，貌似有些山寨： 新增的两块硬盘，组成新的Volume（degraded RAID5），加载点为/share/mdx_tmp（迁移过程的0%到10%） 通过cp，直接复制旧数据到新的volume，在此过程中，磁盘属于Read Only模式（迁移过程的11%到50%） 将旧的磁盘格式化，合并到新的volume里面 通过RAID5的sync，最终实现RAID5 RAID1迁移到RAID5的过程与之类似，因为RAID1两块硬盘互为镜像，所以迁移的过程中，可以直接断开一块硬盘，并执行上面的过程。 从这里看出来，这个迁移过程并不能算是完全的“online”。首先，需要停止所有的网络服务（包括SAMBA，AFP等）；其次，即使可以不停止这些服务，迁移过程的11%～50%也是Read Only模式的，并不能实现完整的服务。 这里的经验是： 迁移之前，停止所有的服务，并且停止所有有访问硬盘的进程 备份，迁移之前备份还是非常重要的 大约1TB的数据，迁移的时间大约为72小时。其中创建degraded RAID5大约需要2个小时，复制数据需要48小时，剩下的大约24小时为最后的迁移和sync的过程]]></description>
			<content:encoded><![CDATA[<p>由于NAS上的硬盘即将告急，又赶上近期硬盘稍有降价。就趁机添置了2块1TB的硬盘，准备添加到NAS上使用。目前的情况是，当硬盘容量超过1TB时，一个好的灾难恢复机制就显得非常重要了。3块硬盘正好组建RAID5，可以容许1块硬盘损坏，但总容量则变为：最小单块容量×（硬盘数－1）。</p>
<p>QNAP 409 Pro号称有Online RAID Migration功能，我的理解就是，所谓Online，就是所有的服务都不需要停止，也不会在此过程中出现中断。然而，QNAP的RAID迁移过程，还是让我受了不少罪的。</p>
<p>Day 1：直接在Web管理界面上选择Single Disk，然后迁移到RAID5。迁移过程开始后，进度基本按照每半小时1%的速度进行着。在将近48小时的时候，未知原因，迁移过程中断。没有错误提示，没有日志，没有数据丢失。</p>
<p>Day 3：经过搜索论坛后，发现有人与我有类似的经历，解决的的方法是关掉所有的后台服务。依此进行，关掉全部AFP、SAMBA、MySQL等服务。仍然是在50%的位置中断。在SSH查看过程时，发现前10%有个mke2fs的进程；从11%到50%，则有一个cp -a的进程。</p>
<p>Day 5：重新启动NAS，确保kill掉所有的无关进程，重新迁移。从11%起，硬盘进入Read Only模式。但在50%时，再次中断。此时却发现_httpd_进程没有了，web管理页面自然也就没有了，重启后仍然没有。</p>
<p>Day 7：准备采取最后的方案，备份数据，然后重新设置服务器。在备份数据的时候，突然想到其他的方案。采用其他的迂回方案。首先remove以前的Single Disk，插入新的2块硬盘。在Web页面（经过换盘重启后不知道什么原因恢复了），创建新的RAID1（镜像）。然后在线插入以前的硬盘，识别后，通过SSH，将全部数据复制到新的Volume里面。接下来重新从Web管理页面将RAID1迁移到RAID5。然而，我却发现，这个迁移过程和之前的过程如出一辙，仍然是将RAID1的一块硬盘，与新硬盘组成一个新的Volume，然后把旧的数据复制进去。再进行迁移。可这次居然再50%之后没有停下来，Web页面能够看到迁移过程，提示剩余600分钟。。在此经过大约8小时，迁移完成，数据也没有丢失。</p>
<p><strong>Single Disk to RAID 5的迁移过程</strong></p>
<p>这个迁移的过程，貌似有些山寨：</p>
<ol>
<li>新增的两块硬盘，组成新的Volume（degraded RAID5），加载点为/share/mdx_tmp（迁移过程的0%到10%）</li>
<li>通过cp，直接复制旧数据到新的volume，在此过程中，磁盘属于Read Only模式（迁移过程的11%到50%）</li>
<li>将旧的磁盘格式化，合并到新的volume里面</li>
<li>通过RAID5的sync，最终实现RAID5</li>
</ol>
<p>RAID1迁移到RAID5的过程与之类似，因为RAID1两块硬盘互为镜像，所以迁移的过程中，可以直接断开一块硬盘，并执行上面的过程。</p>
<p>从这里看出来，这个迁移过程并不能算是完全的“online”。首先，需要停止所有的网络服务（包括SAMBA，AFP等）；其次，即使可以不停止这些服务，迁移过程的11%～50%也是Read Only模式的，并不能实现完整的服务。</p>
<p>这里的经验是：</p>
<ul>
<li>迁移之前，停止所有的服务，并且停止所有有访问硬盘的进程</li>
<li>备份，迁移之前备份还是非常重要的</li>
<li>大约1TB的数据，迁移的时间大约为72小时。其中创建degraded RAID5大约需要2个小时，复制数据需要48小时，剩下的大约24小时为最后的迁移和sync的过程</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.weigblog.com/2010/04/11/migrate-single-disk-to-raid5-in-qnap-409-pro.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>解决nginx和php-fastcgi上传大文件的问题</title>
		<link>http://www.weigblog.com/2009/10/03/nginx-php-fastcgi-upload-big-files.html</link>
		<comments>http://www.weigblog.com/2009/10/03/nginx-php-fastcgi-upload-big-files.html#comments</comments>
		<pubDate>Sat, 03 Oct 2009 14:26:51 +0000</pubDate>
		<dc:creator>Wei</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[body]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[max]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[size]]></category>

		<guid isPermaLink="false">http://www.weigblog.com/?p=495</guid>
		<description><![CDATA[近来需要在blog中上传一些比较大的照片，却发现无论是Flash Uploader还是Web Uploader均无法上传。经过一番试验，发现这种情况仅发生在上传较大图片的时候，而对于几百KB的图片却不出现问题。 我的Server使用了nginx和php-fastcgi，经过检查php的配置文件，发现upload_max_filesize、post_max_size都不应该会影响上传。从phpinfo()来看，这些配置也都正确读入了。经过查看/var/log/nginx/error.log，发现其最下面几行出现日志： 既然log是nginx报出来的，那问题自然出现在nginx上。经过查询nginx的wiki，解决方案如下： 在/etc/nginx/nginx.conf中添加如下配置： 之后运行/etc/init.d/nginx reload重新载入配置文件，上传搞定。]]></description>
			<content:encoded><![CDATA[<p>近来需要在blog中上传一些比较大的照片，却发现无论是Flash Uploader还是Web Uploader均无法上传。经过一番试验，发现这种情况仅发生在上传较大图片的时候，而对于几百KB的图片却不出现问题。</p>
<p>我的Server使用了nginx和php-fastcgi，经过检查php的配置文件，发现upload_max_filesize、post_max_size都不应该会影响上传。从phpinfo()来看，这些配置也都正确读入了。经过查看/var/log/nginx/error.log，发现其最下面几行出现日志：</p>
<pre class="brush: plain; title: ; notranslate">
2009/10/03 22:06:23 [error] 6029#0: *20 client intended to send too large body: 1345385 bytes, client: x.x.x.x, server: weigblog.com, request: &quot;POST /wp-admin/async-upload.php HTTP/1.1&quot;, host: &quot;www.weigblog.com&quot;
</pre>
<p>既然log是nginx报出来的，那问题自然出现在nginx上。经过查询nginx的wiki，解决方案如下：</p>
<p>在/etc/nginx/nginx.conf中添加如下配置：</p>
<pre class="brush: bash; highlight: [3]; title: ; notranslate">
http {
        ...
        client_max_body_size 100m;
        ...
}
</pre>
<p>之后运行/etc/init.d/nginx reload重新载入配置文件，上传搞定。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weigblog.com/2009/10/03/nginx-php-fastcgi-upload-big-files.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在Nginx下运行perl-cgi脚本</title>
		<link>http://www.weigblog.com/2009/09/16/using-per-cgi-in-nginx.html</link>
		<comments>http://www.weigblog.com/2009/09/16/using-per-cgi-in-nginx.html#comments</comments>
		<pubDate>Wed, 16 Sep 2009 14:26:37 +0000</pubDate>
		<dc:creator>Wei</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[pl]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.weigblog.com/?p=487</guid>
		<description><![CDATA[把Web Server更换为Nginx后，发现BugZilla不能用了。打开网站显示403 Forbidden，想来是因为BugZilla使用Perl CGI运行的原因。查了Nginx为数不多的文档，发现Nginx不能像其他Web Server（例如Apache）那样直接运行perl-cgi的脚本。 试用几个不同的方法后，发现确实有方法可以比较简单的实现perl-cgi的功能： 首先下载一个Perl Wrapper，我把它另存为~/perl-fastcgi.pl。 修改perl-fastcgi.pl的属性，添加可执行权限。运行该文件，该脚本会创建一个/var/run/nginx/perl_cgi-dispatch.sock文件。 修改nginx的配置文件，在server section中添加： 配置工作就此完成，重新启动nginx即可。 对于BugZilla，可能还需要运行http://domain.tld/testagent.cgi。]]></description>
			<content:encoded><![CDATA[<p>把Web Server更换为Nginx后，发现BugZilla不能用了。打开网站显示403 Forbidden，想来是因为BugZilla使用Perl CGI运行的原因。查了Nginx为数不多的文档，发现Nginx不能像其他Web Server（例如Apache）那样直接运行perl-cgi的脚本。</p>
<p>试用几个不同的方法后，发现确实有方法可以比较简单的实现perl-cgi的功能：</p>
<p>首先下载一个<a href="http://technotes.1000lines.net/fastcgi-wrapper.pl">Perl Wrapper</a>，我把它另存为~/perl-fastcgi.pl。</p>
<p>修改perl-fastcgi.pl的属性，添加可执行权限。运行该文件，该脚本会创建一个/var/run/nginx/perl_cgi-dispatch.sock文件。</p>
<p>修改nginx的配置文件，在server section中添加：</p>
<pre class="brush: bash; title: ; notranslate">
location ~ \.cgi$ {
        root           /srv/www/domain.tld/public_html;
        fastcgi_pass    unix:/var/run/nginx/perl_cgi-dispatch.sock;
        fastcgi_index   index.cgi;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include         fastcgi_params;
}
</pre>
<p>配置工作就此完成，重新启动nginx即可。</p>
<p>对于BugZilla，可能还需要运行http://domain.tld/testagent.cgi。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weigblog.com/2009/09/16/using-per-cgi-in-nginx.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Web服务器更换到Nginx</title>
		<link>http://www.weigblog.com/2009/09/16/web-services-change-to-nginx.html</link>
		<comments>http://www.weigblog.com/2009/09/16/web-services-change-to-nginx.html#comments</comments>
		<pubDate>Wed, 16 Sep 2009 12:29:47 +0000</pubDate>
		<dc:creator>Wei</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[lemp]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.weigblog.com/?p=480</guid>
		<description><![CDATA[禁不住诱惑，还是把Web服务器更换为Nginx（读音[engine x]），这个俄罗斯人写的高性能的web服务器。[因为在Linode360方案中，使用Apache如果想达到比较好的性能，确实会比较频繁的出现OOM；要避免OOM，就只能减少并发处理能力和内存配置] Debian Lenny自带的nginx是0.6x的，而目前最新版本是0.7x。因此决定，从官方网站安装。 本文简单介绍了完整的安装过程。 首先安装必要的package，这些package将会在后面的过程中用到： 接下来下载并安装nginx（注意，下载的地址的可能会发生变化，可以参考http://wiki.nginx.org/NginxInstall#Stable）： 安装spawn-fcgi（曾经lighttpd的一部分，用来管理php-cgi进程） 创建nginx和php-fastcgi的init脚本 /etc/init.d/nginx文件内容： /etc/init.d/php-fastcgi文件内容： 创建nginx配置文件/etc/nginx/nginx.conf（并实现VirtualHost） 创建VirtualHost文件/etc/nginx/sites-available/domain.tld Enable VirualHost 启动php-fastcgi和nginx 配置php-fastcgi和nginx自动启动 此时，php的配置文件使用/etc/php5/cgi/php.ini。 创建WordPress的rewrite rule：修改/etc/nginx/sites-available/domain.tld，在location /中添加如下的内容： location / { root /srv/www/weigblog.com/public_html; index index.html index.htm index.php; if (!-e $request_filename) { rewrite (.*) /index.php; } } 其中： -e为存在目录或文件 -d为存在目录 -f为存在文件]]></description>
			<content:encoded><![CDATA[<p>禁不住诱惑，还是把Web服务器更换为Nginx（读音[engine x]），这个俄罗斯人写的高性能的web服务器。[因为在Linode360方案中，使用Apache如果想达到比较好的性能，确实会比较频繁的出现OOM；要避免OOM，就只能减少并发处理能力和内存配置]</p>
<p>Debian Lenny自带的nginx是0.6x的，而目前最新版本是0.7x。因此决定，从官方网站安装。</p>
<p>本文简单介绍了完整的安装过程。</p>
<p>首先安装必要的package，这些package将会在后面的过程中用到：</p>
<pre class="brush: bash; title: ; notranslate">
$ sudo apt-get install libssl-dev libpcre3-dev build-essential
$ sudo apt-get install php5 php5-cgi mysql-server mysql-client
</pre>
<p>接下来下载并安装nginx（注意，下载的地址的可能会发生变化，可以参考<a href="http://wiki.nginx.org/NginxInstall#Stable">http://wiki.nginx.org/NginxInstall#Stable</a>）：</p>
<pre class="brush: bash; title: ; notranslate">
$ wget http://sysoev.ru/nginx/nginx-0.7.62.tar.gz
$ tar -zxvf nginx-0.7.62.tar.gz
$ cd nginx-0.7.62
$ ./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid  --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --with-md5-asm --with-md5=/usr/include --with-sha1-asm --with-sha1=/usr/include --with-http_stub_status_module
$ make
$ sudo make install
</pre>
<p>安装spawn-fcgi（曾经lighttpd的一部分，用来管理php-cgi进程）</p>
<pre class="brush: bash; title: ; notranslate">
$ wget http://www.lighttpd.net/download/spawn-fcgi-1.6.2.tar.gz
$ tar -zxvf spawn-fcgi-1.6.2.tar.gz
$ cd spawn-fcgi-1.6.2
$ ./configure
$ make
$ sudo cp ./src/spawn-cgi /usr/bin/
</pre>
<p>创建nginx和php-fastcgi的init脚本</p>
<pre class="brush: bash; title: ; notranslate">
$ sudo vi /etc/init.d/php-fastcgi
$ sudo vi /etc/init.d/nginx
$ sudo chmod +x /etc/init.d/php-fastcgi
$ sudo chmod +x /etc/init.d/nginx
</pre>
<p>/etc/init.d/nginx文件内容：</p>
<pre class="brush: bash; title: ; notranslate">
#! /bin/sh
### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: nginx init.d script for Ubuntu 8.10 and lesser versions.
# Description:       nginx init.d script for Ubuntu 8.10 and lesser versions.
### END INIT INFO
#------------------------------------------------------------------------------
# nginx - this script, which starts and stops the nginx daemon for ubuntu.
#
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server.  This \
#               script will manage the initiation of the \
#               server and its process state.
#
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /acronymlabs/server/nginx.pid
# Provides:    nginx
#
# Author:  Jason Giedymin
#          &lt;jason.giedymin AT acronymlabs.com&gt;.
#
# Version: 1.0 01-Apr-2009 jason.giedymin AT gmail.com
# Notes: nginx init.d script for Ubuntu 8.10 and lesser versions.
#
#------------------------------------------------------------------------------
#                               MIT X11 License
#------------------------------------------------------------------------------
#
# Copyright (c) 2009 Jason Giedymin, http://AcronymLabs.com
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# &quot;Software&quot;), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
#                               Functions
#------------------------------------------------------------------------------
. /lib/lsb/init-functions

#------------------------------------------------------------------------------
#                               Consts
#------------------------------------------------------------------------------
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nginx

NAME=nginx
DESCRIPTION=&quot;Nginx Server...&quot;

PIDSPATH=/var/run/nginx
PS=$NAME                                #the process, which happens to be the NAME
PIDFILE=$NAME.pid                       #pid file
RUNAS=root                              #user to run as

SCRIPT_OK=0                             #ala error codes
SCRIPT_ERROR=1                          #ala error codes
TRUE=1                                  #boolean
FALSE=0                                 #boolean

lockfile=/var/lock/subsys/nginx
NGINX_CONF_FILE=&quot;/etc/nginx/nginx.conf&quot;

#------------------------------------------------------------------------------
#                               Simple Tests
#------------------------------------------------------------------------------

#test if nginx is a file and executable
test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi

#set exit condition
#set -e

#------------------------------------------------------------------------------
#                               Functions
#------------------------------------------------------------------------------

configtest() {
        $DAEMON -t -c $NGINX_CONF_FILE
}

getPSCount() {
        return `pgrep -f $PS | wc -l`
}

isRunning(){
        pidof_daemon
        PID=$?

        if [ $PID -gt 0 ]; then
                return 1
        else
                return 0
        fi
}

status(){
        isRunning
        isAlive=$?

        if [ &quot;${isAlive}&quot; -eq $TRUE ]; then
                echo &quot;$NAME found running with processes:  `pidof $PS`&quot;
        else
                echo &quot;$NAME is NOT running.&quot;
        fi

}

removePIDFile(){
        if [ -f $PIDSPATH/$NAME.pid ]; then
                rm $PIDSPATH/$NAME.pid
        fi
}

start() {
        log_daemon_msg &quot;Starting $DESCRIPTION&quot;

        isRunning
        isAlive=$?

        if [ &quot;${isAlive}&quot; -eq $TRUE ]; then
                log_end_msg $SCRIPT_ERROR
        else
                start-stop-daemon --start --quiet --chuid $RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON
                chmod 400 $PIDSPATH/$PIDFILE
                log_end_msg $SCRIPT_OK
        fi
}

stop() {
        log_daemon_msg &quot;Stopping $DESCRIPTION&quot;

        isRunning
        isAlive=$?
        if [ &quot;${isAlive}&quot; -eq $TRUE ]; then
                start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE

                removePIDFile

                log_end_msg $SCRIPT_OK
        else
                log_end_msg $SCRIPT_ERROR
        fi
}

reload() {
        configtest || return $?

        log_daemon_msg &quot;Reloading (via HUP) $DESCRIPTION&quot;

        isRunning
        if [ $? -eq $TRUE ]; then
                `killall -HUP $PS` #to be safe

                log_end_msg $SCRIPT_OK
        else
                log_end_msg $SCRIPT_ERROR
        fi
}

terminate() {
        log_daemon_msg &quot;Force terminating (via KILL) $DESCRIPTION&quot;

        PIDS=`pidof $PS` || true

        [ -e $PIDSPATH/$PIDFILE ] &amp;&amp; PIDS2=`cat $PIDSPATH/$PIDFILE`

        for i in $PIDS; do
                if [ &quot;$i&quot; = &quot;$PIDS2&quot; ]; then
                        kill $i
                        removePIDFile
                fi
        done

        log_end_msg $SCRIPT_OK

}

pidof_daemon() {
    PIDS=`pidof $PS` || true

    [ -e $PIDSPATH/$PIDFILE ] &amp;&amp; PIDS2=`cat $PIDSPATH/$PIDFILE`

    for i in $PIDS; do
        if [ &quot;$i&quot; = &quot;$PIDS2&quot; ]; then
            return 1
        fi
    done
    return 0
}

case &quot;$1&quot; in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|force-reload)
        stop
        start
        ;;
  reload)
        $1
        ;;
  status)
        status
        ;;
  configtest)
        $1
        ;;
  terminate)
        $1
        ;;
  *)
        FULLPATH=/etc/init.d/$NAME
        echo &quot;Usage: $FULLPATH {start|stop|restart|force-reload|status|configtest|terminate}&quot;
        exit 1
        ;;
esac

exit 0
</pre>
<p>/etc/init.d/php-fastcgi文件内容：</p>
<pre class="brush: bash; title: ; notranslate">
#! /bin/sh
### BEGIN INIT INFO
# Provides:          php-fastcgi
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop php-cgi in external FASTCGI mode
# Description:       Start and stop php-cgi in external FASTCGI mode
### END INIT INFO

# Author: Kurt Zankl &lt;[EMAIL PROTECTED]&gt;

# Do NOT &quot;set -e&quot;

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC=&quot;php-cgi in external FASTCGI mode&quot;
NAME=php-fastcgi
DAEMON=/usr/bin/php-cgi
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
PHP_CONFIG_FILE=/etc/php5/cgi/php.ini

# Exit if the package is not installed
[ -x &quot;$DAEMON&quot; ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] &amp;&amp; . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (&gt;= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# If the daemon is not enabled, give the user a warning and then exit,
# unless we are stopping the daemon
if [ &quot;$START&quot; != &quot;yes&quot; -a &quot;$1&quot; != &quot;stop&quot; ]; then
        log_warning_msg &quot;To enable $NAME, edit /etc/default/$NAME and set START=yes&quot;
        exit 0
fi

# Process configuration
export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS
DAEMON_ARGS=&quot;-q -b $FCGI_HOST:$FCGI_PORT -c $PHP_CONFIG_FILE&quot;

do_start()
{
        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test &gt; /dev/null \
                || return 1
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
                --background --make-pidfile --chuid $EXEC_AS_USER --startas $DAEMON -- \
                $DAEMON_ARGS \
                || return 2
}

do_stop()
{
        # Return
        #   0 if daemon has been stopped
        #   1 if daemon was already stopped
        #   2 if daemon could not be stopped
        #   other if a failure occurred
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE &gt; /dev/null # --name $DAEMON
        RETVAL=&quot;$?&quot;
        [ &quot;$RETVAL&quot; = 2 ] &amp;&amp; return 2
        # Wait for children to finish too if this is a daemon that forks
        # and if the daemon is only ever run from this initscript.
        # If the above conditions are not satisfied then add some other code
        # that waits for the process to drop all resources that could be
        # needed by services started subsequently.  A last resort is to
        # sleep for some time.
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
        [ &quot;$?&quot; = 2 ] &amp;&amp; return 2
        # Many daemons don't delete their pidfiles when they exit.
        rm -f $PIDFILE
        return &quot;$RETVAL&quot;
}
case &quot;$1&quot; in
  start)
        [ &quot;$VERBOSE&quot; != no ] &amp;&amp; log_daemon_msg &quot;Starting $DESC&quot; &quot;$NAME&quot;
        do_start
        case &quot;$?&quot; in
                0|1) [ &quot;$VERBOSE&quot; != no ] &amp;&amp; log_end_msg 0 ;;
                2) [ &quot;$VERBOSE&quot; != no ] &amp;&amp; log_end_msg 1 ;;
        esac
        ;;
  stop)
        [ &quot;$VERBOSE&quot; != no ] &amp;&amp; log_daemon_msg &quot;Stopping $DESC&quot; &quot;$NAME&quot;
        do_stop
        case &quot;$?&quot; in
                0|1) [ &quot;$VERBOSE&quot; != no ] &amp;&amp; log_end_msg 0 ;;
                2) [ &quot;$VERBOSE&quot; != no ] &amp;&amp; log_end_msg 1 ;;
        esac
        ;;
  restart|force-reload)
        log_daemon_msg &quot;Restarting $DESC&quot; &quot;$NAME&quot;
        do_stop
        case &quot;$?&quot; in
          0|1)
                do_start
                case &quot;$?&quot; in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; # Old process is still running
                        *) log_end_msg 1 ;; # Failed to start
                esac
                ;;
          *)
                # Failed to stop
                log_end_msg 1
                ;;
        esac
        ;;
  *)
        echo &quot;Usage: $SCRIPTNAME {start|stop|restart|force-reload}&quot; &gt;&amp;2
        exit 3
        ;;
esac
</pre>
<p>创建nginx配置文件/etc/nginx/nginx.conf（并实现VirtualHost）</p>
<pre class="brush: bash; title: ; notranslate">
user www-data www-data;
worker_processes  4;
events {
    worker_connections  1024;
    use epoll;
}
http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        tcp_nopush     on;
        tcp_nodelay    on;

        keepalive_timeout  65;
        gzip  on;

        include /etc/nginx/sites-enabled/*; #这一句就是实现nginx VirtualHost的
}
</pre>
<p>创建VirtualHost文件/etc/nginx/sites-available/domain.tld</p>
<pre class="brush: bash; title: ; notranslate">
server {
        listen       80;
        server_name  domain.tld www.domain.tld;
        access_log      /srv/www/domain.tld/logs/access.log;
        location / {
                root   /srv/www/domain.tld/public_html;
                index  index.html index.htm index.php;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   /usr/html;
        }

        location ~ \.php$ {
                root           /srv/www/domain.tld/public_html;
                fastcgi_pass    127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
}
</pre>
<p>Enable VirualHost</p>
<pre class="brush: bash; title: ; notranslate">
$ sudo ln -s /etc/nginx/sites-available/domain.tld /etc/nginx/sites-enabled/domain.tld
</pre>
<p>启动php-fastcgi和nginx</p>
<pre class="brush: bash; title: ; notranslate">
$ sudo /etc/init.d/php-fastcgi start
$ sudo /etc/init.d/nginx start
</pre>
<p>配置php-fastcgi和nginx自动启动</p>
<pre class="brush: bash; title: ; notranslate">
$ sudo apt-get install rcconf
$ sudo rcconf # 选中php-fastcgi和nginx
</pre>
<p>此时，php的配置文件使用/etc/php5/cgi/php.ini。</p>
<p>创建WordPress的rewrite rule：修改/etc/nginx/sites-available/domain.tld，在location /中添加如下的内容：</p>
<pre class="brush:shell; highlight: [4, 5, 6];">
location / {
        root   /srv/www/weigblog.com/public_html;
        index  index.html index.htm index.php;
        if (!-e $request_filename) {
                rewrite (.*) /index.php;
        }
}
</pre>
<p>其中：<br />
-e为存在目录或文件<br />
-d为存在目录<br />
-f为存在文件</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weigblog.com/2009/09/16/web-services-change-to-nginx.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>如何重置被遗忘的域控制器（DC）管理员密码</title>
		<link>http://www.weigblog.com/2007/09/08/reset-dc-admin-password.html</link>
		<comments>http://www.weigblog.com/2007/09/08/reset-dc-admin-password.html#comments</comments>
		<pubDate>Fri, 07 Sep 2007 20:14:11 +0000</pubDate>
		<dc:creator>Wei</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[dc]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[domain-controller]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[recovery]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.weigblog.com/2007/09/08/reset-dc-admin-password.html</guid>
		<description><![CDATA[忘记了DC的管理员密码怎么办？如果你没有别的管理员可以登录DC，那么可以用下面的方法，重置Build-in Domain Administrator的密码。 前提： 要重置Domain Admin密码，要同时具备以下条件： 可以物理访问DC的 知道Local Administrator的密码。这个密码实际上在你promote DC之前设置的Windows Local Admin密码。如果你不知道，可以使用ERD Commander之类的工具修复本地管理员密码 有Instsrv.exe和SrvAny.exe文件（这两个文件随Windows2003 Resource Kit Tools一同发布，可以在这里下载。Resource Kit Tools包含了很多Windows 2003的工具，如果你只希望下载Instsrv.exe和SrvAny.exe，可以在这里找到） 接下来开始恢复过程。 很多人认为Domain Controller是没有Local Admin的，其实不是这样的。Local Admin还是有的，只是在正常登录模式下，不能用于登录而已。而目录服务恢复模式（Directory Service Restore Mode）下，则可以使用Local的账户登录。 第1步，启动Windows 2003到目录服务恢复模式（Directory Service Restore Mode）：启动时按F8，然后选择Directory Service Restore Mode。再此模式下，你可以操作计算机，却不能操作域。 第2步，当提示登录的时候，使用Local Admin登录（一般是Administrator）。 第3步：将INSTSRV.exe，SrvAny.exe文件复制到%SYSTEMDRIVE%\temp，为了方便使用，也为了防止权限的影响，也把%WINDIR%\System32\cmd.exe复制到这个目录中。保证3个文件在同一个目录中（如C:\temp）。目录的名字可以随便起，但后面用到的时候也要一致。 第4步：安装SRVANY服务。打开一个命令提示行（Start&#8211;&#62;Run&#8211;&#62;cmd.exe），输入： 其中PassRecovery是安装的服务的名称，可以随便起，但后面使用PassRecovery的时候，要和这里的一样；引号中的是服务的程序，要SRVANY.exe的全路径格式。 第5步：配置SRVANY的参数，在命令提示符中依次输入下面的命令： 上面的123456就是Domain Administrator的新密码，如果DC启用了强密码，就换个强密码吧。 如果不了解上面三条命令的作用，也可以手工操作： 打开注册表编辑器（RegEdit.exe） 找到HKYE_LOCAL_MACHINE\System\CurrentControlSet\Services\PassRecovery，在下面新建一个键值（Key），名字叫Parameters 在新建的Parameters键值中，新建一个Application的字符串，设置为&#8221;C:\temp\cmd.exe&#8221;；新建一个AppParameters的字符串，设置为&#8221;/k net user administrator 123456 /domain&#8221; 第6步：打开管理工具中的服务（services.msc）。双击PassRecovery的服务。做如下配置： 在General选项卡中，设置服务为自动启动（Startup [...]]]></description>
			<content:encoded><![CDATA[<p>忘记了<abbr title="Domain Controller，域控制器">DC</abbr>的管理员密码怎么办？如果你没有别的管理员可以登录DC，那么可以用下面的方法，重置Build-in Domain Administrator的密码。</p>
<p><strong>前提：</strong><br />
要重置Domain Admin密码，要同时具备以下条件：</p>
<ol>
<li>可以物理访问DC的</li>
<li>知道Local Administrator的密码。这个密码实际上在你promote DC之前设置的Windows Local Admin密码。如果你不知道，可以使用ERD Commander之类的工具修复本地管理员密码</li>
<li>有Instsrv.exe和SrvAny.exe文件（这两个文件随Windows2003 Resource Kit Tools一同发布，可以在<a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd">这里</a>下载。Resource Kit Tools包含了很多Windows 2003的工具，如果你只希望下载Instsrv.exe和SrvAny.exe，可以在<a href="http://www.box.net/shared/r4pn3ryand">这里</a>找到）</li>
</ol>
<p><strong>接下来开始恢复过程。</strong></p>
<p><em>很多人认为Domain Controller是没有Local Admin的，其实不是这样的。Local Admin还是有的，只是在正常登录模式下，不能用于登录而已。而目录服务恢复模式（Directory Service Restore Mode）下，则可以使用Local的账户登录。</em></p>
<p><strong>第1步，</strong>启动Windows 2003到目录服务恢复模式（Directory Service Restore Mode）：启动时按F8，然后选择Directory Service Restore Mode。再此模式下，你可以操作计算机，却不能操作域。</p>
<p><strong>第2步，</strong>当提示登录的时候，使用Local Admin登录（一般是Administrator）。</p>
<p><strong>第3步：</strong>将<abbr title="用于安装Windows服务">INSTSRV.exe</abbr>，<abbr title="此工具可以将任何程序作为服务（service）运行">SrvAny.exe</abbr>文件复制到%SYSTEMDRIVE%\temp，为了方便使用，也为了防止权限的影响，也把%WINDIR%\System32\cmd.exe复制到这个目录中。保证3个文件在同一个目录中（如C:\temp）。目录的名字可以随便起，但后面用到的时候也要一致。</p>
<p><strong>第4步：</strong>安装SRVANY服务。打开一个命令提示行（Start&#8211;&gt;Run&#8211;&gt;cmd.exe），输入：</p>
<pre class="brush: powershell; title: ; notranslate">
INSTSRV PassRecovery &quot;C:\temp\srvany.exe&quot;
</pre>
<p>其中PassRecovery是安装的服务的名称，可以随便起，但后面使用PassRecovery的时候，要和这里的一样；引号中的是服务的程序，要SRVANY.exe的全路径格式。</p>
<p><strong>第5步：</strong>配置SRVANY的参数，在命令提示符中依次输入下面的命令：</p>
<pre class="brush: powershell; title: ; notranslate">
REG ADD HKLM\System\CurrentControlSet\Services\PassRecovery\Parameters
REG ADD HKLM\System\CurrentControlSet\Services\PassRecovery\Parameters /v Application /t REG_SZ /v &quot;C:\temp\cmd.exe&quot;
REG ADD HKLM\System\CurrentControlSet\Services\PassRecovery\Parameters /v AppParameters /t REG_SZ /v &quot;/k net user administrator 123456 /domain&quot;
</pre>
<p>上面的123456就是Domain Administrator的新密码，如果DC启用了强密码，就换个强密码吧。</p>
<blockquote><p>如果不了解上面三条命令的作用，也可以手工操作：</p>
<ol>
<li>打开注册表编辑器（RegEdit.exe）</li>
<li>找到HKYE_LOCAL_MACHINE\System\CurrentControlSet\Services\PassRecovery，在下面新建一个键值（Key），名字叫Parameters</li>
<li>在新建的Parameters键值中，新建一个Application的字符串，设置为&#8221;C:\temp\cmd.exe&#8221;；新建一个AppParameters的字符串，设置为&#8221;/k net user administrator 123456 /domain&#8221;</li>
</ol>
</blockquote>
<p><strong>第6步：</strong>打开管理工具中的服务（services.msc）。双击PassRecovery的服务。做如下配置：</p>
<ol>
<li>在General选项卡中，设置服务为自动启动（Startup type=automatic）</li>
<li>在Log on选项卡中，选中“Allow  service to interact with desktop”（允许服务与桌面交互）</li>
</ol>
<p>至此，密码恢复的配置就算结束了。以正常模式启动DC，然后等待登录界面的出现（这时SRVANY已经将密码修改为你设置的值了）。使用在上面（第5步）设置的新的密码登录DC。</p>
<p><strong>收尾工作</strong></p>
<p>密码已经恢复了，接下来的工作就是删除SRVANY服务。<strong>这一步一定要做。</strong>执行下面的命令：</p>
<pre class="brush: powershell; title: ; notranslate">
net stop PassRecovery
sc delete PassRecovery
rd /s C:\temp
</pre>
<p>搞定~~~</p>
<p><strong>后记</strong></p>
<p>可能这个方法对于重置Domain Admin密码是比较容易的，不免让人担心DC的安全性。不过想想也是Reasonable的，有能力物理访问DC的人，多少应该具备管理DC的资格吧。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weigblog.com/2007/09/08/reset-dc-admin-password.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

