标签:lnamp
LNAMP(Linux+Nginx+Apache+Mysql+PHP)架构受到很多IT企业的青睐,取代了原来认为很好的LNMP(Linux+Nginx+Mysql+PHP)架构,那我们说LNAMP到底有什么优点呢,还得从Nginx和apache的优缺点说起。
Nginx处理静态文件能力很强,Apache处理动态文件很强而且很稳定,把二者综合在一块,性能提升很多倍。可能很多Linux SA在从事LNMP运维中,会发现PHP(FastCGI)模式会出现一些502错误的现象,这是因为Nginx+PHP(FastCGI)组合不稳定的原因造成的。
实验机:
[root@192_168_77_189 ~]# uname -a Linux 192_168_77_189 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux [root@192_168_77_189 ~]# cat /etc/issue CentOS release 6.6 (Final) Kernel \r on an \m
源码安装LNAMP之Nginx
[root@192_168_77_189 ~]# yum install pcre pcre-devel -y #依赖包 [root@192_168_77_189 autolamp]# tar -xzvf nginx-1.8.0.tar.gz [root@192_168_77_189 nginx-1.8.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module [root@192_168_77_189 nginx-1.8.0]# make && make install [root@192_168_77_189 nginx-1.8.0]# /usr/local/nginx/sbin/nginx [root@192_168_77_189 nginx-1.8.0]# ps -ef | grep nginx root 9982 1 0 19:38 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx nobody 9983 9982 0 19:38 ? 00:00:00 nginx: worker process root 9987 7577 0 19:38 pts/1 00:00:00 grep nginx
源码安装LNAMP之Apache
[root@192_168_77_189 autolamp]# yum -y install epel-release [root@192_168_77_189 apr-1.5.2]# ./configure --prefix=/usr/local/apr [root@192_168_77_189 apr-1.5.2]# make && make install [root@192_168_77_189 apr-util-1.5.2]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@192_168_77_189 apr-util-1.5.2]# make && make install [root@192_168_77_189 httpd-2.4.16]# ./configure --prefix=/usr/local/apache --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event [root@192_168_77_189 httpd-2.4.16]# make && make install
源码安装LNAMP之MySQL
yum install gcc gcc-c++ make cmake ncurses-devel bison perl [root@192_168_77_189 mysql-5.5.44]# cmake -DCMAKE_INSTALL_PREFIX=/data/app/mysql3306 -DMYSQL_DATADIR=/data/mysql3306 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 -DMYSQL_USER=mysql -DMYSQL_UNIX_ADDR=/data/mysql3306/mysql3306.sock [root@192_168_77_189 mysql-5.5.44]# make && make install [root@192_168_77_189 mysql-5.5.44]# cp -a support-files/my-large.cnf /data/mysql3306/my.cnf [root@192_168_77_189 data]# chown mysql.mysql app/ -R [root@192_168_77_189 data]# chown mysql.mysql mysql3306/ -R [root@192_168_77_189 mysql3306]# cp -a support-files/mysql.server /etc/init.d/mysqld [root@192_168_77_189 mysql3306]# cd /data/app/mysql3306/ [root@192_168_77_189 mysql3306]# ./scripts/mysql_install_db --basedir=/data/app/mysql3306/ --datadir=/data/mysql3306/ --user=mysql [root@192_168_77_189 mysql3306]# echo "export PATH="\$PATH":/data/app/mysql3306/bin/" >>/root/.bash_profile && source /root/.bash_profile [root@192_168_77_189 mysql3306]# /etc/init.d/mysqld restart Shutting down MySQL. SUCCESS! Starting MySQL.. SUCCESS!
源码安装LNAMP之PHP
yum install libxml2-devel libmcrypt-devel bzip2-devel libxml2-devel openssl-devel bzip2 bzip2-devel [root@192_168_77_189 php-5.4.42]# ./configure --prefix=/usr/local/php --with-mysql=/data/app/mysql3306 --with-openssl --with-mysqli=/data/app/mysql3306/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-bz2 --with-config-file-path=/etc/php/php.ini --with-config-file-scan-dir=/etc/php/php.d/ --with-apxs2=/usr/local/apache/bin/apxs [root@192_168_77_189 php-5.4.42]# make && make install
源码安装Apache+PHP整合
[root@192_168_77_189 php-5.4.42]# echo "Addtype application/x-httpd-php .php" >> /usr/local/apache/conf/httpd.conf [root@192_168_77_189 php-5.4.42]# sed -i ‘s/DirectoryIndex index.html/DirectoryIndex index.php index.html/g‘ /usr/local/apache/conf/httpd.conf [root@192_168_77_189 php-5.4.42]# /usr/local/apache/bin/apachectl -t 00557: httpd: apr_sockaddr_info_get() failed for 192_168_77_189 AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName‘ directive globally to suppress this message Syntax OK ServerName www.example.com:80改成ServerName localhost:80即可 [root@192_168_77_189 conf]# /usr/local/apache/bin/apachectl -t Syntax OK [root@192_168_77_189 conf]# ps -ef | grep http root 23847 1 0 21:05 ? 00:00:00 /usr/local/apache/bin/httpd -k restart daemon 23849 23847 0 21:05 ? 00:00:00 /usr/local/apache/bin/httpd -k restart daemon 23850 23847 0 21:05 ? 00:00:00 /usr/local/apache/bin/httpd -k restart daemon 23851 23847 0 21:05 ? 00:00:00 /usr/local/apache/bin/httpd -k restart daemon 23937 23847 0 21:06 ? 00:00:00 /usr/local/apache/bin/httpd -k restart root 23973 22611 0 21:10 pts/1 00:00:00 grep http [root@192_168_77_189 ~]# cd /usr/local/apache/htdocs/ 在index.php里添加 <?php phpinfo(); ?> ~ 在客户端输入http://192.168.77.189/ 测试得到以下页面
源码安装DISCUZ论坛
下载discuz源码包文件
[root@192_168_77_189 ~]# wget [root@192_168_77_189 autolamp]# unzip Discuz_X3.1_SC_UTF8.zip -d /usr/local/apache/htdocs/ [root@192_168_77_189 autolamp]# cd /usr/local/apache/htdocs/;mv upload/* . [root@192_168_77_189 htdocs]# chmod 777 -R data/ uc_server/ config/ uc_client/ 然后访问http://192.168.77.189/安装discuz论坛,如下图,选择“我同意”
数据库授权:
[root@192_168_77_189 ~]# /data/app/mysql3306/bin/mysql 登录,这里数据库没有设置密码 mysql> create database discuz charset=utf8; grant all on discuz.* to identified by "123456"; 授权
然后在论坛页面输入账号信息一路下一步就安装成功了。。。。。。。。。。
自此LAMP环境整合并搭建成功,那如何使用Nginx来整合LAMP呢?
源码安装Nginx+LAMP整合
先修改apache访问端口为8080,Nginx端口默认为80
然后修改nginx配置文件: vi/usr/local/nginx/conf/nginx.conf,server配置段内容如下:
(定义upstream均衡模块,配置动静分离,动态转发至apache,静态文件直接本地响应),这里配置的有动静分离,,动态走app_lamp;模块静态走本地目录,,由于一台机器上实现,有点局限性,理解:
upstreamapp_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; } }
在客户端输入http://192.168.77.189可以直接访问,,动态图片图片程序走app_lamp模块里面的主机,当然可以是另外的机器,静态网页走的是本地
自此,LNAMP源码全部整合完毕
软件包太大无法上传。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
标签:lnamp
原文地址:http://woshitieren.blog.51cto.com/2466034/1684485