fdsfdfe 发表于 2015-8-14 08:45:42

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)组合不稳定的原因造成的。
实验机:

1
2
3
4
5
# 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
# cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m





[*]源码安装LNAMP之Nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# yum install pcre pcre-devel -y      #依赖包

# tar -xzvf nginx-1.8.0.tar.gz

# ./configure--prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

# make && make install

# /usr/local/nginx/sbin/nginx

# ps -ef | grep nginx   
root      9982   10 19:38 ?      00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    998399820 19:38 ?      00:00:00 nginx: worker process      
root      998775770 19:38 pts/1    00:00:00 grep nginx





[*]源码安装LNAMP之Apache

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# yum -y install epel-release

# ./configure --prefix=/usr/local/apr

# make && make install

# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

# make && make install



# ./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

# make && make install





[*]源码安装LNAMP之MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
yum install gcc gcc-c++ make cmakencurses-devel bison perl

# 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

#make && make install


# cp -a support-files/my-large.cnf /data/mysql3306/my.cnf

# chown mysql.mysql app/ -R
# chown mysql.mysql mysql3306/ -R

# cp -a support-files/mysql.server /etc/init.d/mysqld


# cd /data/app/mysql3306/


# ./scripts/mysql_install_db --basedir=/data/app/mysql3306/ --datadir=/data/mysql3306/ --user=mysql

#echo "export PATH="\$PATH":/data/app/mysql3306/bin/" >>/root/.bash_profile && source /root/.bash_profile

# /etc/init.d/mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL.. SUCCESS!





[*]源码安装LNAMP之PHP

1
2
3
4
5
6
7
yum install libxml2-devellibmcrypt-devel bzip2-devel
libxml2-devel openssl-develbzip2 bzip2-devel

# ./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


# make && make install





[*]源码安装Apache+PHP整合

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# echo "Addtype application/x-httpd-php.php" >> /usr/local/apache/conf/httpd.conf

# sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/g' /usr/local/apache/conf/httpd.conf


# /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即可

# /usr/local/apache/bin/apachectl -t
Syntax OK

# ps -ef | grep http
root   23847   10 21:05 ?      00:00:00 /usr/local/apache/bin/httpd -k restart
daemon   23849 238470 21:05 ?      00:00:00 /usr/local/apache/bin/httpd -k restart
daemon   23850 238470 21:05 ?      00:00:00 /usr/local/apache/bin/httpd -k restart
daemon   23851 238470 21:05 ?      00:00:00 /usr/local/apache/bin/httpd -k restart
daemon   23937 238470 21:06 ?      00:00:00 /usr/local/apache/bin/httpd -k restart
root   23973 226110 21:10 pts/1    00:00:00 grep http

# cd /usr/local/apache/htdocs/

在index.php里添加
<?php
phpinfo();
?>
~在客户端输入http://192.168.77.189/ 测试得到以下页面







[*]源码安装DISCUZ论坛
下载discuz源码包文件

1
2
3
4
5
6
7
8
9
10
# wget

# unzip Discuz_X3.1_SC_UTF8.zip -d /usr/local/apache/htdocs/

# cd /usr/local/apache/htdocs/;mv upload/* .

# chmod 777 -R data/ uc_server/ config/ uc_client/


然后访问http://192.168.77.189/安装discuz论坛,如下图,选择“我同意”






数据库授权:

1
2
3
4
5
6
7
# /data/app/mysql3306/bin/mysql   登录,这里数据库没有设置密码


mysql> create database discuz charset=utf8;


grant all on discuz.* toidentified by "123456";   授权




然后在论坛页面输入账号信息一路下一步就安装成功了。。。。。。。。。。

自此LAMP环境整合并搭建成功,那如何使用Nginx来整合LAMP呢?

[*]源码安装Nginx+LAMP整合
先修改apache访问端口为8080,Nginx端口默认为80然后修改nginx配置文件: vi/usr/local/nginx/conf/nginx.conf,server配置段内容如下:(定义upstream均衡模块,配置动静分离,动态转发至apache,静态文件直接本地响应),这里配置的有动静分离,,动态走app_lamp;模块静态走本地目录,,由于一台机器上实现,有点局限性,理解:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
upstreamapp_lamp {
    server127.0.0.1:8080 weight=1 max_fails=2 fail_timeout=30s;
    }
    server {
      listen       80;
      server_namelocalhost;

      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源码全部整合完毕


页: [1]
查看完整版本: LNAMP源码安装整合加论坛及动静分离