首先,安装nginx-1.0.13
配置好本地yum源,rpm -q 检查一下需要的开发组件是否安装,如果没有,则先安装
yum install gcc openssl-devel pcre-devel zlib-devel
然后,为nginx创建系统用户,系统组
# groupadd -r nginx
# useradd -r -g nginx -s /bin/false -M nginx
下面我们就开始安装nginx了,解压nginx压缩包
# tar xf nginx-1.0.13.tar.gz
切换至nginx-1.0.13目录下:
# ./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
接着。为nginx提供服务脚本
# 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 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
为其增加执行权限:
# chmod +x /etc/rc.d/init.d/nginx
加入服务列表
# chkconfig --add nginx
开机启动
# chkconfig nginx on
然后就可以开启nginx服务了 ,开启之前要确定80端口没被占用。
安装mysql-5.5.20
1、准备数据存放的文件系统
新建一个逻辑卷,并将其挂载至特定目录:
首先要有一个8e格式的磁盘分区,我们以sda5为例;
创建物理卷:pvcreate /dev/sda5
创建卷组:vgcreate myvg /dev/sda5
创建逻辑卷:lvcreate -L 4G -n mydata myvg
格式化:mkfs -t ext3 /dev/myvg/mydata
# vim /etc/fstab
开机自动挂载至/mydata目录
/dev/myvg/mydata /mydata ext3 defults 0 0
这里设定其逻辑卷的挂载目录为/mydata,而后需要创建/mydata/data目录做为mysql数据的存放目录。
2、新建用户以安全方式运行进程:
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
# chown -R mysql:mysql /mydata/data
3、安装并初始化mysql-5.5.20
首先下载平台对应的mysql版本至本地
# tar xf mysql-5.5.19-linux2.6-i686.tar.gz -C /usr/local
# cd /usr/local/
# ln -sv mysql-5.5.19-linux2.6-i686 mysql
# cd mysql
# chown -R mysql:mysql .
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
# chown -R root .
4、为mysql提供主配置文件:
# cd /usr/local/mysql
# cp support-files/my-large.cnf /etc/my.cnf
并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
thread_concurrency = 2
另外还需要添加如下行指定mysql数据文件的存放位置:
datadir = /mydata/data
5、为mysql提供sysV服务脚本:
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
添加至服务列表:
# chkconfig --add mysqld
# chkconfig mysqld on
而后就可以启动服务测试使用了。
安装php-5.3.10
解决依赖关系,需要安装:
# yum -y groupinstall "X Software Development"
里外还需要几个额外的扩展软件:
libmcrypt mcrypt mhash libiconv
下载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
libevent-2.0.17-2.i386.rpm
libevent-devel-2.0.17-2.i386.rpm
用rpm命令安装
接下来编译安装php
# tar xf php-5.3.10.tar.bz2
# cd php-5.3.10
# --with-openssl --enable-fpm --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/php --with-config-file-scan-dir=/etc/php --with-bz2
--with-curl --with-iconv=/usr/local
# make ZEND_EXTRA_LIBS='-liconv'
# make install
安装结束,复制配置文件
# mkdir /etc/php
# cp php.ini-production /etc/php/php.ini
提供php启动需要的配置文件
启动fastcgi:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# vim /usr/local/php/etc/php-fpm.conf
启用如下选项:
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
并将
;pid = run/php-fpm.pid
;去掉,表示启用此功能。
这是我们可以使用命令/usr/local/php/sbin/php-fpm直接启动php,也可以通过service启动
但需要一些配置:
# cd php-5.3.10
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# vim php-fpm
加入下一行:
# chkconfig: -84 16
# chmod +x /etc/rc.d/init.d/php-fpm
# chkcnfig --add php-fpm
结合nginx和php
# vim /etc/nginx/nginx.conf
启用location ~\.php$ { ... }
想在那个虚拟主机启用php,把上述内容写在server里面就可以了。
# vim /etc/nginx/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;
# service nginx restart
LNMP 平台就初步搭建好了
转载于:https://blog.51cto.com/4394407/809871