源码编译实现企业级LNMP平台

编译安装nginx需要事先需要安装开发包组”DevelopmentTools”和”Server Platform Development”。同时,还需要专门安装pcre-devel包

[root@yong ~]# yum groupinstall “Development tools” “Server Platform Development”[root@yong ~]# yum -y install pcre-devel

2、编译安装Nginx

首先添加用户nginx,实现以之运行nginx服务进程:

[root@yong ~]# useradd -r nginx

其次解压缩nginx查看介绍编译安装选项:

[root@yong ~]# tar xf nginx-1.4.2.tar.gz#解压nginx[root@yong ~]# cd nginx-1.4.2#切换目录[root@yong nginx-1.4.2]# ./configure –help | less#查看编译选项–helpprint this message –prefix=PATHset installation prefix#目录 –sbin-path=PATHset nginx binary pathname#二进制程序的安装目录 –conf-path=PATHset nginx.conf pathname#配置文件路径 –error-log-path=PATHset error log pathname#错误路径 –pid-path=PATHset nginx.pid pathname#pid路径 –lock-path=PATHset nginx.lock pathnamelock路径 –user=USERset non-privileged user for worker processes#以哪个身份运行 –group=GROUPset non-privileged group for worker processes#以哪个组的身份运行 –builddir=DIRset build directory –with-rtsig_moduleenable rtsig module#启用实时信号模块 –with-select_moduleenable select module#支持select机制模块 –without-select_moduledisable select module –with-poll_moduleenable poll module –without-poll_moduledisable poll module –with-file-aioenable file AIO support#支持文件的AIO机制的,重要的特性增强 –with-ipv6enable IPv6 support –with-http_ssl_moduleenable ngx_http_ssl_module#支持SSL功能–with-http_flv_moduleenable ngx_http_flv_module#支持flv流媒体###############更多选项笔者就不在介绍了###########################我们这里用到的选项如下##############[root@yong nginx-1.4.2]# ./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##############安装######################[root@yong nginx-1.4.2]# make && make install

[root@yong ~]# vim /etc/nginx/nginx.conf#user nobody;worker_processes 1;#启动多少个进程(和CPU的核心个数相关)#error_log logs/error.log;#错误日志定义#error_log logs/error.log notice;#error_log logs/error.log info;#由于我们此前编译时已经指定了错误日志位置所以这里默认注释掉了。#pidlogs/nginx.pid;events {worker_connections 1024;#一个进程允许多少个连接进来(受限于当前用户所能够打开的最大数(ulimit –n 查看最大数))}#################以上这些为全局配置文件##############http {#####这些为http服务相关的配置信息####includemime.types;default_type application/octet-stream;#定义默认类型#log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘ #日志格式#’$status $body_bytes_sent “$http_referer” ‘#'”$http_user_agent” “$http_x_forwarded_for”‘;#'”$http_user_agent” “$http_x_forwarded_for”‘;#access_log logs/access.log main;sendfileon;#支持sendfile(sendfile:提升文件传输速率)#tcp_nopushon;#keepalive_timeout 0;keepalive_timeout 65;#是否支持长连接#gzip on;server {###在nginx中至少有一个虚拟主机,它不支持中心主机listen80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {#匹配的是URL文件,location=…表示精确匹配root html;index index.html index.htm;}##############下面就不在一一介绍了############

4、Nginx启动

首先确保本台服务器上httpd进程已关闭,因为端口一致会征用同一套接字。

提供SysVinit脚本:

[root@yong ~]# vim /etc/rc.d/init.d/nginx#新建文件###############添加如下内容##############!/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 0nginx=”/usr/sbin/nginx”prog=$(basename $nginx)NGINX_CONF_FILE=”/etc/nginx/nginx.conf”[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxmake_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; doif [ `echo $opt | grep ‘.*-temp-path’` ]; thenvalue=`echo $opt | cut -d “=” -f 2`if [ ! -d “$value” ]; then# echo “creating” $valuemkdir -p $value && chown -R $user $valuefifi done}start() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6make_dirsecho -n $”Starting $prog: “daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval}stop() {echo -n $”Stopping $prog: “killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval}restart() {configtest || return $?stopsleep 1start}reload() {configtest || return $?echo -n $”Reloading $prog: “killproc $nginx -HUPRETVAL=$?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” instart)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 2esac#################为此脚本赋予执行权限##########################[root@yong ~]# cd /etc/rc.d/init.d/[root@yong init.d]# chmod +x nginx#################添加之服务管理列表,开机自启动################[root@yong init.d]# chkconfig –add nginx[root@yong init.d]# chkconfig nginx on#################启动服务器####################################[root@yong init.d]# service nginx startStarting nginx:[ OK ]#################查看进程启动状况#############################[root@yong ~]# ps aux | grep nginx

5、访问网页

二:编译安装配置mysql

享受每一刻的感觉,欣赏每一处的风景,这就是人生。

源码编译实现企业级LNMP平台

相关文章:

你感兴趣的文章:

标签云: