配置使用4台主机实现12台主机的集群

一、说明

因为电脑只能开四个虚拟机,于是使用4台虚拟机模拟12台主机。

如下图所示:

图解:

1、四台虚拟机均使用 CentOS 6.5 系统;

2、前端使用 keepalived给haproxy作高可用,keepalived为双主模型,前端两主机互为主从,两虚拟IP为:172.16.36.100、172.16.36.200;

3、前端haproxy给后端的web服务器作负载均衡;

4、前端DNS用于keepalived两虚拟IP作轮询解析域名,域名为:www.wubin.com;

5、事实上,web服务器分为三组,一组用于存储图片,第二组用于存储静态文本,第三组用于存储动态程序;此处只使用两台web服务器实现,使用基于端口的各虚拟主机模拟各web服务器;

6、于是web服务器1中有五个虚拟主机,webserver_img是用于存储图片的虚拟主机,webserver_txt是用于存储静态文件的虚拟主机,webserver_dynamic是用于存储动态程序的虚拟主机;web服务器2中有一个虚拟主机webserver_dynamic;各同类别的虚拟主机互相作负载均衡集群;

7、PHP使用fast-cgi方式安装,两web服务器各安装一个;

8、mysql数据作主从复制,使用mysql-proxy对mysql数据库作读写分离;

各软件版本:

1、keepalived:keepalived-1.2.7-3.el6.x86_64,yum 安装

2、haproxy: haproxy-1.4.24-2.el6.x86_64,yum安装

3、bind:bind-9.8.2-0.17.rc1.el6_4.6.x86_64,yum安装

4、nginx:nginx-1.4.7,编译安装

5、PHP:php-5.4.26,编译安装fast-cgi方式

6、mysql:mariadb-10.0.10-linux-x86_64,二进制版本

7、mysql-proxy:mysql-proxy-0.8.3-linux-glibc2.3-x86-64bit,编译安装

二、实现

1、操作前提条件:

1)、使用任务计划将各主机的时间同步至ntp服务器

# vim /etc/crontab

*/3 * * * * /usr/sbin/ntpdate 172.16.0.1 &> /dev/null

2)、各主机配置IP与主机名

前端一: ha1.wubin.com  172.16.36.10

前端二: ha2.wubin.com  172.16.36.20

web1服务器:web1.wubin.com  172.16.36.30

web2服务器:web2.wubin.com  172.16.36.40

3)、给各虚拟机安装软件

2、实现步骤

1)、配置web服务

配置web1服务器上的虚拟主机,配置/etc/nginx/nginx.conf文件,配置5台虚拟主机,对应图片中的名字为:webserver_img*2、webserver_txt*2、webserver_dynamic;


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
worker_connections  1024;
}

http {
include       mime.types;
default_type  application/octet-stream;

#log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘

log_format  main  ‘$http_x_forwarded_for - $remote_user [$time_local] "$request" ‘
#                  ‘$status $body_bytes_sent "$http_referer" ‘
#                  ‘"$http_user_agent" "$http_x_forwarded_for"‘;

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

gzip  on;

server {
listen       10010;
server_name  img1.wubin.com;

#charset koi8-r;

access_log  /var/web/log/img1.wubin.com.access.log  main;

location / {
root   /var/web/htdocs/img.wubin.com;
index  index.html index.htm;
}

error_page  404/404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500502503504/50x.html;
location =/50x.html {
root   /var/web/htdocs/img.wubin.com;
}
location =/404.html {
root   /var/web/htdocs/img.wubin.com;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

# deny access to .htaccess files, if Apache‘s document root
# concurs with nginx‘s one
#
#location ~ /\.ht {
#    deny  all;
#}
}

server {
listen       10020;
server_name  img2.wubin.com;

#charset koi8-r;

access_log  /var/web/log/img2.wubin.com.access.log  main;

location / {
root   /var/web/htdocs/img.wubin.com;
index  index.html index.htm;
}

error_page  404/404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500502503504/50x.html;
location =/50x.html {
root   /var/web/htdocs/img.wubin.com;
}
location =/404.html {
root   /var/web/htdocs/img.wubin.com;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

# deny access to .htaccess files, if Apache‘s document root
# concurs with nginx‘s one
#
#location ~ /\.ht {
#    deny  all;
#}
}

server {
listen       10030;
server_name  txt1.wubin.com;

access_log  /var/web/log/txt1.wubin.com.access.log  main;

location / {
root   /var/web/htdocs/txt.wubin.com;
index  index.html index.htm;
}

error_page  404/404.html;

error_page   500502503504/50x.html;
location =/50x.html {
root   /var/web/htdocs/txt.wubin.com;
}
location =/404.html {
root   /var/web/htdocs/txt.wubin.com;
}

}

server {
listen       10040;
server_name  txt2.wubin.com;

access_log  /var/web/log/txt2.wubin.com.access.log  main;

location / {
root   /var/web/htdocs/txt.wubin.com;
index  index.html index.htm;
}

error_page  404/404.html;

error_page   500502503504/50x.html;
location =/50x.html {
root   /var/web/htdocs/txt.wubin.com;
}
location =/404.html {
root   /var/web/htdocs/txt.wubin.com;
}

}

server {
listen       10050;
server_name  dynamic.wubin.com;

access_log  /var/web/log/dynamic.wubin.com.access.log  main;

location / {
root           /var/web/htdocs/dynamic.wubin.com;
index  index.php index.html index.htm;
}
location ~ \.php$ {
root           /var/web/htdocs/dynamic.wubin.com;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
include        fastcgi_params;
}

error_page  404/404.html;

error_page   500502503504/50x.html;
location =/50x.html {
root   /var/web/htdocs/dynamic.wubin.com;
}
location =/404.html {
root   /var/web/htdocs/dynamic.wubin.com;
}

}

}

配置web2服务器上的web服务,一台虚拟主机 webserver_dynamic;

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
worker_connections  1024;
}

http {
include       mime.types;
default_type  application/octet-stream;

#log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
log_format  main  ‘$http_x_forwarded_for - $remote_user [$time_local] "$request" ‘
#                  ‘$status $body_bytes_sent "$http_referer" ‘
#                  ‘"$http_user_agent" "$http_x_forwarded_for"‘;

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
listen       80;
server_name  localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
root   html;
index  index.html index.htm;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500502503504/50x.html;
location =/50x.html {
root   html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

# deny access to .htaccess files, if Apache‘s document root
# concurs with nginx‘s one
#
#location ~ /\.ht {
#    deny  all;
#}
}

server {
listen       10050;
server_name  dynamic.wubin.com;

access_log  /var/web/log/dynamic.wubin.com.access.log  main;

location / {
root           /var/web/htdocs/dynamic.wubin.com;
index  index.php index.html index.htm;
}
location ~ \.php$ {
root           /var/web/htdocs/dynamic.wubin.com;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
include        fastcgi_params;
}

error_page  404/404.html;

error_page   500502503504/50x.html;
location =/50x.html {
root   /var/web/htdocs/dynamic.wubin.com;
}
location =/404.html {
root   /var/web/htdocs/dynamic.wubin.com;
}

}

}

2)、配置PHP

使用基于 fast-cgi方式安装PHP,安装完成后,编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

而后重新载入nginx的配置文件:

# service nginx reload

3)、配置mysql主从;

主服务器配置,服务器IP为172.16.36.30:

# service mysqld stop
# vim /etc/my.cnf
  log-bin=/mydata/binlog/master-bin            //开启二进制日志
  binlog_format=mixed
  server-id       =1
# service mysqld start
# mysql
mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO ‘repluser‘@‘172.16.%.%‘ IDENTIFIED BY ‘replpass‘;
Query OK, 0 rows affected (0.00 sec)            //创建复制帐号

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

从服务器配置,服务器IP为172.16.36.40:

# service mysqld stop
# vim /etc/my.cnf
#log-bin=/mydata/binlog/master-bin         //关闭二进制日志
#binlog_format=mixed
server-id       =11//设定 server-id
relay-log       =/mydata/relaylogs/slave-bin  //开启中继日志
# mkdir /mydata/relaylogs
# chown -R mysql.mysql /mydata/relaylogs
# service mysqld start
# mysql
mysql> show global variables like ‘%relay%‘;
  relay_log             |/mydata/relaylogs/slave-bin

mysql> change master to master_host=‘172.16.36.30‘,master_user=‘repluser‘,master_password=‘replpass‘;
Query OK, 0 rows affected (0.07 sec)

mysql> show slave status\G   //查看从服务器状态
Slave_IO_Running: No        //表示IO线程没有启动
Slave_SQL_Running: No       //表示SQL线程没有启动

mysql> start slave;          //手动启动两个线程
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G

4)、配置mysql-proxy

编译安装完成mysql-proxy后,为服务脚本提供配置文件/etc/sysconfig/mysql-proxy,内容如下所示:

# Options for mysql-proxy 
ADMIN_USER="admin"
ADMIN_PASSWORD="admin"
ADMIN_ADDRESS=""
ADMIN_LUA_SCRIPT="/usr/local/mysql-proxy/share/doc/mysql-proxy/admin.lua"
PROXY_ADDRESS=""
PROXY_USER="mysql-proxy"
PROXY_OPTIONS="--daemon --log-level=info --log-use-syslog --plugins=proxy --plugins=admin --proxy-backend-addresses=172.16.36.30:3309 --proxy-read-only-backend-addresses=172.16.36.40:3306 --proxy-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua"

复制如下内容建立admin.lua文件,将其保存至/usr/local/mysql-proxy/share/doc/mysql-proxy/目录中。


--[[ $%BEGINLICENSE%$
Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; version 2 of the
License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; ifnot, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301  USA

$%ENDLICENSE%$ --]]

function set_error(errmsg) 
proxy.response = {
type = proxy.MYSQLD_PACKET_ERR,
errmsg = errmsg or"error"
}
end

function read_query(packet)
if packet:byte() ~= proxy.COM_QUERY then
set_error("[admin] we only handle text-based queries (COM_QUERY)")
return proxy.PROXY_SEND_RESULT
end

local query = packet:sub(2)

local rows = { }
local fields = { }

if query:lower() =="select * from backends"then
fields = { 
{ name ="backend_ndx", 
 type = proxy.MYSQL_TYPE_LONG },

{ name ="address",
 type = proxy.MYSQL_TYPE_STRING },
{ name ="state",
 type = proxy.MYSQL_TYPE_STRING },
{ name ="type",
 type = proxy.MYSQL_TYPE_STRING },
{ name ="uuid",
 type = proxy.MYSQL_TYPE_STRING },
{ name ="connected_clients", 
 type = proxy.MYSQL_TYPE_LONG },
}

for i =1, #proxy.global.backends do
local states = {
"unknown",
"up",
"down"
}
local types = {
"unknown",
"rw",
"ro"
}
local b = proxy.global.backends[i]

