您的位置:首页 > 运维架构 > Nginx

Nginx搭建集群服务器过程详解

2016-07-12 15:12 731 查看
Nginx+Apache+PHP+MySQL搭建集群服务器过程详解

概念介绍在本文未能提及,请自助上网科普,直接进入过程详解:

集群架构图大致如下:


       

    
一、软件下载

序号
软件名称
软件版本
下载地址
1
操作系统
Windows Server 2008 Enterprise 64bit
 
2
Php
php-5.6.19-Win32-VC11-x64 Thread Safe(由于HTTP服务器用的apache)
http://windows.php.net/downloads/releases/php-5.6.19-Win32-VC11-x64.zip
3
VC11
Visual C++ Redistributable for Visual Studio 2012 Update 4(VSU_4\vcredist_x64.exe)
https://www.microsoft.com/en-us/download/confirmation.aspx?id=30679
4
Nginx
nginx/Windows-1.8.1
http://nginx.org/download/nginx-1.8.1.zip
5
Apache
Apache 2.4.18 x64
http://www.apachehaus.com/cgi-bin/download.plx?dli=gVwkjeaVVQy4ERntWTWFVMKVlUGR1UwZ3UVRGU
6
MySql
mysql-5.7.11.0
- win
x64
http://dev.mysql.com/get/Downloads/MySQLInstaller/mysql-installer-community-5.7.11.0.msi
7
Navicate
Navicat Premium
x64
 
http://download3.navicat.com/download/navicat112_premium_en_x64.exe
8
PHPmyadmin
phpMyAdmin-4.4.15.5-all-languages
https://files.phpmyadmin.net/phpMyAdmin/4.4.15.5/phpMyAdmin-4.4.15.5-all-languages.zip
 
二、VC11安装与配置
根据PHP版本选择安装对应版本的VC,php5.6对应的是VC11,根据VC11应用程序安装指引安装VC11。

 
三、PHP安装与配置

解压PHP安装包到C:\Program Files\php-5.6.19-Win32-VC11-x64;
在系统环境变量PATH中添加 ;C:\Program Files\php-5.6.19-Win32-VC11-x64;C:\Program Files\php-5.6.19-Win32-VC11-x64\ext,重启后生效,此步骤对于phpmyadmin的安装十分重要;
模块加载配置: extension_dir = "C:\Program Files\php-5.6.19-Win32-VC11-x64\ext"。

 
四、Apache安装与配置
解压Apache安装包到C:\Program
Files\Apache24;
修改C:\Program Files\Apache24\conf\httpd.conf;      
                     a. Define SRVRROOT改为Apache的安装路径:

Define SRVROOT "C:/Program
Files/Apache24"


Listen 80改为Listen 8080;
LoadModule最后加入PHP5的配置信息;
#LoadModulephp5 support
LoadModule php5_module "C:/Program
Files/php-5.6.19-Win32-VC11-x64/php5apache2_4.dll"

AddTypeapplication/x-httpd-php .php .html .htm
#configurethe path to php.ini
PHPIniDir "C:/ProgramFiles/php-5.6.19-Win32-VC11-x64"
保存httpd.conf文件的修改。

3. 创建Apache2.4服务,具体命令:

-> C:Program Files\Apache24\bin\httpd.exe -k install -n"Apache2.4"
Tips:删除Apache2.4服务命令:

-> C:Program Files\Apache24\bin\httpd.exe -k uninstall -n"Apache2.4"

4. 使用命令行或应用程序重启httpd.exe;

5. 在浏览器中访问http://localhost:8080检查Apache页面是否配置正确,出现“It
works”页面表示安装成功;



 
在C:\Program
Files\Apache24\htdocs\中创建test.php,文件内容为:

<?php  phpinfo(); ?>


在浏览器中访问http://localhost/test.php看是否能访问PHP页面以检查php是否配置正确;



 
五、Nginx安装与配置
上述软件安装成功后,开始着手配置安装Nginx

安装nginx:解压到C:\Program
Files\nginx-1.8.1,到解压目录下运行nginx.exe;

 

