CentOS9 Openresty代理Bind主从配置

操作系统

IP

服务

CentOS9

192.168.8.73

Bind服务

CentOS9

192.168.8.74

Bind服务

CentOS9

192.168.8.71

openresty代理

CentOS9

192.168.8.72

openresty代理

  1. 第一步下载openresty安装包

wget -c https://openresty.org/download/openresty-1.25.3.1.tar.gz

  1. 第二步解压软件包到opt目录下

[root@bind-m-74 opt]# tar xf openresty-1.25.3.1.tar.gz

  1. 下载缺少的依赖包

yum -y install perl-devel openssl-devel pcre-devel gcc gcc-c++ autoconf make zlib-devel 

  1. 编译安装openresty依赖包

./configure ; echo $?

  1. 编译完成后继续安装到没有报错就完成安装了。

 make && make install ; echo $?

  1. 进入到编译安装完成的目录中:

cd /usr/local/openresty

  1. 进入到70 主的配置文件中

[root@bind-m-74 conf]# cat /usr/local/openresty/nginx/conf/nginx.conf

#user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;

    #tcp_nopush     on;

    #keepalive_timeout  0;

    keepalive_timeout  65;

    #gzip  on;

    server {

        listen       80;

        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   html;

            index  index.html index.htm;

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #    root           html;

        #    fastcgi_pass   127.0.0.1:9000;

        #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #    include        fastcgi_params;

        #}

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

    # HTTPS server

    #

    #server {

    #    listen       443 ssl;

    #    server_name  localhost;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;

    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers  on;

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

}

stream {

 upstream bind-ms {

 server 192.168.8.73:53;

 server 192.168.8.74:53;

# access_log logs/proxy-bind-access.log ;

# error_log logs/proxy-bind-error.log error;

 }

 server {

 listen 53 udp;

 proxy_pass bind-ms;

 proxy_timeout 120s;

# access_log logs/proxy-bind-access.log ;

 error_log logs/proxy-bind-error.log error;

 }

}

2.Openrestry从的主配置:

[root@zabbixguo130 conf]# cat nginx.conf

#user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;

    #tcp_nopush     on;

    #keepalive_timeout  0;

    keepalive_timeout  65;

    #gzip  on;

#    server {

#       listen       80;

#        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

#        location / {

#            root   html;

#            index  index.html index.htm;

#       }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

#        error_page   500 502 503 504  /50x.html;

#        location = /50x.html {

#            root   html;

#        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #    root           html;

        #    fastcgi_pass   127.0.0.1:9000;

        #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #    include        fastcgi_params;

        #}

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

#    }

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

    # HTTPS server

    #

    #server {

    #    listen       443 ssl;

    #    server_name  localhost;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;

    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers  on;

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

}

stream {

 upstream bind-ms {

 server 192.168.8.140:53;

 server 192.168.8.141:53;

# access_log logs/proxy-bind-access.log ;

# error_log logs/proxy-bind-error.log error;

 }

 server {

 listen 53 udp;

 proxy_pass bind-ms;

 proxy_timeout 120s;

# access_log logs/proxy-bind-access.log ;

 error_log logs/proxy-bind-error.log error;

 }

}

74最后测试没问题

root@localhost openresty-1.25.3.1]# dig www.guomc.com @192.168.8.74

; <<>> DiG 9.16.23-RH <<>> www.guomc.com @192.168.8.74

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9671

;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:

; EDNS: version: 0, flags:; udp: 1232

; COOKIE: 007304b61ca0838e0100000065afa306c1aac70cf7cdb798 (good)

;; QUESTION SECTION:

;www.guomc.com. IN A

;; ANSWER SECTION:

www.guomc.com. 7200 IN A 192.168.8.74

www.guomc.com. 7200 IN A 192.168.8.73

;; Query time: 4 msec

;; SERVER: 192.168.8.74#53(192.168.8.74)

;; WHEN: Tue Jan 23 19:29:12 CST 2024

;; MSG SIZE  rcvd: 102

[root@localhost openresty-1.25.3.1]#

