linux 下使用mydns

环境:

  Centos 5.4

  使用软件:

  wget http://mydns.bboy.net/download/mydns-1.1.0.tar.gz

  wget http://soft.vpser.net/datebase/mysql/mysql-5.1.54.tar.gz

  安装前准备:

  yum -y install gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip

  一、安装mysql数据库

  tar zxvf mysql-5.1.54.tar.gz

  cd mysql-5.1.54

  ./configure  --prefix=/usr/local/mysql --with-extra-charsets=all --enable-thread-safe-client --enable-assembler --with-charset=utf8 --with-extra-charsets=all --with-

  big-tables --with-readline --with-ssl --with-embedded-server --enable-thread-safe-client --enable-local-infileser

  make

  make install

  groupadd mysql

  useradd -s /sbin/nologin  -M -g mysql mysql

  cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf

  sed -i 's/skip-locking/skip-external-locking/g' /etc/my.cnf

  /usr/local/mysql/bin/mysql_install_db --user=mysql

  chown -R mysql /usr/local/mysql/var

  chgrp -R mysql /usr/local/mysql/.

  cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql

  chmod 755 /etc/init.d/mysql

  vim /etc/ld.so.conf.d/mysql.conf添加如下:

  /usr/local/mysql/lib/mysql

  /usr/local/lib

  ldconfig

  ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql

  ln -s /usr/local/mysql/include/mysql /usr/include/mysql

  /etc/init.d/mysql start

  ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

  ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump

  ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk

  /usr/local/mysql/bin/mysqladmin -u root password  123456  设置密码

  二、安装mydns:

  tar zxvf mydns-1.1.0.tar.gz

  ./configure  --prefix=/usr/local/mydns --with-mysql-lib=/usr/local/mysql/lib/mysql/ --with-mysql-include=/usr/local/mysql/include/mysql/

  make && make install

  /usr/local/mysql/bin/mysqladmin  -uroot -p create mydns  创建dns数据库

  mysql>insert into mysql.user (host,user,password) values ('localhost','mydns',password('mydns'));     //建立用户mydns,密码mydns

  mysq>flush privileges;    //重载MySQL授权表

  mysql>grant all on mydns.* to mydns@'localhost' identified by 'mydns'; 把数据mydns授权于用户mydns

  生成主配置文件:

  /usr/local/mydns/sbin/mydns  --dump-config > /etc/mydns.conf

  三、配置mydns:

  修改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 = 172.16.6.200                   # 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

  四、测试添加相应记录:

  use mydns;

  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;   创建soa表

  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;  创建rr表

  添加数据:

  insert into soa values (1,'crazylinux.cn.','ns.crazylinux.cn.','root.crazylinux.cn.',2011060114,1800,7200,604800,360,1800);

  insert into rr values (1,1,'www','A','172.16.6.202',0,360);添加条A记录www.crazylinux.cn解析到172.16.6.202

  insert into rr values (2,1,'so','CNAME','so.crazylinux.cn.test.com.',0,360);添加条cname记录so.crazylinux.cn解析到so.crazylinux.cn.test.com.

  mysql> select * from rr;

  +----+------+------+-------+----------------------------+-----+-----+

  | id | zone | name | type  | data                       | aux | ttl |

  +----+------+------+-------+----------------------------+-----+-----+

  |  1 |    1 | www  | A     | 172.16.6.202               |   0 | 360 |

  |  2 |    1 | so   | CNAME | so.crazylinux.cn.test.com. |   0 | 360 |

  +----+------+------+-------+----------------------------+-----+-----+

  2 rows in set (0.00 sec)

  测试:

  [root@localhost ~]# dig  @172.16.6.200 www.crazylinux.cn

  ; <<>> DiG 9.3.4-P1 <<>> @172.16.6.200 www.crazylinux.cn

  ; (1 server found)<

linux 下使用powerdns

安装MySQL

yum -y install mysql mysql-server  设置mysql开机自启并启动mysql  

chkconfig --levels 235 mysqld on  /etc/init.d/mysqld start  修改mysql root密码:


mysqladmin -u root password yourrootsqlpassword  安装Powerdns

yum -y install pdns pdns-backend-mysql  连接mysql:  

mysql -u root -p  创建powerdns数据库:  

