Nginx采用了模块化、事件驱动、异步、单线程及非阻塞的架构,并大量采用了多路复用及事件通知机制,是一种轻量级的web服务器。
- yum -y groupinstall "Development Libraries" "Development Tools" "X Software Development"
- yum -y install pcre-devel
- # groupadd -r nginx
- # useradd -r -g nginx nginx
- tar xf nginx-1.2.3.tar.gz
- cd nginx-1.2.3
- 编译安装:
- ./configure \
- --prefix=/usr \
- --sbin-path=/usr/sbin/nginx \
- --conf-path=/etc/nginx/nginx.conf \
- --error-log-path=/var/log/nginx/error.log \
- --http-log-path=/var/log/nginx/access.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_stub_status_module \
- --with-http_gzip_static_module \
- --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/ \
- --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
- --http-scgi-temp-path=/var/tmp/nginx/scgi \
- --with-pcre
- make && make install
- #!/bin/sh
- #
- # nginx - this script starts and stops the nginx daemon
- #
- # chkconfig: - 85 15
- # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
- # proxy and IMAP/POP3 proxy server
- # processname: nginx
- # config: /etc/nginx/nginx.conf
- # config: /etc/sysconfig/nginx
- # pidfile: /var/run/nginx.pid
- # Source function library.
- . /etc/rc.d/init.d/functions
- # Source networking configuration.
- . /etc/sysconfig/network
- # Check that networking is up.
- [ "$NETWORKING" = "no" ] && exit 0
- nginx="/usr/sbin/nginx"
- prog=$(basename $nginx)
- NGINX_CONF_FILE="/etc/nginx/nginx.conf"
- [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
- lockfile=/var/lock/subsys/nginx
- make_dirs() {
- # make required directories
- user=`nginx -V 2>&1 | grep "configure arguments:" | \
- sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
- options=`$nginx -V 2>&1 | grep 'configure arguments:'`
- for opt in $options; do
- if [ `echo $opt | grep '.*-temp-path'` ]; then
- value=`echo $opt | cut -d "=" -f 2`
- if [ ! -d "$value" ]; then
- # echo "creating" $value
- mkdir -p $value && chown -R $user $value
- fi
- fi
- done
- }
- start() {
- [ -x $nginx ] || exit 5
- [ -f $NGINX_CONF_FILE ] || exit 6
- make_dirs
- echo -n $"Starting $prog: "
- daemon $nginx -c $NGINX_CONF_FILE
- retval=$?
- echo
- [ $retval -eq 0 ] && touch $lockfile
- return $retval
- }
- stop() {
- echo -n $"Stopping $prog: "
- killproc $prog -QUIT
- retval=$?
- echo
- [ $retval -eq 0 ] && rm -f $lockfile
- return $retval
- }
- restart() {
- configtest || return $?
- stop
- sleep 1
- start
- }
- reload() {
- configtest || return $?
- echo -n $"Reloading $prog: "
- killproc $nginx -HUP
- RETVAL=$?
- echo
- }
- force_reload() {
- restart
- }
- configtest() {
- $nginx -t -c $NGINX_CONF_FILE
- }
- rh_status() {
- status $prog
- }
- rh_status_q() {
- rh_status >/dev/null 2>&1
- }
- case "$1" in
- start)
- rh_status_q && exit 0
- $1
- ;;
- stop)
- rh_status_q || exit 0
- $1
- ;;
- restart|configtest)
- $1
- ;;
- reload)
- rh_status_q || exit 7
- $1
- ;;
- force-reload)
- force_reload
- ;;
- status)
- rh_status
- ;;
- condrestart|try-restart)
- rh_status_q || exit 0
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|condrestart| \
- try-restart|reload|force-reload|configtest}"
- exit 2
- esac
- chkconfig --add nginx
- chkconfig nginx on
- service nginx start
- netstat -tnlp
- # partprobe /dev/sda
- 创建物理卷:
- # pvcreate /dev/sda5
- 创建卷组:
- # vgcreate myvg /dev/sda5
- 创建大小为5G的逻辑卷,命名为data:
- # lvcreate -L 5G -n data myvg
- 格式化:
- # mke2fs -j /dev/myvg/data
- # mkdir /mydata
- # vim /etc/fstab 添加如下行:
- /dev/myvg/data /mydata ext3 defaults 0 0
- # mount -a ##自动挂载
- # mount
- /dev/mapper/myvg-data on /mydata type ext3 (rw)
- #mkdir /mydata/data
- # groupadd -r mysql
- # useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
- # chown -R mysql.mysql /mydata/data
- # tar xf mysql-5.5.28-linux2.6-i686.tar.gz -C /usr/local
- # cd /usr/local
- # ln -sv mysql-5.5.28-linux2.6-i686 mysql ##创建连接
- # cd mysql
- # scripts/mysql_install_db --datadir=/mydata/data --user=mysql
- # ls /mydata/data ##生成了三个文件
- mysql performance_schema test
- # cd support-files/
- # cp support-files/my-large.cnf /etc/my.cnf ##内存超过512M的话,建议使用my-large.cnf
- # vim /etc/my.cnf
- thread_concurrency = 4 ##根据你的cpu的个数适当修改这个参数
- 另外还需要添加如下行指定mysql数据文件的存放位置:
- datadir = /mydata/data
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 22953/mysqld
- # echo $PATH
- # vim /etc/profile.d/mysql.sh
- 添加如下:
- PATH=$PATH:/usr/local/mysql/bin
- export PATH
- 重新登录:
- vim /etc/man.config
- 在MANPATH处添加:MANPATH /usr/local/mysql/man
- # vim /etc/ld.so.conf.d/mysql.conf
- 写入:/usr/local/mysql/lib
- 这可以通过简单的创建链接实现:
- # ln -sv /usr/local/mysql/include /usr/include/mysql
- 如果想让编译的php支持mcrypt、mhash扩展和libevent,此处还需要下载录如下几个rpm包并安装之:
- libmcrypt-2.5.8-4.el5.centos.i386.rpm
- libmcrypt-devel-2.5.8-4.el5.centos.i386.rpm
- mhash-0.9.9-1.el5.centos.i386.rpm
- mhash-devel-0.9.9-1.el5.centos.i386.rpm
- mcrypt-2.6.8-1.el5.i386.rpm
# rpm -Uvh *.rpm
- # tar xf php-5.4.8.tar.bz2
- # cd php-5.4.8
- # ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql \
- --with-openssl --enable-fpm --enable-sockets --enable-sysvshm \
- --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring \
- --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir \
- --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt \
- --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d \
- --with-bz2 --with-curl
- # make && make intall
- 3.1:为php提供配置文件:
- # cp php.ini-production /etc/php.ini
- 3.2、为php-fpm提供Sysv init脚本,并将其添加至服务列表:
- # cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
- # chmod +x /etc/rc.d/init.d/php-fpm
- # chkconfig --add php-fpm
- # chkconfig php-fpm on
- 3.3为php-fpm提供配置文件:
- # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
- 3.4、编辑php-fpm的配置文件:
- # vim /usr/local/php/etc/php-fpm.conf
- 配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):
- pm.max_children = 50
- pm.start_servers = 5
- pm.min_spare_servers = 2
- pm.max_spare_servers = 8
- pid = /usr/local/php/var/run/php-fpm.pid
# service php-fpm start
使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
# ps aux | grep php-fpm
- location ~ \.php$ {
- root /web/htdocs;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- include fastcgi_params;
- }
- fastcgi_param GATEWAY_INTERFACE CGI/1.1;
- fastcgi_param SERVER_SOFTWARE nginx;
- 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 SCRIPT_FILENAME $document_root$fastcgi_script_name;
- 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;
将index.php加到index行:如下
- ocation / {
- root html;
- index index.php index.html index.htm;
- }
# service nginx reload
- # cat > /usr/html/index.php << EOF
- <?php
- phpinfo();
- ?>
- # tar xf xcache-2.0.0.tar.gz
- # cd xcache-2.0.0
- # /usr/local/php/bin/phpize
- # ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
- # make && make install
- 安装结束时,会出现类似如下行:
- Installing shared extensions: /usr/local/php/lib/php/extensions/no \
- -debug-non-zts-20100525/
- 首先将xcache提供的样例配置导入php.ini
- # mkdir /etc/php.d
- # cp xcache.ini /etc/php.d
- 说明:xcache.ini文件在xcache的源码目录中。
- 接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:
- zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so
- 注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。
# service php-fpm restart
- # tar xf phpMyAdmin-3.5.1-all-languages.tar.bz2
- # cd phpMyAdmin-3.5.1-all-languages
- # mv * /web/htdocs/
- # cd /web/htdocs/
- # cp config.sample.inc.php config.inc.php
- mysql> set password for root@localhost=password('nongda');
- Query OK, 0 rows affected (0.07 sec)
- mysql> flush privileges;
- Query OK, 0 rows affected (0.01 sec)
- 7.1、修改主配置文件/etc/pki/tls/openssl.conf
- 将目录设置为/etc/pki/CA
- dir = /etc/pki/CA ##45行
- 7.2 生成私钥,并放置于/etc/pki/CA/pravate下,命名为cakey.pem
- # cd /etc/pki/CA
- # (umask 077;openssl genrsa 2048 > private/cakey.pem)
- 7.3:基于私钥生成自签证书
- # openssl req -new -x509 -key private/catey.pem -out cacert.pem -days 3650
- Country Name (2 letter code) [GB]:cn
- State or Province Name (full name) [Berkshire]:henan
- Locality Name (eg, city) [Newbury]:zz
- Organization Name (eg, company) [My Company Ltd]:nongda
- Organizational Unit Name (eg, section) []:yuanlin
- Common Name (eg, your name or your server's hostname) []:ca.xiangbo.com
- 7.5:创建相关目录文件:
- # mkdir certs newcerts crl
- # touch index.txt serial
- # echo 01 > serial
- 7.6:生成一个证书颁发请求
- # cd /etc/nginx
- # mkdir ssl
- # cd ssl
- # (umask 077;openssl genrsa 1024 > nginx.key)
- 7.7生成证书签发请求:
- # openssl req -new -key nginx.key -out nginx.csr
- Country Name (2 letter code) [GB]:cn
- State or Province Name (full name) [Berkshire]:henan
- Locality Name (eg, city) [Newbury]:zz
- Organization Name (eg, company) [My Company Ltd]:nongda
- Organizational Unit Name (eg, section) []:yuanlin
- Common Name (eg, your name or your server's hostname) []:www.xiangbo.com
- //www.xiangbo.com 要与被访问的主机名保持一致
- 6.8签发私有证书:
- # openssl ca -in nginx.csr -out nginx.crt
- 查看生成文件