Ubuntu14.04安裝PowerDNS踩坑實錄


公司要使用PowerDNS,作為內網域名解析的工具。讓我和另一組的同事學一下如何配置及調優。所以先找了兩台服務器試着安裝一下。這一裝就是一個禮拜,經歷了大大小小的坑,記下來以后可能需要參考。安裝過程如下:
 
1、安裝mysql:
盡量使用源碼安裝,不要使用apt-get,安裝的版本不完全,缺少相關的庫,會導致后面缺少mysql.h、mysql_config等等文件。我手里這台機器已經裝好了mysql,這步就直接略過了。
 
2、安裝php:
在php官網 http://www.php.net/ 中下載的5.6.16包,解壓后配置如下:
sudo ./configure --prefix=/usr/local/php-5.6.16 --enable-exif --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-mbstring --with-mysql=/usr --with-mysql-sock=/tmp/mysql.socket  --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --enable-zip --with-pcre-dir --enable-maintainer-zts --enable-zend-multibyte --with-config-file-path=/usr/local/php-5.6.16/etc/ --with-mysqli=/usr/bin/mysql_config --with-gettext --with-mcrypt
配置問題:
(1)configure: error: jpeglib.h not found
缺少libjpeg庫。到  http://www.ijg.org/ 去下載。tar解壓,./configure配置,make編譯,make install安裝。后面三步都需要sudo。記得要下最新版的庫安裝。
(2)configure: error: png.h not found.
缺少 libpng包。
sudo apt-get -y install libpng12-dev
(3)configure: error: libjpeg.(a|so) not found.
裝好了libjpeg包,可能還會找不到libjpeg.so文件,這時候可以先
sudo find / -name libjpeg.so
然后增加一條鏈接到/usr/lib:
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/libjpeg.so
 (我的  libjpeg.so 在/usr/lib/x86_64-linux-gnu/ 目錄下,64位Ubuntu/Debian還有可能在/usr/lib64下)
jpeg換成png解決方法類似
(4)configure: error: mcrypt.h not found. Please reinstall libmcrypt.
缺少libmcrypt庫。到  http://mcrypt.hellug.gr/lib/ 下載。tar解壓,./configure配置,make編譯,make install安裝。后面三步都需要sudo。記得要下最新版的庫安裝。
也可以
sudo apt-get -y install libmcrypt-dev
(5)configure: error: Cannot find MySQL header files under /usr/bin/mysql.
Note that the MySQL client library is not bundled anymore!
--with-mysql=/usr:mysql.h沒找到頭文件,無法配置mysql.socket。find搜索一下,然后改一下--with-mysql后面的路徑。(centos下如果找不到的話,需要安裝一個mysql-devel)
(6)configure: error: Please reinstall the mysql distribution
--with-mysqli=/usr/bin/mysql_config:mysql_config沒找到配置文件,find搜索一下,更改路徑。
(7)configure: error: wrong mysql library version or lib not found. Check config.log for more information.
--enable-embedded-mysqli:原文中的這個編譯參數,跟--with-mysqli沖突,刪掉即可
(8)configure: error: Cannot find libz.
沒有找到zlib。到  http://www.zlib.net/ 去下載,tar解壓,./configure配置,make編譯,make install安裝。后面三步都需要sudo。記得要下最新版的庫安裝。
(9)configure: error: freetype-config not found.
缺少libfreetype6包。
sudo apt-get -y install libfreetype6 libfreetype6-dev

幸好后面的make和make install都沒有出問題。安裝好之后,需要復制一下配置文件:

sudo cp php.ini-production /usr/local/php-5.6.16/etc/php.ini
(沒錯,拷個文件也需要sudo)
 
