Sophie

Sophie

distrib > Mandriva > 2010.1 > i586 > by-pkgid > 563affe035311228f138962d4d47d4fd > files > 29

pdns-3.0.1-0.1mdv2010.2.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Configure database connectivity</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PowerDNS manual"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="Running PDNS on Microsoft Windows"
HREF="running-on-windows.html"><LINK
REL="NEXT"
TITLE="Dynamic resolution using the PipeBackend"
HREF="pipebackend-dynamic-resolution.html"></HEAD
><BODY
CLASS="CHAPTER"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PowerDNS manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="running-on-windows.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="pipebackend-dynamic-resolution.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="CONFIGURING-DB-CONNECTION"
></A
>Chapter 4. Configure database connectivity</H1
><P
>      This chapter shows you how to configure the Generic MySQL backend, which we like a lot. But feel free to use any of the myriad
      other backends.
      This backend is called 'gmysql', and needs to be configured
      in <TT
CLASS="FILENAME"
>pdns.conf</TT
>. Add the following lines, adjusted for your local setup:
      
      <PRE
CLASS="SCREEN"
>	launch=gmysql
	gmysql-host=127.0.0.1
	gmysql-user=root
	gmysql-dbname=pdnstest
      </PRE
>
      
      Remove any earlier <B
CLASS="COMMAND"
>launch</B
> statements. Also remove the <B
CLASS="COMMAND"
>bind-example-zones</B
>
      statement as the <B
CLASS="COMMAND"
>bind</B
> module is no longer launched.
    </P
><P
>      <DIV
CLASS="WARNING"
><P
></P
><TABLE
CLASS="WARNING"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/warning.gif"
HSPACE="5"
ALT="Warning"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>	  Make sure that you can actually resolve the hostname of your database without accessing the database! It is advised to supply
	  an IP address here to prevent chicken/egg problems!
	</P
></TD
></TR
></TABLE
></DIV
>
      <DIV
CLASS="WARNING"
><P
></P
><TABLE
CLASS="WARNING"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/warning.gif"
HSPACE="5"
ALT="Warning"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>	  Be very very sure that you configure the *g*mysql backend and not the mysql backend. See
	  <A
HREF="generic-mypgsql-backends.html"
>Section A.5</A
>. If you use the 'mysql' backend things will only appear to work.
	</P
></TD
></TR
></TABLE
></DIV
>
    </P
><P
>      Now start PDNS using the monitor command:
      <PRE
CLASS="SCREEN"
>	# /etc/init.d/pdns monitor
	(...)
	15:31:30 About to create 3 backend threads
	15:31:30 [gMySQLbackend] Failed to connect to database: Error: Unknown database 'pdnstest'
	15:31:30 [gMySQLbackend] Failed to connect to database: Error: Unknown database 'pdnstest'
	15:31:30 [gMySQLbackend] Failed to connect to database: Error: Unknown database 'pdnstest'
      </PRE
>
      
      This is as to be expected - we did not yet add anything to MySQL for PDNS to read from. At this point you may also see
      other errors which indicate that PDNS either could not find your MySQL server or was unable to connect to it. Fix these 
      before proceeding.
    </P
><P
>      General MySQL knowledge is assumed in this chapter, please do not interpret these commands as DBA advice!
    </P
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="CONFIGURING-MYSQL"
>4.1. Configuring MySQL</A
></H1
><P
>	Connect to MySQL as a user with sufficient privileges and issue the following commands:
	<PRE
CLASS="SCREEN"
>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)
)type=InnoDB;

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)
)type=InnoDB;

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
);

GRANT SELECT ON supermasters TO pdns;
GRANT ALL ON domains TO pdns;
GRANT ALL ON records TO pdns;
	</PRE
>
	
	Now we have a database and an empty table. PDNS should now be able to launch in monitor mode and display no errors:

	<PRE
CLASS="SCREEN"
>	  # /etc/init.d/pdns monitor
	  (...)
	  15:31:30 PowerDNS 1.99.0 (Mar 12 2002, 15:00:28) starting up
	  15:31:30 About to create 3 backend threads
	  15:39:55 [gMySQLbackend] MySQL connection succeeded
	  15:39:55 [gMySQLbackend] MySQL connection succeeded
	  15:39:55 [gMySQLbackend] MySQL connection succeeded
	</PRE
>
	
	A sample query sent to the database should now return quickly without data:
	<PRE
CLASS="SCREEN"
>	  $ host www.test.com 127.0.0.1
	  www.test.com A record currently not present at localhost
	</PRE
>

	And indeed, the control console now shows:
	<PRE
CLASS="SCREEN"
>	  Mar 12 15:41:12 We're not authoritative for 'www.test.com', sending unauth normal response
	</PRE
>

	Now we need to add some records to our database:
	<PRE