73 测试

[root@localhost openresty-1.25.3.1]# dig www.guomc.com @192.168.8.73

; <<>> DiG 9.16.23-RH <<>> www.guomc.com @192.168.8.73

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63818

;; flags: qr aa rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:

; EDNS: version: 0, flags:; udp: 1232

; COOKIE: 7fecde1f7d393f840100000065afa2fb0df23893e2778884 (good)

;; QUESTION SECTION:

;www.guomc.com. IN A

;; ANSWER SECTION:

www.guomc.com. 7200 IN A 192.168.8.77

www.guomc.com. 7200 IN A 192.168.8.75

www.guomc.com. 7200 IN A 192.168.8.74

www.guomc.com. 7200 IN A 192.168.8.73

www.guomc.com. 7200 IN A 192.168.8.76

;; Query time: 4 msec

;; SERVER: 192.168.8.73#53(192.168.8.73)

;; WHEN: Tue Jan 23 19:29:00 CST 2024

;; MSG SIZE  rcvd: 150

最后重新启动openrestry
  • 21
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
CentOS 系统上,我们可以使用 BIND9 实现 DNS 服务器的主从配置。主服务器将承担管理 DNS 区域的主要任务,从服务器将从主服务器获取 DNS 区域的副本。这样可以提高 DNS 服务器的可靠性和可用性。 下面是在 CentOS 系统上实现 BIND9 主从配置的步骤: 1. 安装 BIND9 软件包 在主服务器和从服务器上都需要安装 BIND9 软件包。可以使用以下命令在 CentOS 系统上安装 BIND9: ``` sudo yum install bind bind-utils ``` 2. 配置主服务器 在主服务器上,需要配置 BIND9 以管理 DNS 区域。可以编辑 /etc/named.conf 文件并添加以下内容: ``` zone "example.com" IN { type master; file "example.com.zone"; allow-transfer { 192.168.1.2; }; // 允许从服务器的 IP 地址 }; ``` 这里的 "example.com" 是你要管理的 DNS 区域。你可以将其替换为自己的域名。"example.com.zone" 是 DNS 区域的文件名,你可以将其替换为你自己的文件名。 然后,你需要创建一个 DNS 区域文件(例如 /var/named/example.com.zone),并添加相应的 DNS 记录。例如: ``` $TTL 86400 @ IN SOA ns1.example.com. admin.example.com. ( 2019010101 ; serial 3600 ; refresh 1800 ; retry 604800 ; expire 86400 ; minimum ) @ IN NS ns1.example.com. @ IN NS ns2.example.com. ns1 IN A 192.168.1.1 ns2 IN A 192.168.1.2 www IN A 192.168.1.3 ``` 这里的 "ns1.example.com" 和 "ns2.example.com" 是主服务器和从服务器的域名。你需要将其替换为你自己的域名。"192.168.1.1" 和 "192.168.1.2" 是主服务器和从服务器的 IP 地址。你需要将其替换为实际的 IP 地址。 3. 配置从服务器 在从服务器上,需要配置 BIND9 以从主服务器获取 DNS 区域的副本。可以编辑 /etc/named.conf 文件并添加以下内容: ``` zone "example.com" IN { type slave; file "example.com.zone"; masters { 192.168.1.1; }; // 主服务器的 IP 地址 }; ``` 这里的 "example.com" 是你要获取的 DNS 区域。你可以将其替换为自己的域名。"example.com.zone" 是 DNS 区域的文件名,你可以将其替换为你自己的文件名。 然后,你需要启动 BIND9 服务并测试配置是否正确。你可以使用以下命令启动 BIND9 服务并检查日志: ``` sudo systemctl start named sudo systemctl status named sudo tail -f /var/log/messages ``` 如果配置正确,则你应该能够在从服务器上看到从主服务器获取 DNS 区域的副本。 总之,以上是在 CentOS 系统上实现 BIND9 主从配置的步骤。需要注意的是,在配置 BIND9 主从时,需要确保主服务器和从服务器之间可以相互通信,并且需要在防火墙中打开相应的端口。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值