DNS服务器部署

简单DNS服务器部署

  1. 安装dnsmasq

    sudo apt-get install dnsmasq
    
  2. 添加域名解析记录

    sudo vim /etc/hosts
    ##加入你要解析的域名和ip
    192.168.1.10 example.xxx.com
    192.168.1.11 example2.xxx.com
  3. 设置静态IP以及上级DNS服务器

    sudo vim /etc/network/interface
    ##加入下面的代码,其中enp0s3为网卡名称
    auto enp0s3
    iface enp0s3 inet static
    address 192.168.2.222
    netmask 255.255.255.0
    gateway 192.168.2.1
    dns-nameserver 114.114.114.114
  4. 启动服务

    sudo /etc/init.d/dnsmasq start
    

智能DNS解析部署,根据源IP的不同网段解析不同的IP地址

  1. 安装bind9

    sudo apt-get install bind9
    
  2. 修改配置文件

    sudo vim /etc/bind/named.conf
    

    增加如下内容,声明两个视图,view_2,view_11

    include "/etc/bind/name.2.conf";
    view "View_2" {
    match-clients {"2";};
    zone "1234tv.lan" IN {
    type master;
    file "1234tv.lan-2.zone";
    allow-update {none;};
    };
    };
    include "/etc/bind/name.111.conf";
    view "View_111" {
    match-clients {"111";};
    zone "1234tv.lan" IN {
    type master;
    file "1234tv.lan-111.zone";
    allow-update {none;};
    };
    };

    具体的视图文件如下:

    name.2.conf

    acl "2" {
        192.168.2.0/24;
    };

    name.111.conf

    acl "111" {
        192.168.111.0/24;
    };

    DNS解析文件文件:

    1234tv.lan-2.zone

    $TTL    604800
    @       IN      SOA     1234tv.lan. root.1234tv.lan. (
    2 ; Serial
    604800 ; Refresh
    86400 ; Retry
    2419200 ; Expire
    604800 ) ; Negative Cache TTL
    ;
    @ IN NS 1234tv.lan.
    @ IN A 192.168.2.222
    gitlab IN A 192.168.2.84

    1234tv.lan-111.zone

    $TTL    604800
    @       IN      SOA     1234tv.lan. root.1234tv.lan. (
    2 ; Serial
    604800 ; Refresh
    86400 ; Retry
    2419200 ; Expire
    604800 ) ; Negative Cache TTL
    ;
    @ IN NS 1234tv.lan.
    @ IN A 192.168.111.222
    gitlab IN A 192.168.111.84
2018/12/05 posted in  Linux

PT924光猫 更改桥接模式/路由模式

  1. http://192.168.1.1:8080/cgi-bin/index2.asp 进入这个页面
    用useradmin账号密码登录

  2. 将地址改为http://192.168.1.1:8080/cgi-bin/net-wanset.asp 进入internet设置页面(更改其他地址也会进入其他页面)

其中6_INTERNET_B_VID_229是桥接模式,路由器需要拨号,而5_INTERNET_R_VID_229是路由模式,由猫拨号,路由器不需要拨号

2018/07/19 posted in  Linux

uwsgi重启shell脚本

#!/bin/bash
if [ ! -n "$1" ]
then
    echo "Usages: sh uwsgiserver.sh [start|stop|restart]"
    exit 0
fi

if [ $1 = start ]
then
    psid=`ps aux | grep "uwsgi" | grep -v "grep" | wc -l`
    if [ $psid -gt 4 ]
    then
        echo "uwsgi is running!"
        exit 0
    else
        uwsgi /etc/uwsgi.ini
        echo "Start uwsgi service [OK]"
    fi
    

elif [ $1 = stop ];then
    killall -9 uwsgi
    echo "Stop uwsgi service [OK]"
elif [ $1 = restart ];then
    killall -9 uwsgi
    /usr/bin/uwsgi --ini /etc/uwsgi.ini #修改成自己业务的配置文件或命令
    echo "Restart uwsgi service [OK]"

else
    echo "Usages: sh uwsgiserver.sh [start|stop|restart]"
fi
2018/05/31 posted in  Linux

nginx 相关技巧

  1. 防止域名被人恶意指向,由于nginx存在默认的空主机头问题,可以通过添加如下配置,将未配置的域名强行重定向,或者return 404

      server {
          listen 80 default;
    server_name _;
    rewrite ^(.*) http://www.mylonly.com permanent;
    }
  2. Ubuntu developer tool

    sudo apt-get install build-essential
    
2018/04/26 posted in  Linux

Ubuntu 安装uwsgi

先源码安装python3.6(记得先用apt-get 安装好一些系统库zlib_dev,openssl_dev)
然后利用pip3 安装uwsgi

wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
tar -xvf Python-3.6.3.tar.xz
cd Python-3.6.3/

apt-get install zlib1g-dev
apt-get install libssl-dev
apt-get install sqlite3


./configure --enable-loadable-sqlite-extensions

make && sudo make install


pip3 install uwsgi

uwsgi -i /data/web/xxxx.ini

uwsgi 配置侦测文件改动自动自动重启,在ini中加入

py-autoreload = 1
2017/12/07 posted in  Linux