rows[#rows + 1] = {
i,
b.dst.name,          -- configured backend address
states[b.state +1], -- the C-id is pushed down starting at 0
types[b.type +1],   -- the C-id is pushed down starting at 0
b.uuid,              -- the MySQL Server‘s UUID if it is managed
b.connected_clients  -- currently connected clients
}
end
elseif query:lower() == "select * from help" then
fields = { 
{ name = "command", 
 type = proxy.MYSQL_TYPE_STRING },
{ name = "description", 
 type = proxy.MYSQL_TYPE_STRING },
}
rows[#rows + 1] = { "SELECT * FROM help", "shows this help" }
rows[#rows + 1] = { "SELECT * FROM backends", "lists the backends and their state" }
else
set_error("use ‘SELECT * FROM help‘ to see the supported commands")
return proxy.PROXY_SEND_RESULT
end

proxy.response = {
type = proxy.MYSQLD_PACKET_OK,
resultset = {
fields = fields,
rows = rows
}
}
return proxy.PROXY_SEND_RESULT
end

启动服务

[[email protected] ~]# service mysql-proxy start

查看mysql

[[email protected] ~]# mysql -uadmin -padmin -h172.16.36.30 --port=4041
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version:5.0.99-agent-admin

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

Type ‘help;‘or‘\h‘for help. Type ‘\c‘ to clear the current input statement.

MySQL [(none)]> select * from backends;
+-------------+-------------------+---------+------+------+-------------------+
| backend_ndx | address           | state   | type | uuid | connected_clients |
+-------------+-------------------+---------+------+------+-------------------+
|1|172.16.36.30:3309| up      | rw   | NULL |1|
|2|172.16.36.40:3306| unknown | ro   | NULL |0|
+-------------+-------------------+---------+------+------+-------------------+
2 rows in set (0.00 sec)

MySQL [(none)]>

5)、配置haproxy,给后端web服务器实现负载均衡,前端两主机配置文件一样,配置文件为/etc/haproxy/haproxy.cfg;

#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events.  This is done
#    by adding the ‘-r‘ option to the SYSLOGD_OPTIONS in
#    /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
#   file. A line like the following can be added to
#   /etc/sysconfig/syslog
#
#    local2.*                       /var/log/haproxy.log
#
log         127.0.0.1 local2

chroot      /var/lib/haproxy
pidfile     /var/run/haproxy.pid
maxconn     4000
user        haproxy
group       haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the ‘listen‘ and ‘backend‘ sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode                    http
log                     global
option                  httplog
option                  dontlognull
option http-server-close
option forwardfor       except 127.0.0.0/8
option                  redispatch
retries                 3
timeout http-request    10s
timeout queue           1m
timeout connect         10s
timeout client          1m
timeout server          1m
timeout http-keep-alive 10s
timeout check           10s
maxconn                 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  websrvs 
bind *:80
acl url_img       path_beg       -i /img /imgs /image /images
acl url_img       path_end       -i .jpg .gif .png .jpeg
acl host_img      hdr_beg(host)  -i img. images.
acl url_txt       path_beg       -i /css /javascript /js /stylesheets     
acl url_txt       path_end         -i .css .js .html .htm .shtml .xml
acl host_static     hdr_beg(host)  -i img. video. download. ftp. imgs. images. videos.
acl url_php         path_end     -i .php

use_backend imgserver          if url_img or host_img
use_backend txtserver          if url_txt
use_backend dynamicserver        if url_php
default_backend             dynamicserver

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend imgserver
balance     roundrobin
server      img1.wubin.com 172.16.36.30:10010 check
server      img2.wubin.com 172.16.36.30:10020 check

backend txtserver
balance     roundrobin
server      txt1.wubin.com 172.16.36.30:10030 check
server      txt2.wubin.com 172.16.36.30:10040 check

backend dynamicserver
cookie node insert nocache
balance     roundrobin
server      dynamic1.wubin.com 172.16.36.30:10050 check rise 2 fall 5 cookie node1
server      dynamic2.wubin.com 172.16.36.40:10050 check rise 2 fall 5 cookie node2

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
#backend dynamic
#    balance     roundrobin
#    server      node2.wubin.com 192.168.0.12:80 check maxconn 1000

listen statistics
bind *:8009
stats enable
stats auth admin:admin
stats uri /hastatus
stats admin if TRUE
stats hide-version

6)、配置keepalived,给前端haproxy作高可用集群,配置文件为/etc/keepalived/keepalived.conf;两VIP可以实现当haproxy服务下线时VIP自动转移至另一主机;

主机:172.16.36.10

! Configuration File for keepalived

global_defs {
  notification_email {
[email protected]
  }
  notification_email_from [email protected]
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id LVS_DEVEL
}

vrrp_script chk_haproxy {  
script "killall -0 haproxy"
interval 1
weight 2
}

vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 36
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 111136
}
virtual_ipaddress {
172.16.36.100
}
track_script {
chk_haproxy
}
}
vrrp_instance VI_2 {
state BACKUP
interface eth0
virtual_router_id 136
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111136
}
virtual_ipaddress {
172.16.36.200
}
track_script {
chk_haproxy
}
}

主机:172.16.36.20

! Configuration File for keepalived

global_defs {
  notification_email {
[email protected]
  }
  notification_email_from [email protected]
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id LVS_DEVEL
}

vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 1
weight 2
}

vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 36
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 111136
}
virtual_ipaddress {
172.16.36.100
}
track_script {
chk_haproxy
}
}
vrrp_instance VI_2 {
state MASTER
interface eth0
virtual_router_id 136
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111136
}
virtual_ipaddress {
172.16.36.200
}
track_script {
chk_haproxy
}
}

7)、配置DNS服务器,172.16.36.20;

配置文件/etc/named.conf:

//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/for example named configuration files.
//

options {
//    listen-on port 53 { 127.0.0.1; };
//    listen-on-v6 port 53 { ::1; };
directory     "/var/named";
dump-file     "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
//    allow-query     { localhost; };
//    recursion yes;

//    dnssec-enable yes;
//    dnssec-validation yes;
//    dnssec-lookaside auto;

/* Path to ISC DLV key */
//    bindkeys-file "/etc/named.iscdlv.key";

//    managed-keys-directory "/var/named/dynamic";
};

logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};

zone "." IN {
type hint;
file "named.ca";
};

include "/etc/named.rfc1912.zones";
#include "/etc/named.root.key";

配置文件/etc/named.rfc1912.zones

// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package 
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1: localhost TLDs and address zones
//and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt
// (c)2007 R W Franks
//
// See /usr/share/doc/bind*/sample/for example named configuration files.
//

zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};

zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};

zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};

zone "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};

zone "0.in-addr.arpa" IN {
type master;
file "named.empty";
allow-update { none; };
};

zone "wubin.com" IN {
type master;
file "wubin.com.zone";
};

配置文件/var/named/wubin.com.zone

$TTL 600
@    IN    SOA    dns.wubin.com dnsadmin.wubin.com (
2014030504
2H
4M
1D
2D )
@    IN    NS    dns.wubin.com.
@    IN    MX  10  mail.wubin.com.
dns    IN    A    172.16.36.20
mail    IN    A    172.16.36.20
www    IN    A    172.16.36.100
www    IN    A    172.16.36.200

测试:

[[email protected] ~]# dig -t A www.wubin.com @172.16.36.20

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6<<>>-t A www.wubin.com @172.16.36.20
;; global options:+cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id:7045
;; flags: qr aa rd ra; QUERY:1, ANSWER:2, AUTHORITY:1, ADDITIONAL:1

;; QUESTION SECTION:
;www.wubin.com.            IN    A

;; ANSWER SECTION:
www.wubin.com.        600    IN    A    172.16.36.200
www.wubin.com.        600    IN    A    172.16.36.100

;; AUTHORITY SECTION:
wubin.com.        600    IN    NS    dns.wubin.com.

;; ADDITIONAL SECTION:
dns.wubin.com.        600    IN    A    172.16.36.20

;; Query time:2 msec
;; SERVER:172.16.36.20#53(172.16.36.20)
;; WHEN: Sun May  422:57:462014
;; MSG SIZE  rcvd:97

配置完成,打开一个windows xp系统,将DNS服务器的IP地址设成刚才配置的DNS服务器的IP地址;

打开浏览器安装程序,测试;

三、此集群不足之处

虽然各同类虚拟主机使用的是一个相同的目录实现的文件同步,但动静分离时,明显web文件需在所有虚拟主机目录存放一份;

时间: 2024-10-13 10:36:22

配置使用4台主机实现12台主机的集群的相关文章

Linux高可用集群方案之配置heartbeat v2基于haresources配置文件的httpd高可用集群

本章主要配置heartbeat v2基于haresources配置文件的httpd高可用集群.  ll  本文导航    · 前期准备   · 安装heartbeat v2   · node1.node2主机安装httpd   · shared-nfs主机安装nfs   · 配置httpd高可用集群   · 客户端访问测试  ll  要求  完全掌握heartbeat v2基于haresources配置文件的httpd高可用服务.   前期准备  1.heartbeat服务主机规划 主机 接口

Docker1.12.1之swarm集群搭建与使用

1:前言 在docker1.12版本之前,众所周知dokcer本身只能单机上运行,而集群则要依赖mesos.kubernetes.swarm等集群管理方案.其中swarm是docker公司自己的容器集群管理工具,在当时的热度还是低于前两者.docker1.12.0版本发布中,Docker公司出于战略眼光,将swarm集成到docker-engine中,使docker内置了集群解决方案.于是swarm这个"亲儿子"的江湖地位迅速提升,在docker集群方案中与mesos,k8s形成三足鼎

Oracle RAC中的一台机器重启以后无法接入集群

前天有个同事说有套AIX RAC的其中一台服务器重启了操作系统以后,集群资源CSSD的资源一直都在START的状态,检查日志输出有如下内容: [    CSSD][1286]clssnmvDiskVerify: Successful discovery of 0 disks [    CSSD][1286]clssnmCompleteInitVFDiscovery: Completing initial voting file discovery [    CSSD][1286]clssnmvF

配置网络、集群内主机名设定、ssh登入、bash命令、通配符

作业一:临时配置网络(ip,网关,dns)+永久配置 设置临时网络配置: 配置IP ifcongfig ens33 192.168.16.177/24 (ifconfig 网卡 ip地址    /24代表它子网掩码) 配置网关 route add default gw 192.168.16.177 netmask 255.255.255.0  添加默认网关 配置 DNS vim /etc/resolv.conf            (DNS配置文件位置) 设置永久网络配置: cd /etc/s

Hadoop集群(第5期)_Hadoop安装配置

1.集群部署介绍 1.1 Hadoop简介 Hadoop是Apache软件基金会旗下的一个开源分布式计算平台.以Hadoop分布式文件系统(HDFS,Hadoop Distributed Filesystem)和MapReduce(Google MapReduce的开源实现)为核心的Hadoop为用户提供了系统底层细节透明的分布式基础架构. 对于Hadoop的集群来讲,可以分成两大类角色:Master和Salve.一个HDFS集群是由一个NameNode和若干个DataNode组成的.其中Nam

Hadoop集群_Hadoop安装配置

1.集群部署介绍 1.1 Hadoop简介 Hadoop是Apache软件基金会旗下的一个开源分布式计算平台.以Hadoop分布式文件系统(HDFS,Hadoop Distributed Filesystem)和MapReduce(Google MapReduce的开源实现)为核心的Hadoop为用户提供了系统底层细节透明的分布式基础架构. 对于Hadoop的集群来讲,可以分成两大类角色:Master和Salve.一个HDFS集群是由一个NameNode和若干个DataNode组成的.其中Nam

Rabbitmq 相关介绍之单机集群配置

一.说明: 说到集群,大家应该都不陌生,为了提高性能需要配置集群,而在有的时候,我们需要在测试环境先测试然后灰度上线,所以这里介绍在一台服务器上配置rabbitmq集群 二.rabbitmq集群模式 1.普通模式:rabbitmq默认的集群模式 RabbitMQ集群中节点包括内存节点.磁盘节点.内存节点就是将所有数据放在内存,磁盘节点将数据放在磁盘上.如果在投递消息时,打开了消息的持久化,那么即使是内存节点,数据还是安全的放在磁盘.那么内存节点的性能只能体现在资源管理上,比如增加或删除队列(qu

Hadoop多节点集群安装配置

目录: 1.集群部署介绍 1.1 Hadoop简介 1.2 环境说明 1.3 环境配置 1.4 所需软件 2.SSH无密码验证配置 2.1 SSH基本原理和用法 2.2 配置Master无密码登录所有Salve 3.Java环境安装 3.1 安装JDK 3.2 配置环境变量 3.3 验证安装成功 3.4 安装剩余机器 4.Hadoop集群安装 4.1 安装hadoop 4.2 配置hadoop 4.3 启动及验证 4.4 网页查看集群 5.常见问题FAQ   5.1 关于 Warning: $H

Haproxy做LB负载均衡集群的搭建和配置,可以通过web页面监控web服务器的运行状态

HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持或七层处理. 实验(一) 实验目的:使用Haproxy做负载均衡集群(七层) 实验环境准备: 客户端  IP地址:1.1.1.1 主机名waiwang web1   IP地址:1.1.1.10 主机名:localhost web2   IP地址:1.1.1.20 主机名:localhost 配置HA