前期准备工作:

 Nginx 代理服务器IP : 192.168.9.123 192.168.9.124

 Nginx WEB服务器IP: 192.168.9.126

Mysql DB服务器IP: 192.168.9.118

安装UbuntuServer 10.10 系统

分区 /boot 100M

 /tmp 1G

 swap 内存2

剩下的分给 /

进系统后更换为mirrors.163.com的源

执行 Apt-get install update

Apt-get install upgrade

Apt-get install vim

Apt-get install build-essential

一、安装NGINX (编译安装)

1 安装pcre nginx支持rewrite 方便以后所需

tar zxvf pcre-8.20.tar.gz

cd pcre-8.20

./configure

make && make install

2 安装nginx

tar zxvf nginx-1.0.10.tar.gz

cd nginx-1.0.10

./configure --user=www-data --group=www-data --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-cc-opt='-O2' --with-cpu-opt=opteron

make && make install

3 常见报错

/usr/local/webserver/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory

安装apt-get install libpcre3-dev

4测试并启动nginx
ulimit -SHn 51200
/usr/local/webserver/nginx/sbin/nginx -t 
/usr/local/webserver/nginx/sbin/nginx

 

5 自启动脚本

先运行命令关闭nginx
sudo kill `cat /usr/local/nginx/logs/nginx.pid`

 vim /etc/init.d/nginx

#! /bin/sh

# chkconfig: - 58 74

# description: nginx is the Nginx daemon.

# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and

# run 'sudo update-rc.d nginx defaults', or use the appropriate command on your

# distro.

#

# Author:  Ryan Norbauer

# Modified:     Geoffrey Grosenbach http://topfunky.com

# Modified:     David Krmpotic http://davidhq.com

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DESC="nginx daemon"

NAME=nginx

DAEMON=/usr/local/webserver/nginx/sbin/$NAME

CONFIGFILE=/usr/local/webserver/nginx/conf/nginx.conf

PIDFILE=/usr/local/webserver/nginx/logs/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.

test -x $DAEMON || exit 0

d_start() {

  $DAEMON -c $CONFIGFILE || echo -en "\n already running"

}

d_stop() {

  kill -QUIT `cat $PIDFILE` || echo -en "\n not running"

}

d_reload() {

  kill -HUP `cat $PIDFILE` || echo -en "\n can't reload"

}

case "$1" in

  start)

    echo -n "Starting $DESC: $NAME"

    d_start

        echo "."

  ;;

  stop)

    echo -n "Stopping $DESC: $NAME"

    d_stop

        echo "."

  ;;

  reload)

    echo -n "Reloading $DESC configuration..."

    d_reload

        echo "."

  ;;

  restart)

    echo -n "Restarting $DESC: $NAME"

    d_stop

    # One second might not be time enough for a daemon to stop,

    # if this happens, d_start will fail (and dpkg will break if

    # the package is being upgraded). Change the timeout if needed

    # be, or change d_stop to have start-stop-daemon use --retry.

    # Notice that using --retry slows down the shutdown process

    # somewhat.

    sleep 1

    d_start

    echo "."

  ;;

  *)

    echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2

    exit 3

  ;;

esac

exit 0

 

chmod +x nginx  #赋予执行权限

apt-get install sysv-rc-conf  #安装启动项管理工具

sysv-rc-conf nginx on #Nginx加入启动项

二、安装Mysql

1 运行语句

apt-get install mysql-server mysql-client

2安装过程中会让要求输入MySQLroot用户密码

New password for the MySQL "root" user: <-- yourrootsqlpassword

Repeat password for the MySQL "root" user: <-- yourrootsqlpassword

3 重启Mysql

Service mysql restart

4 登陆Mysql

Mysql –uroot –p

Enter password:

elcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 37

Server version: 5.1.49-1ubuntu8.1 (Ubuntu)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

+--------------------+

2 rows in set (0.00 sec)

5 安装完毕