CREATE DATABASE powerdns;  

为Powerdns创建powerdns数据库用户:  

GRANT ALL ON powerdns.* TO

'power_admin'@'localhost'

IDENTIFIED

BY

'power_admin_password';  

FLUSH PRIVILEGES;  

请替换power_admin_password成自己的密码。 现在创建数据表:  

USE powerdns;  

CREATE TABLE domains (  

id INT auto_increment,  

name VARCHAR(255) NOT NULL,  

master VARCHAR(128) DEFAULT NULL,  last_check INT DEFAULT NULL,  type VARCHAR(6) NOT NULL,  notified_serial INT DEFAULT NULL,  account VARCHAR(40) DEFAULT NULL,  primary key (id)  );  

CREATE UNIQUE INDEX name_index ON domains(name);  CREATE TABLE records (  id INT auto_increment,  

domain_id INT DEFAULT NULL,  

name VARCHAR(255) DEFAULT NULL,  type VARCHAR(6) DEFAULT NULL,  

content VARCHAR(255) DEFAULT NULL,  ttl INT DEFAULT NULL,  







prio INT DEFAULT NULL,  

change_date INT DEFAULT NULL,  primary key(id)  );  

CREATE INDEX rec_name_index ON records(name);  CREATE INDEX nametype_index ON records(name,type);  CREATE INDEX domain_id ON records(domain_id);  CREATE TABLE supermasters (  ip VARCHAR(25) NOT NULL,  

nameserver VARCHAR(255) NOT NULL,  account VARCHAR(40) DEFAULT NULL  );  

最后退出mysql shell:  

quit;  

现在配置Powerdns以使用mysql后端:  

vi /etc/pdns/pdns.conf  增加如下内容到pdns.conf  [...]  

#################################  

# launch        Which backends to launch and order to query them in  #  

# launch=  

launch=gmysql  

gmysql-host=127.0.0.1  

gmysql-user=power_admin  

gmysql-password=power_admin_password  gmysql-dbname=powerdns  

[...]  

设置Powerdns自启动并立即启动Powerdns。  

chkconfig --levels 235 pdns on  

/etc/init.d/pdns start  

现在Powerdns已经正常运行,下面我们为Powerdns安装Poweradmin实现web管理。  

安装Poweradmin

Poweradmin运行在PHP环境中,我们现在配置web环境。


yum -y install httpd php php-devel php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mhash gettext  设置apache自启动,并启动APACHE。  







chkconfig --levels 235 httpd on  

/etc/init.d/httpd start  

Poweradmin还需要安装两个PEAR软件包。  

yum install php-pear-DB php-pear-MDB2-Driver-mysql  

现在Poweradmin所需的环境已经配置完成,我们将把Poweradmin安装在目录/var/www/html,这是APACHE默认的文档根目录。

到https://www.poweradmin.org/trac/wiki/GettingPoweradmin找到最新的版本下载:  cd /tmp  

wget https://www.poweradmin.org/download/poweradmin-2.1.5.tgz  然后安装在/var/www/html/poweradmin目录。  

tar xvfz poweradmin-2.1.5.tgz  

mv poweradmin-2.1.5 /var/www/html/poweradmin  touch /var/www/html/poweradmin/inc/config.inc.php  

chown -R APACHE:APACHE /var/www/html/poweradmin/  

现在打开浏览器运行安装程序(如:http://www.centos.bz/poweradmin/install或http://192.168.0.100/poweradmin/install)。 1、选择语言为英文,并点击Go to step 2  

2、点击“Go to step 3”到安装的第三步,填入数据库详细信息。输入root用户和密码,和输入Poweradmin的admin用户的密码。  

3、点击下一步,填入在安装powerdns那一步所创建的power_admin mysql用户的信息,并且填入域名服务器地址:  

4、下一步是需要执行mysql语句,我们不需要执行了,因为前面我们已经执行过了,直接点击下一步即可。  

5、继续点击下一步。  

6、现在poweradmin安装完成。  

7、为了安全,需要删除安装目录。  

rm -fr /var/www/html/poweradmin/install/  

现在你可以进入http://www.centos.bz/poweradmin或者http://192.168.0.100/poweradmin页面,输入用户admin和执行安装程序时设置的密码进入管理界面。