CLASS="SCREEN"
>	  # mysql pdnstest
	  mysql&#62; INSERT INTO domains (name, type) values ('test.com', 'NATIVE');
	  INSERT INTO records (domain_id, name, content, type,ttl,prio) 
	  VALUES (1,'test.com','localhost ahu@ds9a.nl 1','SOA',86400,NULL);
	  INSERT INTO records (domain_id, name, content, type,ttl,prio)
	  VALUES (1,'test.com','dns-us1.powerdns.net','NS',86400,NULL);
	  INSERT INTO records (domain_id, name, content, type,ttl,prio)
	  VALUES (1,'test.com','dns-eu1.powerdns.net','NS',86400,NULL);
	  INSERT INTO records (domain_id, name, content, type,ttl,prio)
	  VALUES (1,'www.test.com','199.198.197.196','A',120,NULL);
	  INSERT INTO records (domain_id, name, content, type,ttl,prio)
	  VALUES (1,'mail.test.com','195.194.193.192','A',120,NULL);
	  INSERT INTO records (domain_id, name, content, type,ttl,prio)
	  VALUES (1,'localhost.test.com','127.0.0.1','A',120,NULL);
	  INSERT INTO records (domain_id, name, content, type,ttl,prio)
	  VALUES (1,'test.com','mail.test.com','MX',120,25);
	</PRE
>
	
	If we now requery our database, <B
CLASS="COMMAND"
>www.test.com</B
> should be present:
	<PRE
CLASS="SCREEN"
>	  $ host www.test.com 127.0.0.1
	  www.test.com        	A	199.198.197.196
	  
	  $ host -v -t mx test.com 127.0.0.1
	  Address: 127.0.0.1
	  Aliases: localhost

	  Query about test.com for record types MX
	  Trying test.com ...
	  Query done, 1 answer, authoritative status: no error
	  test.com            	120	IN	MX	25 mail.test.com
	  Additional information:
	  mail.test.com       	120	IN	A	195.194.193.192
	</PRE
>
	
	To confirm what happened, issue the command <B
CLASS="COMMAND"
>SHOW *</B
> to the control console:
	<PRE
CLASS="SCREEN"
>	  % show *
	  corrupt-packets=0,latency=0,packetcache-hit=2,packetcache-miss=5,packetcache-size=0,
	  qsize-a=0,qsize-q=0,servfail-packets=0,tcp-answers=0,tcp-queries=0,
	  timedout-packets=0,udp-answers=7,udp-queries=7,
	  % 
	</PRE
>
	The actual numbers will vary somewhat. Now enter <B
CLASS="COMMAND"
>QUIT</B
> and start PDNS as a regular daemon, and check launch status:

	<PRE
CLASS="SCREEN"
>	  # /etc/init.d/pdns start 
	  pdns: started
	  # /etc/init.d/pdns status
	  pdns: 8239: Child running
	  # /etc/init.d/pdns dump  
	  pdns: corrupt-packets=0,latency=0,packetcache-hit=0,packetcache-miss=0,
	  packetcache-size=0,qsize-a=0,qsize-q=0,servfail-packets=0,tcp-answers=0,
	  tcp-queries=0,timedout-packets=0,udp-answers=0,udp-queries=0,
	</PRE
>
	
	You now have a working database driven nameserver! To convert other zones already present, use the <B
CLASS="COMMAND"
>zone2sql</B
> 
        described in Appendix A.
      </P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN2846"
>4.1.1. Common problems</A
></H2
><P
>	  Most problems involve PDNS not being able to connect to the database. 
	<P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><SPAN
CLASS="ERRORTYPE"
> Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)</SPAN
></DT
><DD
><P
>		  Your MySQL installation is probably defaulting to another location for its socket. Can be resolved
		  by figuring out this location (often <TT
CLASS="FILENAME"
>/var/run/mysqld.sock</TT
>), and specifying it 
		  in the configuration file with the <B
CLASS="COMMAND"
>gmysql-socket</B
> parameter.
		</P
><P
>		  Another solution is to not connect to the socket, but to 127.0.0.1, which can be achieved by specifying
		  <B
CLASS="COMMAND"
>gmysql-host=127.0.0.1</B
>.
		</P
></DD
><DT
><SPAN
CLASS="ERRORTYPE"
>Host 'x.y.z.w' is not allowed to connect to this MySQL server</SPAN
></DT
><DD
><P
>		  These errors are generic MySQL errors. Solve them by trying to connect to your MySQL database with the MySQL 
		  console utility <B
CLASS="COMMAND"
>mysql</B
> with the parameters specified to PDNS. Consult the MySQL documentation.
		</P
></DD
></DL
></DIV
>
	</P
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="running-on-windows.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="pipebackend-dynamic-resolution.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Running PDNS on Microsoft Windows</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Dynamic resolution using the PipeBackend</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>