碎语:
Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler 站点开发的,已经在一些俄罗斯的大型网站上运行多年,相当的稳定。
Nginx性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。
Nginx性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。
各种有点不说了!!!
闲言:
最近一直时间不太多,一直在学习路由技术,谁知道一个朋友喊我帮忙做下ras,做完了就想起了nginx,于是这篇文章诞生了,在这里我采用的是CentOS 6.0。安装时是默认的minimal安装,不带有任何非必要软件包的!装完不到1G!
至于操作系统的安装,图形化肯定挑战不了大家的智商,至于文本安装,辰逸的博客里有一篇redhat5文本安装全过程~这里就省略掉了!
安装前准备:
1:配置好IP dns 网关,确保xshell等工具可以连上去~咳咳!xshell是个好东西,使用linux就应该要会用xshell(个人见解,如需下载,可在本博客搜索!)
2:关闭SElinux
vi /etc/selinux/config 把SELINUX=enforcing 注释掉 添加一行为 SELINUX=disabled
3:关闭Iptables(不建议)
可为iptables 添加策略 允许80端口和3306端口! 相关知识可以在俺博客里参考一番!
安装所需软件包!!!有点小多。呵呵呵!
pcre-8.20.tar.gz (支持nginx伪静态)
nginx-1.0.6.tar.gz (目前的稳定版本)
mysql-5.1.59.tar.gz
php-5.2.17.tar.gz
php-5.2.17-fpm-0.5.14.diff.gz (支持PHP FastCGI模式)
ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
libmcrypt-2.5.7.tar.gz
下面的有好多好多需要安装的软件包(前面有提过,我用的mini安装,所以很多包需要手动打,个人感觉除了麻烦了一点,其实挺不错的)
kernel-headers-2.6.32-71.el6.i686.rpm
compat-glibc-headers-2.5-46.2.i686.rpm
compat-glibc-2.5-46.2.i686.rpm
compat-libstdc++-33-3.2.3-69.el6.i686.rpm
compat-libf2c-34-3.4.6-19.el6.i686.rpm
compat-libgcc-296-2.96-144.el6.i686.rpm
mpfr-2.4.1-6.el6.i686.rpm
cpp-4.4.4-13.el6.i686.rpm
glibc-headers-2.12-1.7.el6.i686.rpm
glibc-devel-2.12-1.7.el6.i686.rpm
libgomp-4.4.4-13.el6.i686.rpm
libstdc++-devel-4.4.4-13.el6.i686.rpm
ppl-0.10.2-11.el6.i686.rpm
cloog-ppl-0.15.7-1.2.el6.i686
gcc-4.4.4-13.el6.i686.rpm
compat-gcc-34-3.4.6-19.el6.i686.rpm
compat-gcc-34-c++-3.4.6-19.el6.i686.rpm
make-3.81-19.el6.i686.rpm
keyutils-libs-devel-1.4-1.el6.i686.rpm
libcom_err-devel-1.41.12-3.el6.i686.rpm
libsepol-devel-2.0.41-3.el6.i686.rpm
libselinux-devel-2.0.94-2.el6.i686.rpm
krb5-devel-1.8.2-3.el6.i686.rpm
zlib-devel-1.2.3-25.el6.i686.rpm
openssl-devel-1.0.0-4.el6.i686.rpm
libXpm-3.5.8-2.el6.i686.rpm
gd-2.0.35-10.el6.i686.rpm
freetype-2.3.11-5.el6.i686.rpm
libxml2-2.7.6-1.el6.i686.rpm
libxml2-devel-2.7.6-1.el6.i686.rpm
curl-7.19.7-16.el6.i686.rpm
libjpeg-devel-6b-46.el6.i686.rpm
libjpeg-6b-46.el6.i686.rpm
libjpeg-static-6b-46.el6.i686.rpm
libpng-1.2.44-1.el6.i686.rpm
libpng-devel-1.2.44-1.el6.i686.rpm
libpng-static-1.2.44-1.el6.i686.rpm
php-common-5.3.2-6.el6.i686.rpm
php-gd-5.3.2-6.el6.i686.rpm
gcc-c++-4.4.4-13.el6.i686.rpm
ncurses-devel-5.7-3.20090208.el6.i686.rpm
ncurses-term-5.7-3.20090208.el6.i686.rpm
ncurses-static-5.7-3.20090208.el6.i686.rpm
perl-Pod-Escapes-1.04-115.el6.i686.rpm
perl-libs-5.10.1-115.el6.i686.rpm
perl-version-0.77-115.el6.i686.rpm
perl-Module-Pluggable-3.90-115.el6.i686.rpm
perl-Pod-Simple-3.13-115.el6.i686.rpm
perl-5.10.1-115.el6.i686.rpm
autoconf213-2.13-20.1.el6.noarch.rpm
autoconf-2.63-5.1.el6.noarch.rpm
automake-1.11.1-1.2.el6.noarch.rpm
automake14-1.4p6-19.2.el6.noarch.rpm
automake16-1.6.3-18.el6.1.noarch.rpm
libtool-ltdl-2.2.6-15.5.el6.i686.rpm
libtool-ltdl-devel-2.2.6-15.5.el6.i686.rpm
libtool-2.2.6-15.5.el6.i686.rpm
patch-2.6-6.el6.i686.rpm
把这些软件包啊用xshell自带的文件传输功能传输 或者 flashfxp 的sftp传输过去!再或者你可以挂载镜像~~~
建议装上vim 如果你和我环境一样的话,呵呵
————————————————————邪恶的分割线————————————————————
正式开始安装咯~~
下面均是采用xshell操作~
按照顺序依次安装,如果你嫌麻烦可直接复制以下命令(如果你不嫌麻烦....呵呵呵)
rpm -ivh kernel-headers-2.6.32-71.el6.i686.rpm rpm -ivh compat-glibc-headers-2.5-46.2.i686.rpm rpm -ivh compat-glibc-2.5-46.2.i686.rpm rpm -ivh compat-libstdc++-33-3.2.3-69.el6.i686.rpm rpm -ivh compat-libf2c-34-3.4.6-19.el6.i686.rpm rpm -ivh compat-libgcc-296-2.96-144.el6.i686.rpm rpm -ivh mpfr-2.4.1-6.el6.i686.rpm rpm -ivh cpp-4.4.4-13.el6.i686.rpm rpm -ivh glibc-headers-2.12-1.7.el6.i686.rpm rpm -ivh glibc-devel-2.12-1.7.el6.i686.rpm rpm -ivh libgomp-4.4.4-13.el6.i686.rpm rpm -ivh libstdc++-devel-4.4.4-13.el6.i686.rpm rpm -ivh ppl-0.10.2-11.el6.i686.rpm rpm -ivh cloog-ppl-0.15.7-1.2.el6.i686.rpm rpm -ivh gcc-4.4.4-13.el6.i686.rpm rpm -ivh compat-gcc-34-3.4.6-19.el6.i686.rpm rpm -ivh compat-gcc-34-c++-3.4.6-19.el6.i686.rpm rpm -ivh make-3.81-19.el6.i686.rpm rpm -ivh keyutils-libs-devel-1.4-1.el6.i686.rpm rpm -ivh libcom_err-devel-1.41.12-3.el6.i686.rpm rpm -ivh libsepol-devel-2.0.41-3.el6.i686.rpm rpm -ivh libselinux-devel-2.0.94-2.el6.i686.rpm rpm -ivh krb5-devel-1.8.2-3.el6.i686.rpm rpm -ivh zlib-devel-1.2.3-25.el6.i686.rpm rpm -ivh openssl-devel-1.0.0-4.el6.i686.rpm rpm -ivh libXpm-3.5.8-2.el6.i686.rpm rpm -ivh gd-2.0.35-10.el6.i686.rpm rpm -ivh freetype-2.3.11-5.el6.i686.rpm rpm -ivh libxml2-2.7.6-1.el6.i686.rpm rpm -ivh libxml2-devel-2.7.6-1.el6.i686.rpm rpm -ivh curl-7.19.7-16.el6.i686.rpm rpm -ivh libjpeg-devel-6b-46.el6.i686.rpm rpm -ivh libjpeg-6b-46.el6.i686.rpm rpm -ivh libjpeg-static-6b-46.el6.i686.rpm rpm -ivh libpng-1.2.44-1.el6.i686.rpm rpm -ivh libpng-devel-1.2.44-1.el6.i686.rpm rpm -ivh libpng-static-1.2.44-1.el6.i686.rpm rpm -ivh php-common-5.3.2-6.el6.i686.rpm rpm -ivh php-gd-5.3.2-6.el6.i686.rpm rpm -ivh gcc-c++-4.4.4-13.el6.i686.rpm rpm -ivh ncurses-devel-5.7-3.20090208.el6.i686.rpm rpm -ivh ncurses-term-5.7-3.20090208.el6.i686.rpm rpm -ivh ncurses-static-5.7-3.20090208.el6.i686.rpm rpm -ivh --nodeps perl-Pod-Escapes-1.04-115.el6.i686.rpm rpm -ivh --nodeps perl-libs-5.10.1-115.el6.i686.rpm rpm -ivh --nodeps perl-version-0.77-115.el6.i686.rpm rpm -ivh --nodeps perl-Module-Pluggable-3.90-115.el6.i686.rpm rpm -ivh --nodeps perl-Pod-Simple-3.13-115.el6.i686.rpm rpm -ivh --nodeps perl-5.10.1-115.el6.i686.rpm rpm -ivh autoconf213-2.13-20.1.el6.noarch.rpm rpm -ivh autoconf-2.63-5.1.el6.noarch.rpm rpm -ivh automake-1.11.1-1.2.el6.noarch.rpm rpm -ivh automake14-1.4p6-19.2.el6.noarch.rpm rpm -ivh automake16-1.6.3-18.el6.1.noarch.rpm rpm -ivh libtool-ltdl-2.2.6-15.5.el6.i686.rpm rpm -ivh libtool-ltdl-devel-2.2.6-15.5.el6.i686.rpm rpm -ivh libtool-2.2.6-15.5.el6.i686.rpm rpm -ivh patch-2.6-6.el6.i686.rpm
————————————————————邪恶的分割线————————————————————————
安装Mysql
解包mysql 并进行预配置
[root@itchenyi chenyi]# tar -zxf mysql-5.1.59.tar.gz [root@itchenyi chenyi]# cd mysql-5.1.59 [root@itchenyi mysql-5.1.59]# ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data/ --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-unix-socket-path=/tmp/mysql.sock --with-shared --without-debug --with-extra-charsets=all --without-embedded-server --enable-profiling --enable-assembler --enable-thread-safe-client --with-server-suffix=-community --with-extra-charset=utf8,gbk
编译 并 安装
[root@itchenyi mysql-5.1.59]# make && make install
更多精彩:转到www.itchenyi.com
特别注意:在执行make install编译的过程中,如果你看到屏幕突然不动了,卡在那里,很久都过不去,你一定认为编译错误了,或者服务器闹情绪了
,但是往往需要坚持,耐心的等待几分钟,就会编译成功!Mysql编译安装告诉我们,任何事情,只要坚持下去,终会成功!
对文件夹设置相应权限|建立配置文件|添加为系统服务
[root@itchenyi mysql-5.1.59]# chown -R root:mysql /usr/local/mysql/ [root@itchenyi mysql-5.1.59]# cd /usr/local/mysql/ [root@itchenyi mysql]# cp share/mysql/my-huge.cnf /etc/my.cnf [root@itchenyi mysql]# cp share/mysql/mysql.server /etc/init.d/mysqld
编辑 /etc/profile 在末行加入一下命令~
export PATH=$PATH:/usr/local/mysql/bin
下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。
[root@itchenyi mysql]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql [root@itchenyi mysql]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
生成mysql系统数据库~~
[root@itchenyi mysql]# /usr/local/mysql/bin/mysql_install_db --user=mysql &
启动mysql | 设置开机自启并给它来个密码~~~~
[root@itchenyi mysql]# chkconfig mysqld on [root@itchenyi mysql]# /etc/rc.d/init.d/mysqld start [root@itchenyi mysql]# mysqladmin -u root -p password 'chenyi'
mysql安装完毕~你可以mysql -u root -p回车输入密码测试一番了~
安装pcre
解包|预配置
[root@itchenyi chenyi]# tar zxf pcre-8.20.tar.gz [root@itchenyi chenyi]# mkdir /usr/local/pcre [root@itchenyi chenyi]# cd pcre-8.20 [root@itchenyi pcre-8.20]# ./configure --prefix=/usr/local/pcre/
编译|安装
[root@itchenyi pcre-8.20]# make && make install
安装nginx
解包|预配置
[root@itchenyi chenyi]# tar zxf nginx-1.0.6.tar.gz [root@itchenyi chenyi]# cd nginx-1.0.6 [root@itchenyi nginx-1.0.6]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/usr/local/src/pcre-8.20
注:--with-openssl=/usr/ --with-pcre=/usr/local/src/pcre-8.20 指向的路径是源码包解包的路径,并非其安装路径~~~否则会报错的哦!
编译|安装
[root@itchenyi nginx-1.0.6]# make && make install
启动,控制权限~
[root@itchenyi nginx-1.0.6]# /usr/local/nginx/sbin/nginx [root@itchenyi nginx-1.0.6]# chown nobody:nobody -R /usr/local/nginx/html/ [root@itchenyi nginx-1.0.6]# chmod 777 -R /usr/local/nginx/html/
设置nginx开机启动~~
vi /etc/rc.d/init.d/nginx 然后一字不漏的将以下代码复制进去~~
#!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/usr/local/nginx/logs/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid } reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL
赋权文件~~~|~~~加入自启
[root@itchenyi nginx-1.0.6]# chmod 755 /etc/rc.d/init.d/nginx [root@itchenyi nginx-1.0.6]# chkconfig nginx on [root@itchenyi /etc/rc.d/init.d/nginx restart 停止 nginx: [失败] 正在启动 nginx: [确定]
更多精彩:转到www.itchenyi.com
安装 libmcrypt| 一条命令完成安装,你要是不放心就拆开用~~~~
[root@itchenyi chenyi]tar zxf libmcrypt-2.5.7.tar.gz [root@itchenyi chenyi]cd libmcrypt-2.5.7 [root@itchenyi libmcrypt-2.5.7]# ./configure && make && make install
安装php 做到这一步 就可以去喝壶茶了~~~~~无奈啊。。。
解包|解包|打补丁|预配置|
[root@itchenyi chenyi]# tar -zxf php-5.2.17.tar.gz [root@itchenyi chenyi]# gunzip php-5.2.17-fpm-0.5.14.diff.gz [root@itchenyi chenyi]# patch -d php-5.2.17 -p1 <php-5.2.17-fpm-0.5.14.diff [root@itchenyi chenyi]# cd php-5.2.17 [root@itchenyi php-5.2.17]# ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv --with-freetype --with-jpeg --with-png --with-zlib --with-libxml --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --enable-suhosin --enable-session --with-mcrypt
编译|安装
[root@itchenyi php-5.2.17]# make && make install
建立配置文件
[root@itchenyi php5]# cd /usr/local/php5/ [root@itchenyi php5]# cp /chenyi/php-5.2.17/php.ini-dist /usr/local/php5/etc/php.ini [root@itchenyi php5]# rm -rf /etc/php.ini [root@itchenyi php5]# ln -s /usr/local/php5/etc/php.ini /etc/php.ini
编辑php-fpm.conf
vi /usr/local/php5/etc/php-fpm.conf
取消下面的注释 如图~
启动php-fpm 设置为开机自启
[root@itchenyi php5]# /usr/local/php5/sbin/php-fpm start [root@itchenyi php5]# cp /usr/local/php5/sbin/php-fpm /etc/rc.d/init.d/php-fpm 在#!/bin/bash下添加两行 #chkconfig:345 62 62 #description:php-fpm [root@itchenyi php5]# chmod 755 /etc/rc.d/init.d/php-fpm [root@itchenyi php5]# chkconfig php-fpm on
安装 Zend optimizer
[root@itchenyi chenyi]# tar zxf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz [root@itchenyi chenyi]# cp /chenyi/ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so /usr/local/zend [root@itchenyi chenyi]# rm -rf /chenyi/ZendOptimizer-3.3.9-linux-glibc23-i386
更多精彩:转到www.itchenyi.com
配置Zend optimizer
在末行加入一下内容
[Zend Optimizer] zend_optimizer.optimization_level=15 zend_extension="/usr/local/zend/ZendOptimizer.so"
重启web服务器
[root@itchenyi chenyi]# service nginx restart
停止 nginx: [确定]
正在启动 nginx: [确定]
[root@itchenyi chenyi]# service php-fpm restart
Shutting down php_fpm . done
Starting php_fpm done
配置nginx支持php
代码如下
location / { root html; index index.php index.html index.htm; #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; include fastcgi_params; } }
完成配置后重新启动~~~
[root@itchenyi chenyi]# service nginx restart
停止 nginx: [确定]
正在启动 nginx: [确定]
[root@itchenyi chenyi]# service php-fpm restart
Shutting down php_fpm . done
Starting php_fpm done
现在测试网站~~~~传个php探针上去一试便知~~~
[root@itchenyi html]# mv /root/tz.php ./ [root@itchenyi html]# chown nobody:nobody -R /usr/local/nginx/html/ [root@itchenyi html]# chmod 777 -R /usr/local/nginx/html/
各种支持~~~
如果你的php无法跟nginx相爱那么请检查路径的设置~~~~
转载于:https://blog.51cto.com/itchenyi/1085827