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

Nginx+Apache+PHP+MySQL搭建集群服务器过程详解


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

  • 集群架构图大致如下:

Nginx搭建集群服务器过程详解_第1张图片       

    

一、软件下载

序号

软件名称

软件版本

下载地址

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版本选择安装对应版本的VCphp5.6对应的是VC11,根据VC11应用程序安装指引安装VC11

 

三、PHP安装与配置

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

 

四、Apache安装与配置

  1. 解压Apache安装包到C:\Program Files\Apache24;
  2. 修改C:\Program Files\Apache24\conf\httpd.conf;      

                     a. Define SRVRROOT改为Apache的安装路径:

Define SRVROOT "C:/Program Files/Apache24"

  1. Listen 80改为Listen 8080;
  2. 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"

  1. 保存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”页面表示安装成功;

Nginx搭建集群服务器过程详解_第2张图片

 

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

 phpinfo(); ?>


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

Nginx搭建集群服务器过程详解_第3张图片

 

五、Nginx安装与配置

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

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

 

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

Nginx搭建集群服务器过程详解_第4张图片

 

  1. 打开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;

    }

 

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

nginx

NginxService

HighPerformance Nginx Service

C:\ProgramFiles\nginx-1.8.1\nginx.exe

C:\ProgramFiles\nginx-1.8.1

roll

-pC:\Program Files\nginx-1.8.1

-pC:\Program Files\nginx-1.8.1 -s stop

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

 

六、 Mysql安装与配置

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

 

七、 PhpMyAdmin安装

  1. 将安装包解压或上传到服务器的Web文件目录,即G:\Program Files\Apache24\htdocs中;
  2. 修改配置文件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配置成功。



你可能感兴趣的:(Technique,Related)