烹茶细论

bind+mysql一键安装脚本

上次搭建完DNS服务器之后,发现再重新安装一台的话要重复相同的步骤,好麻烦。于是想着自己也写个脚本方便安装,然后就写了个非常粗糙的脚本。后期有时间再修改吧。暂时先用着。
环境:
系统:Centos6.5
需要先安装mysql,编译或者直接yum源安装 yum install -y mysql-server mysql mysql-devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
bind_url="ftp://ftp.isc.org/isc/bind9/cur/9.9/bind-9.9.6.tar.gz"
mysql_bind="http://nchc.dl.sourceforge.net/project/mysql-bind/mysql-bind/mysql-bind-0.2%20src/mysql-bind.tar.gz"
base_dir="/opt/bind_install"
bind_filename=`basename ${bind_url}`
mysql_filename=`basename ${mysql_bind}`
# Download files
function download_files(){
if [ ! -d "$base_dir" ]; then
mkdir $base_dir
fi
cd $base_dir
if [ ! -f "$bind_filename" ];then
if wget ${bind_url}; then
tar -zxvf $bind_filename
else
echo "Failed to download bind tar file!"
fi
else
tar -zxvf $bind_filename
fi
if [ ! -f "$mysql_filename" ];then
if wget ${mysql_bind}; then
tar -zxvf $mysql_filename
else
echo "Failed to download bind_mysql tar file!"
fi
else
tar -zxvf $mysql_filename
fi
}
##configure bind
function confige_bind(){
bind_dir=`cd ${base_dir}/bind*;pwd`
mysql_dir=`cd ${base_dir}/mysql*;pwd`
cd $mysql_dir
cp -f mysqldb.c mysqldb.h ${bind_dir}/bin/named/
cp -f mysqldb.c mysqldb.h ${bind_dir}/bin/named/include
if [ -f "${bind_dir}/bin/named/mysqldb.c" ] || [ -f "${bind_dir}/bin/named/mysqldb.h"] ; then
echo "mysql.c mysql.h in ${bind_dir}/bin/named/"
else
echo "mysql.c mysql.h copy is fail"
fi
#Makefile.in
if [ -f "${bind_dir}/bin/named/Makefile.in" ]; then
sed -i "s/DBDRIVER_OBJS =.*/DBDRIVER_OBJS = mysqldb.@O@/g" ${bind_dir}/bin/named/Makefile.in
sed -i "s/DBDRIVER_SRCS =.*/DBDRIVER_SRCS = mysqldb.c/g" ${bind_dir}/bin/named/Makefile.in
mysql_config=`find / -name mysql_config | awk NR==1`
INCLUDES=`${mysql_config} --cflags`
DBDRIVER_INCLUDES=`echo $INCLUDES | sed 's#\/#\\\/#g'`
LIBS=`${mysql_config} --libs`
DBDRIVER_LIBS=`echo $LIBS | sed 's#\/#\\\/#g'`
sed -i "s/DBDRIVER_INCLUDES =.*/DBDRIVER_INCLUDES = ${DBDRIVER_INCLUDES}/g" ${bind_dir}/bin/named/Makefile.in
sed -i "s/DBDRIVER_LIBS =.*/DBDRIVER_LIBS = ${DBDRIVER_LIBS}/g" ${bind_dir}/bin/named/Makefile.in
fi
#main.c
MAIN=${bind_dir}/bin/named/main.c
if [ -f "$MAIN" ]; then
sed -i "/ns_server_create/i\ mysqldb_init();" $MAIN
sed -i "/ns_server_destroy/a\ mysqldb_clear();" $MAIN
else
echo "$MAIN modify fail"
fi
#bin/named/mysql.c
MYSQLC=${bind_dir}/bin/named/mysqldb.c
if [ -f "$MYSQLC" ]; then
sed -i "s/#include <named\/mysqldb.h>/#include <include\/mysqldb.h>/" $MYSQLC
else
echo "$MYSQLC modify fail"
fi
cd ${bind_dir}
./configure --prefix=/usr/local/bind9/ -disable-openssl-version-check
make && make install
cd /usr/local/bind9/etc/
echo 'asldjfkasjasdgfasdgsgsgsdfg' > random && ../sbin/rndc-confgen -r random >rndc.conf && rm -rf random && tail -n10 rndc.conf | head -n9 | sed -e s/#\//g >named.conf && ../bin/dig > named.root
echo "###########################"
echo "bind dir is /usr/local/bind9/"
echo "###########################"
}
download_files
confige_bind