LNAMP(Linux+Nginx+Apache+Mysql+PHP)架构受到很多IT企业的青睐,取代了原来认为很好的LNMP(Linux+Nginx+Mysql+PHP)架构。
那我们说LNAMP到底有什么优点呢,还得从Nginx和apache的优缺点说起。
1)Nginx处理静态文件能力很强
2)Apache处理动态文件很强而且很稳定,把二者综合在一块,性能提升很多倍。
可能很多Linux SA在从事LNMP运维中,会发现PHP(FastCGI)模式会出现一些502错误的现象,这是因为Nginx+PHP(FastCGI)组合不稳定的原因造成的。
源码安装LNAMP之Nginx
yum install prce-devel -y;cd /usr/src ;wget http://nginx.org/download/nginx-1.6.0.tar.gz ;cd nginx-1.6.0;./configure -prefix=/usr/local/nginx && make && make install源码安装LNAMP之Apacheyum install apr-devel apr-util-devel –y;cd /usr/src ; wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.27.tar.gz ;tar xzf httpd-2.2.27.tar.gz ;cd httpd-2.2.27 ;./configure--prefix=/usr/local/apache --enable-so --enable-rewrite && make&& make install源码安装LNAMP之MySQLcd/usr/src ;wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.63.tar.gz ;tar xzf mysql-5.1.63.tar.gz ;cd mysql-5.1.63;./configure --prefix=/usr/local/mysql--enable-assembler && make && make install配置Mysql服务为系统服务:cp/usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnfcp/usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqldchkconfig --add mysqldchkconfig --level 345 mysqld oncd /usr/local/mysqluseraddmysqlchown -R mysql.mysql /usr/local/mysql/usr/local/mysql/bin/mysql_install_db --user=mysql chown -R mysql var/usr/local/mysql/bin/mysqld_safe --user=mysql &
源码安装LNAMP之PHP
cd/usr/src ;wget http://mirrors.sohu.com/php/php-5.3.28.tar.bz2 ;tar jxf php-5.3.28.tar.bz2 ;cd php-5.3.28 ;./configure --prefix=/usr/local/php5--with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql/源码安装Apache+PHP整合
整合apache+php环境,修改httpd.conf配置文件,然后加入如下语句:
LoadModule php5_modulemodules/libphp5.so (默认已存在)
AddType application/x-httpd-php .php
DirectoryIndex index.phpindex.html (把index.php加入index.html之前)
然后在/usr/local/apache/htdocs目录下创建index.php测试页面,执行如下命令:
cat>>/usr/local/apache/htdocs/index.php <<EOF
<?php
phpinfo();
?>
EOF
重新启动apache服务,通过IP访问界面如下图,即代表LAMP环境搭建成功。
源码安装DISCUZ论坛下载discuz源码包文件,然后解压:cd /usr/src ;wget http://download.comsenz.com/DiscuzX/3.1/Discuz_X3.1_SC_UTF8.zip解压discuz程序包:unzip Discuz_X3.1_SC_UTF8.zip -d/usr/local/apache/htdocs/重命名程序文件:cd /usr/local/apache/htdocs/ ;mv upload/* .赋予discuz目录完全访问权限:cd /usr/local/apache/htdocs/;chmod 777 -R data/ uc_server/ config/ uc_client/然后访问IP安装discuz论坛,如下图,选择“我同意”
进入如下界面,数据库安装,如果不存在则需要新建数据库并授权。
点击下一步,直至安装完成,进入等待已久的论坛画面:
自此LAMP环境整合并搭建成功,那如何使用Nginx来整合LAMP呢?
源码安装Nginx+LAMP整合
先修改apache访问端口为8080,Nginx端口为80。
然后修改nginx配置文件: vi /usr/local/nginx/conf/nginx.conf,server配置段内容如下:
(定义upstream均衡模块,配置动静分离,动态转发至apache,静态文件直接本地响应)
upstream app_lamp {
server 127.0.0.1:8080 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
location / {
root /usr/local/apache/htdocs;
index index.php index.html index.htm;
}
location ~ .*\.(php|jsp|cgi)?$
{
proxy_set_header Host $host;
proxy_set_header X-Real-IP$remote_addr;
proxy_set_header X-Forwarded-For$proxy_add_x_forwarded_for;
proxy_pass http://app_lamp;
}
location ~.*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root /usr/local/apache/htdocs;
expires 3d;
}
}
测试,访问nginx ip+port如下图所示:
查看系统启动的端口及进程如下图:
自此,LNAMP全部整合完毕,接下来就是对系统内核、各个服务、架构进行优化.