红联Linux门户
Linux帮助

Ubuntu 16.04 LTS安装数据库防火墙DBShield

发布时间:2017-09-23 09:23:27来源:linux网站作者:水共禾刀
一、GO语言环境配置
1.安装GO
root@ubuntu:/home/zhl/goworkspace# apt-get install golang
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The 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-generic
Use '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-src
Suggested packages:
bzr mercurial subversion
The 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-src
0 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] Y
Get: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/go
root@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/DBShield
github.com/nim4/DBShield (download)
cd .
git clone https://github.com/nim4/DBShield /home/zhl/goworkspace/src/github.com/nim4/DBShield
cd /home/zhl/goworkspace/src/github.com/nim4/DBShield
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/nim4/DBShield
git show-ref
cd /home/zhl/goworkspace/src/github.com/nim4/DBShield
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/nim4/DBShield
git config remote.origin.url
github.com/boltdb/bolt (download)
cd .
git clone https://github.com/boltdb/bolt /home/zhl/goworkspace/src/github.com/boltdb/bolt
cd /home/zhl/goworkspace/src/github.com/boltdb/bolt
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/boltdb/bolt
git show-ref
cd /home/zhl/goworkspace/src/github.com/boltdb/bolt
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/nim4/DBShield
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/nim4/DBShield
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/nim4/DBShield
git config remote.origin.url
github.com/spf13/viper (download)
cd .
git clone https://github.com/spf13/viper /home/zhl/goworkspace/src/github.com/spf13/viper
cd /home/zhl/goworkspace/src/github.com/spf13/viper
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/spf13/viper
git show-ref
cd /home/zhl/goworkspace/src/github.com/spf13/viper
git submodule update --init --recursive
github.com/fsnotify/fsnotify (download)
cd .
git clone https://github.com/fsnotify/fsnotify /home/zhl/goworkspace/src/github.com/fsnotify/fsnotify
cd /home/zhl/goworkspace/src/github.com/fsnotify/fsnotify
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/fsnotify/fsnotify
git show-ref
cd /home/zhl/goworkspace/src/github.com/fsnotify/fsnotify
git submodule update --init --recursive
Fetching https://golang.org/x/sys/unix?go-get=1
https fetch failed: Get https://golang.org/x/sys/unix?go-get=1: dial tcp 216.239.37.1:443: i/o timeout
package 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/hcl
cd /home/zhl/goworkspace/src/github.com/hashicorp/hcl
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/hashicorp/hcl
git show-ref
cd /home/zhl/goworkspace/src/github.com/hashicorp/hcl
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/hashicorp/hcl
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/hashicorp/hcl
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/hashicorp/hcl
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/hashicorp/hcl
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/hashicorp/hcl
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/hashicorp/hcl
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/hashicorp/hcl
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/hashicorp/hcl
git config remote.origin.url
github.com/magiconair/properties (download)
cd .
git clone https://github.com/magiconair/properties /home/zhl/goworkspace/src/github.com/magiconair/properties
cd /home/zhl/goworkspace/src/github.com/magiconair/properties
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/magiconair/properties
git show-ref
cd /home/zhl/goworkspace/src/github.com/magiconair/properties
git submodule update --init --recursive
github.com/mitchellh/mapstructure (download)
cd .
git clone https://github.com/mitchellh/mapstructure /home/zhl/goworkspace/src/github.com/mitchellh/mapstructure
cd /home/zhl/goworkspace/src/github.com/mitchellh/mapstructure
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/mitchellh/mapstructure
git show-ref
cd /home/zhl/goworkspace/src/github.com/mitchellh/mapstructure
git submodule update --init --recursive
github.com/pelletier/go-toml (download)
cd .
git clone https://github.com/pelletier/go-toml /home/zhl/goworkspace/src/github.com/pelletier/go-toml
cd /home/zhl/goworkspace/src/github.com/pelletier/go-toml
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/pelletier/go-toml
git show-ref
cd /home/zhl/goworkspace/src/github.com/pelletier/go-toml
git submodule update --init --recursive
github.com/spf13/afero (download)
cd .
git clone https://github.com/spf13/afero /home/zhl/goworkspace/src/github.com/spf13/afero
cd /home/zhl/goworkspace/src/github.com/spf13/afero
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/spf13/afero
git show-ref
cd /home/zhl/goworkspace/src/github.com/spf13/afero
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/spf13/afero
git config remote.origin.url
Fetching https://golang.org/x/text/transform?go-get=1
https fetch failed: Get https://golang.org/x/text/transform?go-get=1: dial tcp 216.239.37.1:443: i/o timeout
package 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=1
https fetch failed: Get https://golang.org/x/text/unicode/norm?go-get=1: dial tcp 216.239.37.1:443: i/o timeout
package 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/cast
cd /home/zhl/goworkspace/src/github.com/spf13/cast
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/spf13/cast
git show-ref
cd /home/zhl/goworkspace/src/github.com/spf13/cast
git submodule update --init --recursive
github.com/spf13/jwalterweatherman (download)
cd .
git clone https://github.com/spf13/jwalterweatherman /home/zhl/goworkspace/src/github.com/spf13/jwalterweatherman
cd /home/zhl/goworkspace/src/github.com/spf13/jwalterweatherman
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/spf13/jwalterweatherman
git show-ref
cd /home/zhl/goworkspace/src/github.com/spf13/jwalterweatherman
git submodule update --init --recursive
github.com/spf13/pflag (download)
cd .
git clone https://github.com/spf13/pflag /home/zhl/goworkspace/src/github.com/spf13/pflag
cd /home/zhl/goworkspace/src/github.com/spf13/pflag
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/spf13/pflag
git show-ref
cd /home/zhl/goworkspace/src/github.com/spf13/pflag
git submodule update --init --recursive
Fetching https://gopkg.in/yaml.v2?go-get=1
Parsing 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=1
gopkg.in/yaml.v2 (download)
cd .
git clone https://gopkg.in/yaml.v2 /home/zhl/goworkspace/src/gopkg.in/yaml.v2
cd /home/zhl/goworkspace/src/gopkg.in/yaml.v2
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/gopkg.in/yaml.v2
git show-ref
cd /home/zhl/goworkspace/src/gopkg.in/yaml.v2
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/nim4/DBShield
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/nim4/DBShield
git config remote.origin.url
github.com/xwb1989/sqlparser (download)
cd .
git clone https://github.com/xwb1989/sqlparser /home/zhl/goworkspace/src/github.com/xwb1989/sqlparser
cd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparser
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparser
git show-ref
cd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparser
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparser
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparser
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparser
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/xwb1989/sqlparser
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/nim4/DBShield
git config remote.origin.url
cd /home/zhl/goworkspace/src/github.com/nim4/DBShield
git config remote.origin.url
github.com/gorilla/securecookie (download)
cd .
git clone https://github.com/gorilla/securecookie /home/zhl/goworkspace/src/github.com/gorilla/securecookie
cd /home/zhl/goworkspace/src/github.com/gorilla/securecookie
git submodule update --init --recursive
cd /home/zhl/goworkspace/src/github.com/gorilla/securecookie
git show-ref
cd /home/zhl/goworkspace/src/github.com/gorilla/securecookie
git 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 -h
DBShield 1.0.0-beta4
Usage 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.git
Cloning 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 3274
Receiving 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,并拷贝到相关目录
 
本文永久更新地址:http://www.linuxdiyf.com/linux/32651.html