godns/README.md

180 lines
3.0 KiB
Markdown
Raw Normal View History

2013-07-23 11:10:38 +00:00
GODNS
====
2013-07-25 04:32:57 +00:00
A simple and fast dns cache server written by go.
2013-07-23 11:10:38 +00:00
Similar to [dnsmasq](http://www.thekelleys.org.uk/dnsmasq/doc.html) ,but support some difference features:
2013-07-23 11:10:38 +00:00
2015-02-12 11:22:05 +00:00
* Keep hosts records in redis and the local file /etc/hosts
2013-07-23 11:10:38 +00:00
* Auto-Reloads when hosts configuration is changed. (Yes, dnsmasq needs to be reloaded)
2013-07-23 11:10:38 +00:00
2013-07-23 16:37:38 +00:00
## Installation & Running
2013-07-24 16:09:07 +00:00
2013-07-25 04:32:57 +00:00
1. Install
$ go get github.com/kenshinx/godns
2. Build
$ cd $GOPATH/src/github.com/kenshinx/godns
2015-02-12 11:22:05 +00:00
$ go build -o godns
2013-07-25 04:32:57 +00:00
3. Running
$ sudo ./godns -c godns.conf
2015-02-11 03:13:05 +00:00
4. Test
$ dig www.github.com @127.0.0.1
More details about how to install and running godns can reference my [blog (Chinese)](http://blog.kenshinx.me/blog/compile-godns/)
2013-07-25 04:32:57 +00:00
## Use godns
2013-07-25 04:32:57 +00:00
$ sudo vi /etc/resolv.conf
nameserver #the ip of godns running
2013-07-24 10:29:38 +00:00
## Configuration
2013-07-23 16:37:38 +00:00
All the configuration in `godns.conf` is a TOML format config file.
2013-07-23 16:37:38 +00:00
More about Toml :[https://github.com/mojombo/toml](https://github.com/mojombo/toml)
2013-07-24 02:52:59 +00:00
#### resolv.conf
Upstream server can be configured by changing file from somewhere other than "/etc/resolv.conf"
2013-07-24 02:52:59 +00:00
```
[resolv]
resolv-file = "/etc/resolv.conf"
```
If multiple `namerservers` are set in resolv.conf, the upsteam server will try in a top to bottom order
2013-07-24 02:52:59 +00:00
2013-07-23 16:37:38 +00:00
2013-07-24 10:29:38 +00:00
#### cache
Only the local memory storage backend is currently implemented. The redis backend is in the todo list
2013-07-24 14:40:18 +00:00
2013-07-24 16:09:07 +00:00
```
[cache]
backend = "memory"
expire = 600 # default expire time 10 minutes
maxcount = 100000
```
2013-07-26 16:29:19 +00:00
#### hosts
Force resolve domain to assigned ip, support two types hosts configuration:
2013-07-26 16:29:19 +00:00
* locale hosts file
* remote redis hosts
__hosts file__
can be assigned at godns.conf,default : `/etc/hosts`
```
[hosts]
host-file = "/etc/hosts"
```
__redis hosts__
This is a special requirment in our system. Must maintain a global hosts configuration,
2013-07-26 16:29:19 +00:00
and support update the hosts record from other remote server.
so "redis-hosts" will be supported, and will query the redis db when each dns request is reached.
2013-07-26 16:29:19 +00:00
2013-11-04 16:50:12 +00:00
The hosts record is organized with redis hash map. and the key of the map is configured.
2013-07-26 16:29:19 +00:00
```
[hosts]
redis-key = "godns:hosts"
```
2013-07-31 02:01:45 +00:00
_Insert hosts records into redis_
```
redis > hset godns:hosts www.sina.com.cn 1.1.1.1
```
2013-07-26 16:29:19 +00:00
2013-07-25 04:32:57 +00:00
## Benchmak
2013-07-26 16:10:17 +00:00
__Debug close__
2013-07-25 04:32:57 +00:00
```
$ go test -bench=.
testing: warning: no tests to run
PASS
BenchmarkDig-8 50000 57945 ns/op
ok _/usr/home/keqiang/godns 3.259s
2013-07-25 04:32:57 +00:00
```
The result : 15342 queries/per second
2013-07-25 04:32:57 +00:00
The test environment:
2013-07-25 04:32:57 +00:00
CentOS release 6.4
2013-07-25 04:32:57 +00:00
* CPU:
Intel Xeon 2.40GHZ
4 cores
2013-07-25 04:32:57 +00:00
* MEM:
46G
2013-07-25 04:32:57 +00:00
2013-08-15 02:58:11 +00:00
## Web console
Joke: A web console for godns
[https://github.com/kenshinx/joke](https://github.com/kenshinx/joke)
screenshot
![joke](https://raw.github.com/kenshinx/joke/master/screenshot/joke.png)
2013-07-25 04:32:57 +00:00
2013-08-21 03:37:28 +00:00
## Deployment
Deployment in productive supervisord highly recommended.
```
[program:godns]
command=/usr/local/bin/godns -c /etc/godns.conf
autostart=true
autorestart=true
user=root
stdout_logfile_maxbytes = 50MB
stdoiut_logfile_backups = 20
stdout_logfile = /var/log/godns.log
```
2013-07-24 16:09:07 +00:00
## TODO
* The redis cache backend
* Update ttl
2013-07-24 10:29:38 +00:00
2013-07-23 16:37:38 +00:00