搭建LANMP实现反向代理及负载均衡

试验要求:

在一台CentOS 6.5服务器上安装Apache、Nginx、PHP、Mysql服务。Apache处理动态PHP页面,Nginx作为前端服务器处理静态页面,并实现Nginx反向代理。

 

1、在安装前我们需要检查这些包安装没有,如何安装了我就卸载掉,并关闭防火墙。保证一台干净的服务器。

 

[root@localhost ~]#service iptables stop

[root@localhost ~]#chkconfig iptables off

[root@localhost ~]#vim /etc/sysconfig/selinux

  修改此内容:SELINUX=disabled

[root@localhost ~]#rpm -qa httpd          

[root@localhost ~]#rpm -qa php

[root@localhost ~]#rpm -qa nginx

[root@localhost ~]#rpm -qa mysql

[root@localhost ~]#yum -y remove httpd    {此处卸载只限于yum安装过的程序}

[root@localhost ~]#yum -y remove php

[root@localhost ~]#yum -y remove nginx

[root@localhost ~]#yum -y remove mysql

 

 

2、这儿我们采用第三方源,因为在虚拟机里默认是没有Nginx的安装包的。

 

[root@localhost ~]#cd /etc/yum.repos.d/

[root@localhost ~]#wget http://www.atomicorp.com/installers/atomic

[root@localhost ~]#sh ./atomic

[root@localhost ~]#yum check-update

 

3、安装Apache并修改端口为:8080  >>{因为Nginx会占用80端口}

 

[root@localhost ~]#yum install httpd
[root@localhost ~]#vim /etc/httpd/conf/httpd.conf

找到:Listen 80 修改为:Listen 8080

ServerName www.example.com:80 #注解去掉,改为相应的端口和域名 >>{访问WEB可以直接使用域名}

[root@localhost ~]#service httpd start

[root@localhost ~]#chkconfig httpd on

安装Apache扩展库

[root@localhost ~]#yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

 

4、安装PHP

 

[root@localhost ~]#yum install php php-devel php-mysql gd php-gd gd-devel php-common php-mbstring php-mcrypt php-ldap php-pear php-xml php-xmlrpc php-imap php-curl

[root@localhost ~]#vim /etc/php.ini    >>{编辑修改增加内容}

cgi.fix_pathinfo =1 #将注释去掉,开启PHP的pathinfo功能,伪静态要用到。

max_execution_time = 0  #脚本运行的最长时间,默认30秒
max_input_time = 300#脚本可以消耗的时间,默认60秒
memory_limit = 256M#脚本运行最大消耗的内存,根据你的需求更改数值,默认128M
post_max_size = 100M  #单提交的最大数据,此项不是限制上传单个文件的大小,而是针对整个表单的提交数据进行限制的。限制范围包括表单提交的所有内容.例如:发表贴子时,贴子标题,内容,附件等…默认8M,这个值一定大于upload_max_filesize
upload_max_filesize = 10M#上载文件的最大许可大小 ,默认2M

 

5、安装Mysql

 

[root@localhost ~]#yum install mysql mysql-server mysql-devel

[root@localhost ~]#service mysqld start

[root@localhost ~]#chkconfig mysqld on

[root@localhost ~]#mysql -u root

安装好的Mysql数据库默认是没有密码的,为了安全我们可以设置一个密码

[root@localhost ~]#mysqladmin -u root password 123456    >>{密码是123456 回车即可}

[root@localhost ~]#mysql -u root -p {回车输入密码即可,或者mysql -u root -p123456}

 

6、安装nginx

 

[root@localhost ~]#yum install nginx

[root@localhost ~]#service nginx start

[root@localhost ~]#chkconfig nginx on

修改配置文件,实现反向代理

[root@localhost ~]#vim /etc/nginx/conf.d/default.conf

#修改location / 为以下内容,让其根目录与Apache的目录相同。
location / {
            root   /var/www/html;
            index  index.html index.php index.htm;
}

添加以下内容

location ~ \.php$ {

            proxy_pass  http://127.0.0.1:8080;}

 

猜你喜欢

转载自kangh.iteye.com/blog/2298557
今日推荐