3、安裝PowerDNS:
PowerDNS官網  https://www.powerdns.com/ 不要去github上下載源碼,因為——跟安裝文檔都對不上啊喂!在PowerDNS官網Older versions can be found on  downloads.powerdns.com/releases. (鏈接 https://downloads.powerdns.com/releases/) ,找了一個3.3.0(因為是.tar.gz包,並沒有那么花哨的后綴)。下載,解壓,然后配置參數
sudo ./configure --prefix=/etc/powerdns --enable-verbose-logging --enable-static-binaries --enable-pdns_server --enable-nedmalloc --with-mysql=/usr
配置問題:
(1)要裝lua。
在官網下載lua( http://www.lua.org/)裝的時候要裝readline庫。
sudo apt-get -y install libreadline-dev

或者

sudo apt-get -y install lua5.1

(powerdns要求lua版本要在5.1以上,但是我安裝5.2和5.3都遇到莫名其妙的問題)

裝完之后需要配置環境變量:
sudo vim /etc/profile
在結尾加上:
export LUA_CFLAGS="-I/usr/local/lua/include" export LUA_LIBS="-L/usr/local/lua/lib -llua -ldl"
我也不知道為啥這兩個就好使啊!明明lua並沒有裝在這里啊!!
(此方法不一定成功,裝lua的過程中我已經把機器搞的很亂了,不知道哪里蒙對的)
(2)configure: error: cannot find Boost headers version >= 1.35.0
缺少libboost。
sudo apt-get -y install libboost-all-dev
 
***后記:在我都裝好之后,同事給我個地址: http://www.unixmen.com/how-to-install-powerdns-on-ubuntu-14-04/ 你倒是早給我啊喂!
 
4、都裝好了,開始設置。
(1)設置my.cnf
sudo vim /etc/mysql/my.cnf
里面有一句 bind-address           = 127.0.0.1  需要注釋掉
(查了一下,在  http://blog.chinaunix.net/uid-24500107-id-2602917.html 中說, msyql默認的bind-address是127.0.0.1,這樣的話就算你創建的用戶有可以remote訪問的話 也不能通過-h 來訪問,mysql只接受localhost,錯誤提示為:ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)bind-address后面增加遠程訪問IP地址或者禁掉這句話就可以讓遠程機登陸訪問了)
然后重啟mysql服務:
sudo service mysql restart

 

(2)進入mysql建立powerdns相關表

建立powerdns數據庫:
CREATE DATABASE powerdns;
為數據庫授權(我這里沒有新建用戶,直接授權給root,沒有什么卵用):
GRANT ALL ON powerdns.* TO 'root'@'localhost' IDENTIFIED BY 'password';

這里powerdns是數據庫,root是授權給這個用戶,password是這個用戶的密碼:

之后可以使用
FLUSH PRIVILEGES; 

更新一下用戶設置。

然后使用
USE powerdns; 

進入數據庫中。創建表和記錄。

創建domains表:
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)
);

給domains表創建一個索引:

CREATE UNIQUE INDEX name_index ON domains(name);

創建records表:

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

給records表創建三個索引:

CREATE INDEX rec_name_index ON records(name);
CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);

創建supermasters表;

CREATE TABLE supermasters (
  ip VARCHAR(25) NOT NULL,
  nameserver VARCHAR(255) NOT NULL,
  account VARCHAR(40) DEFAULT NULL
);

OK,mysql建表完成。quit(個人還是比較喜歡mysql在退出時候這個Bye的)

 
(3)設置powerdns:
cd /etc/powerdns

這里面有pdns.d目錄,但是進不去,因為權限不夠,可使用chmod 755 pdns.d提權,之后cd pdns.d進入

ls可看到這個目錄里面有兩個文件:pdns.local和pdns.local.gmysql,這兩個文件是要刪除掉的。但是為保險起見,備份一下先。
sudo cp pdns.local pdns.local.gmysql ~/
sudo rm *.*  #刪的時候一定要記得只是把這兩個文件刪掉,要注意是在這個目錄里使用,要是刪掉其他什么東西可就開心了!
sudo vim pdns.local.gmysql.conf 

建立新文件,在里面輸入以下內容:

# MySQL Configuration
#
# Launch gmysql backend
launch=gmysql
# gmysql parameters
gmysql-host=localhost
gmysql-dbname=powerdns
gmysql-user=poweruser
gmysql-password=ubuntu

(后面三行是剛才數據庫建表時候給權限的,數據庫名、用戶名、密碼注意對應)

保存退出,最后啟動powerdns:
sudo service pdns start

用ps -ef |grep pdns檢查一下看看pdns有沒有啟動。啟動正常,完成!

 
至此一個禮拜的大坑終於特么讓我填上了。簡直開心。
 
最后,嘗試安裝poweradmin,用來管理powerdns。可參考這兩篇:
php版本有點亂,一直沒裝明白,最后同事都重裝了遍,我沒參與。很慚愧,答應同事給裝好結果拖拖拉拉好幾天最后還裝的亂七八糟的。
算個遺憾,以后有空補上~(才怪咧!)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM