Ubuntu 16.04 LTS 安装数据库防火墙DBShield
一、GO语言环境配置
1. 安装GO
root@ubuntu:/home/zhl/goworkspace# apt-get install golangReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following packages were automatically installed and are no longer required: linux-headers-4.10.0-28 linux-headers-4.10.0-28-generic linux-image-4.10.0-28-generic linux-image-extra-4.10.0-28-genericUse 'apt autoremove' to remove them.The following additional packages will be installed: golang-1.6 golang-1.6-doc golang-1.6-go golang-1.6-race-detector-runtime golang-1.6-src golang-doc golang-go golang-race-detector-runtime golang-srcSuggested packages: bzr mercurial subversionThe following NEW packages will be installed: golang golang-1.6 golang-1.6-doc golang-1.6-go golang-1.6-race-detector-runtime golang-1.6-src golang-doc golang-go golang-race-detector-runtime golang-src0 upgraded, 10 newly installed, 0 to remove and 50 not upgraded.Need to get 29.4 MB of archives.After this operation, 202 MB of additional disk space will be used.Do you want to continue? [Y/n] YGet:1 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 golang-1.6-src amd64 1.6.2-0ubuntu5~16.04.3 [6,415 kB]Get:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 golang-1.6-go amd64 1.6.2-0ubuntu5~16.04.3 [20.2 MB]Get:3 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 golang-1.6-doc all 1.6.2-0ubuntu5~16.04.3 [2,370 kB] Get:4 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 golang-1.6 all 1.6.2-0ubuntu5~16.04.3 [16.8 kB] Get:5 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 golang-src amd64 2:1.6-1ubuntu4 [3,066 B] Get:6 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 golang-go amd64 2:1.6-1ubuntu4 [21.8 kB] Get:7 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 golang-doc all 2:1.6-1ubuntu4 [2,808 B] Get:8 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 golang all 2:1.6-1ubuntu4 [2,766 B] Get:9 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 golang-1.6-race-detector-runtime amd64 0.0+svn252922-0ubuntu1 [404 kB] Get:10 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 golang-race-detector-runtime amd64 2:1.6-1ubuntu4 [2,854 B] Fetched 29.4 MB in 32s (909 kB/s) Selecting previously unselected package golang-1.6-src.(Reading database ... 248273 files and directories currently installed.)Preparing to unpack .../golang-1.6-src_1.6.2-0ubuntu5~16.04.3_amd64.deb ...Unpacking golang-1.6-src (1.6.2-0ubuntu5~16.04.3) ...Selecting previously unselected package golang-1.6-go.Preparing to unpack .../golang-1.6-go_1.6.2-0ubuntu5~16.04.3_amd64.deb ...Unpacking golang-1.6-go (1.6.2-0ubuntu5~16.04.3) ...Selecting previously unselected package golang-1.6-doc.Preparing to unpack .../golang-1.6-doc_1.6.2-0ubuntu5~16.04.3_all.deb ...Unpacking golang-1.6-doc (1.6.2-0ubuntu5~16.04.3) ...Selecting previously unselected package golang-1.6.Preparing to unpack .../golang-1.6_1.6.2-0ubuntu5~16.04.3_all.deb ...Unpacking golang-1.6 (1.6.2-0ubuntu5~16.04.3) ...Selecting previously unselected package golang-src.Preparing to unpack .../golang-src_2%3a1.6-1ubuntu4_amd64.deb ...Unpacking golang-src (2:1.6-1ubuntu4) ...Selecting previously unselected package golang-go.Preparing to unpack .../golang-go_2%3a1.6-1ubuntu4_amd64.deb ...Unpacking golang-go (2:1.6-1ubuntu4) ...Selecting previously unselected package golang-doc.Preparing to unpack .../golang-doc_2%3a1.6-1ubuntu4_all.deb ...Unpacking golang-doc (2:1.6-1ubuntu4) ...Selecting previously unselected package golang.Preparing to unpack .../golang_2%3a1.6-1ubuntu4_all.deb ...Unpacking golang (2:1.6-1ubuntu4) ...Selecting previously unselected package golang-1.6-race-detector-runtime.Preparing to unpack .../golang-1.6-race-detector-runtime_0.0+svn252922-0ubuntu1_amd64.deb ...Unpacking golang-1.6-race-detector-runtime (0.0+svn252922-0ubuntu1) ...Selecting previously unselected package golang-race-detector-runtime.Preparing to unpack .../golang-race-detector-runtime_2%3a1.6-1ubuntu4_amd64.deb ...Unpacking golang-race-detector-runtime (2:1.6-1ubuntu4) ...Processing triggers for man-db (2.7.5-1) ...Setting up golang-1.6-src (1.6.2-0ubuntu5~16.04.3) ...Setting up golang-1.6-go (1.6.2-0ubuntu5~16.04.3) ...Setting up golang-1.6-doc (1.6.2-0ubuntu5~16.04.3) ...Setting up golang-1.6 (1.6.2-0ubuntu5~16.04.3) ...Setting up golang-src (2:1.6-1ubuntu4) ...Setting up golang-go (2:1.6-1ubuntu4) ...Setting up golang-doc (2:1.6-1ubuntu4) ...Setting up golang (2:1.6-1ubuntu4) ...Setting up golang-1.6-race-detector-runtime (0.0+svn252922-0ubuntu1) ...Setting up golang-race-detector-runtime (2:1.6-1ubuntu4) ...
2. 环境变量配置
root@ubuntu:/usr/lib/go# export GOROOT=/usr/lib/goroot@ubuntu:/usr/lib/go# export GOPATH=/home/zhl/goworkdir
二、DBShield安装
1. 下载DBShield源码
root@ubuntu:/home/zhl/goworkspace/src# go get -v -u -x github.com/nim4/DBShieldgithub.com/nim4/DBShield (download)cd .git clone https://github.com/nim4/DBShield /home/zhl/goworkspace/src/github.com/nim4/DBShieldcd /home/zhl/goworkspace/src/github.com/nim4/DBShieldgit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/nim4/DBShieldgit show-refcd /home/zhl/goworkspace/src/github.com/nim4/DBShieldgit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/nim4/DBShieldgit config remote.origin.urlgithub.com/boltdb/bolt (download)cd .git clone https://github.com/boltdb/bolt /home/zhl/goworkspace/src/github.com/boltdb/boltcd /home/zhl/goworkspace/src/github.com/boltdb/boltgit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/boltdb/boltgit show-refcd /home/zhl/goworkspace/src/github.com/boltdb/boltgit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/nim4/DBShieldgit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/nim4/DBShieldgit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/nim4/DBShieldgit config remote.origin.urlgithub.com/spf13/viper (download)cd .git clone https://github.com/spf13/viper /home/zhl/goworkspace/src/github.com/spf13/vipercd /home/zhl/goworkspace/src/github.com/spf13/vipergit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/spf13/vipergit show-refcd /home/zhl/goworkspace/src/github.com/spf13/vipergit submodule update --init --recursivegithub.com/fsnotify/fsnotify (download)cd .git clone https://github.com/fsnotify/fsnotify /home/zhl/goworkspace/src/github.com/fsnotify/fsnotifycd /home/zhl/goworkspace/src/github.com/fsnotify/fsnotifygit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/fsnotify/fsnotifygit show-refcd /home/zhl/goworkspace/src/github.com/fsnotify/fsnotifygit submodule update --init --recursiveFetching https://golang.org/x/sys/unix?go-get=1https fetch failed: Get https://golang.org/x/sys/unix?go-get=1: dial tcp 216.239.37.1:443: i/o timeoutpackage golang.org/x/sys/unix: unrecognized import path "golang.org/x/sys/unix" (https fetch: Get https://golang.org/x/sys/unix?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)github.com/hashicorp/hcl (download)cd .git clone https://github.com/hashicorp/hcl /home/zhl/goworkspace/src/github.com/hashicorp/hclcd /home/zhl/goworkspace/src/github.com/hashicorp/hclgit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/hashicorp/hclgit show-refcd /home/zhl/goworkspace/src/github.com/hashicorp/hclgit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/hashicorp/hclgit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/hashicorp/hclgit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/hashicorp/hclgit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/hashicorp/hclgit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/hashicorp/hclgit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/hashicorp/hclgit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/hashicorp/hclgit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/hashicorp/hclgit config remote.origin.urlgithub.com/magiconair/properties (download)cd .git clone https://github.com/magiconair/properties /home/zhl/goworkspace/src/github.com/magiconair/propertiescd /home/zhl/goworkspace/src/github.com/magiconair/propertiesgit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/magiconair/propertiesgit show-refcd /home/zhl/goworkspace/src/github.com/magiconair/propertiesgit submodule update --init --recursivegithub.com/mitchellh/mapstructure (download)cd .git clone https://github.com/mitchellh/mapstructure /home/zhl/goworkspace/src/github.com/mitchellh/mapstructurecd /home/zhl/goworkspace/src/github.com/mitchellh/mapstructuregit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/mitchellh/mapstructuregit show-refcd /home/zhl/goworkspace/src/github.com/mitchellh/mapstructuregit submodule update --init --recursivegithub.com/pelletier/go-toml (download)cd .git clone https://github.com/pelletier/go-toml /home/zhl/goworkspace/src/github.com/pelletier/go-tomlcd /home/zhl/goworkspace/src/github.com/pelletier/go-tomlgit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/pelletier/go-tomlgit show-refcd /home/zhl/goworkspace/src/github.com/pelletier/go-tomlgit submodule update --init --recursivegithub.com/spf13/afero (download)cd .git clone https://github.com/spf13/afero /home/zhl/goworkspace/src/github.com/spf13/aferocd /home/zhl/goworkspace/src/github.com/spf13/aferogit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/spf13/aferogit show-refcd /home/zhl/goworkspace/src/github.com/spf13/aferogit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/spf13/aferogit config remote.origin.urlFetching https://golang.org/x/text/transform?go-get=1https fetch failed: Get https://golang.org/x/text/transform?go-get=1: dial tcp 216.239.37.1:443: i/o timeoutpackage golang.org/x/text/transform: unrecognized import path "golang.org/x/text/transform" (https fetch: Get https://golang.org/x/text/transform?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)Fetching https://golang.org/x/text/unicode/norm?go-get=1https fetch failed: Get https://golang.org/x/text/unicode/norm?go-get=1: dial tcp 216.239.37.1:443: i/o timeoutpackage golang.org/x/text/unicode/norm: unrecognized import path "golang.org/x/text/unicode/norm" (https fetch: Get https://golang.org/x/text/unicode/norm?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)github.com/spf13/cast (download)cd .git clone https://github.com/spf13/cast /home/zhl/goworkspace/src/github.com/spf13/castcd /home/zhl/goworkspace/src/github.com/spf13/castgit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/spf13/castgit show-refcd /home/zhl/goworkspace/src/github.com/spf13/castgit submodule update --init --recursivegithub.com/spf13/jwalterweatherman (download)cd .git clone https://github.com/spf13/jwalterweatherman /home/zhl/goworkspace/src/github.com/spf13/jwalterweathermancd /home/zhl/goworkspace/src/github.com/spf13/jwalterweathermangit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/spf13/jwalterweathermangit show-refcd /home/zhl/goworkspace/src/github.com/spf13/jwalterweathermangit submodule update --init --recursivegithub.com/spf13/pflag (download)cd .git clone https://github.com/spf13/pflag /home/zhl/goworkspace/src/github.com/spf13/pflagcd /home/zhl/goworkspace/src/github.com/spf13/pflaggit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/spf13/pflaggit show-refcd /home/zhl/goworkspace/src/github.com/spf13/pflaggit submodule update --init --recursiveFetching https://gopkg.in/yaml.v2?go-get=1Parsing meta tags from https://gopkg.in/yaml.v2?go-get=1 (status code 200)get "gopkg.in/yaml.v2": found meta tag main.metaImport{Prefix:"gopkg.in/yaml.v2", VCS:"git", RepoRoot:"https://gopkg.in/yaml.v2"} at https://gopkg.in/yaml.v2?go-get=1gopkg.in/yaml.v2 (download)cd .git clone https://gopkg.in/yaml.v2 /home/zhl/goworkspace/src/gopkg.in/yaml.v2cd /home/zhl/goworkspace/src/gopkg.in/yaml.v2git submodule update --init --recursivecd /home/zhl/goworkspace/src/gopkg.in/yaml.v2git show-refcd /home/zhl/goworkspace/src/gopkg.in/yaml.v2git submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/nim4/DBShieldgit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/nim4/DBShieldgit config remote.origin.urlgithub.com/xwb1989/sqlparser (download)cd .git clone https://github.com/xwb1989/sqlparser /home/zhl/goworkspace/src/github.com/xwb1989/sqlparsercd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparsergit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparsergit show-refcd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparsergit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparsergit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparsergit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparsergit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparsergit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/nim4/DBShieldgit config remote.origin.urlcd /home/zhl/goworkspace/src/github.com/nim4/DBShieldgit config remote.origin.urlgithub.com/gorilla/securecookie (download)cd .git clone https://github.com/gorilla/securecookie /home/zhl/goworkspace/src/github.com/gorilla/securecookiecd /home/zhl/goworkspace/src/github.com/gorilla/securecookiegit submodule update --init --recursivecd /home/zhl/goworkspace/src/github.com/gorilla/securecookiegit show-refcd /home/zhl/goworkspace/src/github.com/gorilla/securecookiegit submodule update --init --recursive
2. DBShield 编译并安装:
root@ubuntu:/home/zhl/goworkspace/src/github.com/nim4/DBShield# go build root@ubuntu:/home/zhl/goworkspace/src/github.com/nim4/DBShield# go install
root@ubuntu:/home/zhl/goworkspace/bin# ./DBShield -hDBShield 1.0.0-beta4Usage of ./DBShield: -a get list of abnormal queries -c file config file (default "/etc/dbshield.yml") -h show help -k show parsed config and exit -l get list of captured patterns -purge remove internal database -r string remove a captured pattern -sql-max-length-errors int truncate queries in error logs to the given length (default unlimited) -sql-max-length-ui int truncate queries in debug UIs to the given length (default 512) (default 512) -version show version
可能会遇到如下问题:
root@ubuntu:/home/zhl/goworkspace/src/github.com/nim4/DBShield# go build../../fsnotify/fsnotify/inotify.go:19:2: cannot find package "golang.org/x/sys/unix" in any of: /usr/lib/go/src/golang.org/x/sys/unix (from $GOROOT) /home/zhl/goworkspace/src/golang.org/x/sys/unix (from $GOPATH)../../spf13/afero/util.go:29:2: cannot find package "golang.org/x/text/transform" in any of: /usr/lib/go/src/golang.org/x/text/transform (from $GOROOT) /home/zhl/goworkspace/src/golang.org/x/text/transform (from $GOPATH) ../../spf13/afero/util.go:30:2: cannot find package "golang.org/x/text/unicode/norm" in any of: /usr/lib/go/src/golang.org/x/text/unicode/norm (from $GOROOT) /home/zhl/goworkspace/src/golang.org/x/text/unicode/norm (from $GOPATH)
解决方法
root@ubuntu:/home/zhl/goworkspace/src# git clone https://github.com/golang/sys.gitCloning into 'sys'...remote: Counting objects: 3285, done.remote: Compressing objects: 100% (9/9), done.remote: Total 3285 (delta 3), reused 6 (delta 2), pack-reused 3274Receiving objects: 100% (3285/3285), 2.08 MiB | 375.00 KiB/s, done.Resolving deltas: 100% (2757/2757), done. Checking connectivity... done. root@ubuntu:/home/zhl/goworkspace/src# mkdir -p golang.org/x/sys/unix root@ubuntu:/home/zhl/goworkspace/src/golang.org/x# cp -r ./../../sys .
类似地操作:git clone https://github.com/golang/text.git,并拷贝到相关目录