案例:
搭建mydns
环境:redhat 5.4
软件:mysql mysql-server php mydns(http://mydns.bboy.net/)
安装步骤:
1、准备工作(配置本地yum)
2、安装mysql
3、安装http
4、安装php
5、安装mydns
6、配置
a、数据库配置
创建数据库
mysqladmin -u root -p create mydns
//建立用户mydns,密码mydns
mysql>insert into mysql.user (host,user,password) values ('localhost','mydns',password('mydns'));
//重载MySQL授权表
mysq>flush privileges;
把数据mydns授权于用户mydns
mysql>grant all on mydns.* to mydns@'localhost' identified by 'mydns';
创建soa表
CREATE TABLE soa (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
origin CHAR(255) NOT NULL,
ns CHAR(255) NOT NULL,
mbox CHAR(255) NOT NULL,
serial INT UNSIGNED NOT NULL DEFAULT '20110601',
refresh INT UNSIGNED NOT NULL DEFAULT '1800',
retry INT UNSIGNED NOT NULL DEFAULT '7200',
expire INT UNSIGNED NOT NULL DEFAULT '604800',
minimum INT UNSIGNED NOT NULL DEFAULT '300',
ttl INT UNSIGNED NOT NULL DEFAULT '1800'
) TYPE=MyISAM;
创建rr表
CREATE TABLE rr (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
zone INT UNSIGNED NOT NULL,
name CHAR(64) NOT NULL,
type ENUM('A','AAAA','CNAME','HINFO','MX','NS','PTR','RP','SRV','TXT') NOT NULL,
data CHAR(128) NOT NULL,
aux INT UNSIGNED NOT NULL,
ttl INT UNSIGNED NOT NULL DEFAULT '36000'
) TYPE=MyISAM; l
添加区域
insert into soa values (1,'crazylinux.cn.','ns.crazylinux.cn.','root.crazylinux.cn.',2011060114,1800,7200,604800,360,1800);
添加条A记录www.crazylinux.cn解析到172.16.6.202
insert into rr values (1,1,'www','A','172.16.6.202',0,360);
添加条cname记录so.crazylinux.cn解析到so.crazylinux.cn.test.com.
insert into rr values (2,1,'so','CNAME','so.crazylinux.cn.test.com.',0,360);
b、配置mydns
生成主配置文件:
/usr/local/mydns/sbin/mydns --dump-config > /etc/mydns.conf
修改mydns.conf如下:
# DATABASE INFORMATION
db-host = localhost # SQL server hostname
db-user = mydns # SQL server username
db-password = mydns # SQL server password
database = mydns # MyDNS database name
# GENERAL OPTIONS
user = mydns # Run with the permissions of this user
group = mydns # Run with the permissions of this group
listen = 192.168.102.188 # Listen on these addresses ('*' for all)
no-listen = # Do not listen on these addresses
# CACHE OPTIONS
zone-cache-size = 1024 # Maximum number of elements stored in the zone cache
zone-cache-expire = 60 # Number of seconds after which cached zones expires
reply-cache-size = 1024 # Maximum number of elements stored in the reply cache
reply-cache-expire = 30 # Number of seconds after which cached replies expire
# ESOTERICA
log = LOG_DAEMON # Facility to use for program output (LOG_*/stdout/stderr)
pidfile = /var/run/mydns.pid # Path to PID file
timeout = 120 # Number of seconds after which queries time out
multicpu = 1 # Number of CPUs installed on your system
recursive = 8.8.8.8 # Location of recursive resolver把解析不了的转发到8.8.8
recursive-timeout = # Number of seconds before first retry
recursive-retries = # Number of retries before abandoning recursion
recursive-algorithm = # Recursion retry algorithm one of: linear, exponential, progressive
allow-axfr = yes # Should AXFR be enabled?
allow-tcp = yes # Should TCP be enabled?
allow-update = no # Should DNS UPDATE be enabled?
ignore-minimum = no # Ignore minimum TTL for zone?
soa-table = soa # Name of table containing SOA records
rr-table = rr # Name of table containing RR data
soa-where = # Extra WHERE clause for SOA queries
rr-where = # Extra WHERE clause for RR queries
/usr/local/mydns/sbin/mydns --background 放入后台运行mydns
/usr/local/mydns/sbin/mydns reload 重新加载配置文件
/usr/local/mydns/sbin/mydns restart 重新启动mydns
c、配置web页面
修改这些内容
dbhost = "localhost";
$dbuser = "mydns";
$dbpass = "mydns";
$dbname = "mydns";
7、测试
在地址栏输入
http://mydns服务器ip/admin.php
点一下浏览,可以看到我们在数据库中添加的域
点击,可以看得此域的详细信息
新建一个
新建一个域,点击new
填入详细信息
在另一台主机上将dns指向mydns服务器