配置使用4臺主機實現12臺主機的集羣

1、說明


由於電腦只能開四個虛擬機,因而使用4臺虛擬機模擬12臺主機。


以下圖所示:

wKiom1NmXRDQrlHiAAK-ozoFuEM141.jpgspacer.gif


圖解:
一、四臺虛擬機均使用 CentOS 6.5 系統;
二、前端使用 keepalived給haproxy做高可用,keepalived爲雙主模型,前端兩主機互爲主從,兩虛擬IP爲:172.16.36.100、172.16.36.200;
三、前端haproxy給後端的web服務器做負載均衡;
四、前端DNS用於keepalived兩虛擬IP做輪詢解析域名,域名爲:www.wubin.com;
五、事實上,web服務器分爲三組,一組用於存儲圖片,第二組用於存儲靜態文本,第三組用於存儲動態程序;此處只使用兩臺web服務器實現,使用基於端口的各虛擬主機模擬各web服務器;
六、因而web服務器1中有五個虛擬主機,webserver_img是用於存儲圖片的虛擬主機,webserver_txt是用於存儲靜態文件的虛擬主機,webserver_dynamic是用於存儲動態程序的虛擬主機;web服務器2中有一個虛擬主機webserver_dynamic;各同類別的虛擬主機互相做負載均衡集羣;
七、PHP使用fast-cgi方式安裝,兩web服務器各安裝一個;
八、mysql數據做主從複製,使用mysql-proxy對mysql數據庫做讀寫分離;


各軟件版本:
一、keepalived:keepalived-1.2.7-3.el6.x86_64,yum 安裝
二、haproxy: haproxy-1.4.24-2.el6.x86_64,yum安裝
三、bind:bind-9.8.2-0.17.rc1.el6_4.6.x86_64,yum安裝
四、nginx:nginx-1.4.7,編譯安裝
五、PHP:php-5.4.26,編譯安裝fast-cgi方式
六、mysql:mariadb-10.0.10-linux-x86_64,二進制版本
七、mysql-proxy:mysql-proxy-0.8.3-linux-glibc2.3-x86-64bit,編譯安裝



2、實現


一、操做前提條件:

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.40javascript



3)、給各虛擬機安裝軟件


二、實現步驟


1)、配置web服務


配置web1服務器上的虛擬主機, 配置/etc/nginx/nginx.conf文件,配置5臺虛擬主機,對應圖片中的名字爲: webserver_img*二、 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


啓動服務
[root@web1 ~]# service mysql-proxy start


查看mysql
[root@web1 ~]# 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 /p_w_picpath /p_w_picpaths
acl url_img       path_end       -i .jpg .gif .png .jpeg
acl host_img      hdr_beg(host)  -i img. p_w_picpaths.
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. p_w_picpaths. 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 p_w_picpaths, 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 {
root@localhost
  }
  notification_email_from admin@wubin.com
  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 {
root@localhost
  }
  notification_email_from admin@wubin.com
  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


測試:
[root@ha2 ~]# 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地址;
spacer.gif wKioL1NmXQKiO6TjAAT06ZgESoU530.jpg


打開瀏覽器安裝程序,測試;
spacer.gif wKioL1NmXRbCZY9OAAUkvuP2b_U995.jpg


3、此集羣不足之處


雖然各同類虛擬主機使用的是一個相同的目錄實現的文件同步,但動靜分離時,明顯web文件需在全部虛擬主機目錄存放一份;
相關文章
相關標籤/搜索