在浏览器中输入http://lcoalhost/检查Nginx是否配置正确,出现“Welcome
to nginx!”页面则表示安装成功;



 

打开nginx配置文件conf/nginx.conf,在http模块下配置服务器集群信息;

    upstreammyCluster {

        server ip address1 : 8080 ;

        server ip address2 : 8081 ;

    }
然后在server模块中加入

    location ~\.php$ {

        proxy_pass  http://myCluster;

        proxy_redirect     off;

        proxy_set_header   Host             $host;

        proxy_set_header   X-Real-IP        $remote_addr;

        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

    }

 

分别在2个apache的htdocs下新建两个test.php文件,区分内容以便后面辨别负载均衡是否成功;
在浏览器中分别输入http://localhost/ http://localhost/test.php试试;
Nginx service服务创建
下载windows service wrapper,如下载的是winsw-1.7-bin.exe
将winsw-1.7-bin.exe更名为nginx-service.exe,并将它复制到nginx的安装目录
在同一个目录创建Windows Service Wrapper的XML配置文件,名称必须为nginx-service.xml
nginx-service.xml的内容为:

<?xmlversion="1.0" encoding="UTF-8" ?>
<service>
<id>nginx</id>
<name>NginxService</name>
<description>HighPerformance Nginx Service</description>
<executable>C:\ProgramFiles\nginx-1.8.1\nginx.exe</executable>
<logpath>C:\ProgramFiles\nginx-1.8.1</logpath>
<logmode>roll</logmode>
<depend></depend>
<startargument>-pC:\Program Files\nginx-1.8.1</startargument>
<stopargument>-pC:\Program Files\nginx-1.8.1 -s stop</stopargument>
</service>

在命令行下执行nginx-service.exe install
按照上述步骤操作即可在Windows服务列表看到Nginx
Service服务了

 
六、 Mysql安装与配置

运行mysql-5.7.11.msi,更具可视化安装界面,据自己需求操作即可;
打开SQL命令行,输入默认账号root的密码,进入Mysql命令行操作界面,即可验证数据库是否安装正确;

 
七、 PhpMyAdmin安装
将安装包解压或上传到服务器的Web文件目录,即G:\Program
Files\Apache24\htdocs中;
修改配置文件C:\Program Files\Apache24\htdocs\phpmyadmin\libraries\config.default.php;
/**
 * Your phpMyAdmin URL.
 *
 * Complete the variable below with the fullURL ie
 *   http://www.your_web.net/path_to_your_phpMyAdmin_directory/
 *
 * It must contain characters that are validfor a URL, and the path is
 * case sensitive on some Web servers, forexample Unix-based servers.
 *
 * In most cases you can leave this variableempty, as the correct value
 * will be detected automatically. However, werecommend that you do
 * test to see that the auto-detection codeworks in your system. A good
 * test is to browse a table, then edit a rowand save it.  There will be
 * an error message if phpMyAdmin cannotauto-detect the correct value.
 *
 * @global string $cfg['PmaAbsoluteUri']
 */
$cfg['PmaAbsoluteUri'] = 'http://yourdomain/phpmyadmin/';
/**
 * MySQL hostname or IP address
 *
 * @global string $cfg['Servers'][$i]['host']
 */
$cfg['Servers'][$i]['host'] = 'ip address';
/**
 * Authentication method (valid choices:config, http, signon or cookie)
 *
 * @global string$cfg['Servers'][$i]['auth_type']
 */
$cfg['Servers'][$i]['auth_type']= 'cookie';
 
/**
 * MySQL user
 *
 * @global string $cfg['Servers'][$i]['user']
 */
$cfg['Servers'][$i]['user']= 'your user name';
 
/**
 * MySQL password (only needed with 'config'auth_type)
 *
 * @global string$cfg['Servers'][$i]['password']
 */
$cfg['Servers'][$i]['password']= 'your password';

 
注意:本人亲测:phpmyadmin不支持被配置为负载均衡。
3. 打开浏览器访问phpmyadmin,输入用户名和密码,进入到phpmyadmin控制台则表明PhpMyadmin配置成功。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx 集群 server