Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

常见python脚本 #2

Open
AlexZ33 opened this issue Oct 25, 2019 · 0 comments
Open

常见python脚本 #2

AlexZ33 opened this issue Oct 25, 2019 · 0 comments
Labels

Comments

@AlexZ33
Copy link
Member

AlexZ33 commented Oct 25, 2019

bind+mysql一键安装脚本

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

#!/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

@AlexZ33 AlexZ33 added the 运维 label Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant