海运的博客

PDNS实现智能DNS

发布时间:May 16, 2014 // 分类:DNS // No Comments

PDNS默认不支持bind view功能,通过PowerDNS Recursor加载Lua脚本判断再递归查询PowerDNS实现智能DNS。

#关闭数据包缓存,测试时开启查询时直接读缓存不经过lua preresolve()
disable-packetcache=yes
forward-zones=com=108.61.242.102
local-address=0.0.0.0
lua-dns-script=/tmp/b.lua
#转发所有域到pdns server
forward-zones=.=127.0.0.1:54

lua:

function preresolve ( remoteip, domain, qtype )
    pdnslog("a test message.. received query "..domain.." from "..remoteip.." on "..getlocaladdress());
    ret={}
    if qtype ~= pdns.A then return -1, ret end --非A记录查询跳过,后端查询
    local ips = {"192.168.1.1/32", "10.1.0.0/16", "127.0.0.0/24"}
    if matchnetmask(remoteip, ips) and domain == "www.example.com."
        then
            ret[1]= {qtype=pdns.A, content="85.17.220.215", ttl=86400}
            setvariable()
            return 0, ret
        else
            setvariable()
            return -1, ret 
        end
    end

PDNS缓存

发布时间:May 16, 2014 // 分类:DNS // No Comments

packet cache:数据包缓存,优先级高
query cache:后台数据库查询缓存,packet cache无时查询
negquery-cache:无域名或域名无记录缓存
缓存操作:

PDNS Server:
pdns_control ccounts
pdns_control purge example.net
pdns_control purge

PDNS Recursor
rec_control get cache-entries packetcache-entries negcache-entries nsspeeds-entries
rec_control dump-cache /tmp/dns-cache
rec_control wipe-cache example.net

Tmux自动恢复或打开新窗口

发布时间:May 14, 2014 // 分类:Tmux // No Comments

方法1:

if [ "$TERM" != "screen" ]; then
    WHOAMI=$(whoami)
    if tmux has-session -t $WHOAMI 2>/dev/null; then
        tmux -2 attach-session -t $WHOAMI
    else
        tmux -2 new-session -s $WHOAMI
        exit
    fi
fi

方法2:

if [ `which tmux 2> /dev/null` -a -z "$TMUX" ]; then
        tmux -2 attach || tmux -2 new; exit
fi

20220315更新:

[ -f /usr/bin/tmux ] && [ -z "$TMUX"  ] && { tmux attach || tmux new-session;}

20230211更新,更简单的方法:

tmux new -As0

参考:
http://bionicraptor.ca/2011/07/24/automatically-start-tmux/
https://coderwall.com/p/tgm2la

MySQL主从同步配置

发布时间:May 8, 2014 // 分类:数据库 // No Comments

Master配置:

log-bin = mysql-bin
server-id = 1
binlog-do-db = powerdns #要同步的数据库

Master新增slave账号:

mysql> grant replication slave on *.* to 'slave'@'192.168.1.2' identified by 'passwd';  
mysql> flush privileges; 

重启Master MySQL,查看Master状态信息,记住File名称,POS位置。

mysql> show master status;  
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 |      309 | powerdns     | mysql            |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

Slave配置:

server-id =2 
slave-skip-errors = 1062 #跳过重复字段错误

开始同步:

mysql> change master to master_host='192.168.1.1',master_user='slave',master_password='passwd',\
master_log_file='mysql-bin.000002',master_log_pos=309;  
mysql> start slave;

查看Slave同步状态:

mysql> show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

Nginx配置泛二域名保存为一级域名名称日志

发布时间:May 1, 2014 // 分类:Nginx // No Comments

listen    80 default; 
server_name   ~^(.*?\.)*(?<domain>.[^\.]+?\..[^\.|\d]+?)$;
access_log  /home/wwwlogs/$domain main;

参考:
http://nginx.org/en/docs/http/server_names.html#regex_names

分类
最新文章
最近回复
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...
  • jiangker: good, very helpful to me
  • fengfeng: N1 armbian 能有编译下内核吗。。我要开启can 不懂怎么操作
  • 1: 方法一ngtcp2要改下:./configure PKG_CONFIG_PATH=/usr/l...