本文中的代码在 这里
目录结构:
│ .gitignore
│ mvnw
│ mvnw.cmd
│ pom.xml
│ README.md
│
├─src
│ │
│ ├─main
│ ├─java
│ │ └─com
│ │ └─guochenxu
│ │ └─gstore
│ │ │ GstoreApplication.java
│ │ │
│ │ ├─config
│ │ │ GstoreConfiguration.java // 数据库配置信息
│ │ │ WebMvcConfig.java
│ │ │
│ │ ├─controller
│ │ │ GstoreController.java // 接口
│ │ │
│ │ ├─entity
│ │ │ GstoreResult.java // gstore查询结果
│ │ │
│ │ ├─jgsc
│ │ │ GstoreConnector.java
│ │ │
│ │ ├─service
│ │ │ │ GstoreService.java // 服务类
│ │ │ │
│ │ │ └─impl
│ │ │ GstoreServiceImpl.java
│ │ │
│ │ └─vo
│ │ R.java
│ │
│ └─resources
│ │ application.properties
│ │ application.yml
│ │
│ ├─static
│ └─templates
│
├─test_scripts // 测试脚本文件
gstore 安装
环境配置
-
检查 gcc/g++版本
g++ --version
需要版本大于 5.4, 否则需要安装
wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-5.4.0/gcc-5.4.0.tar.gz tar xvf gcc-5.4.0.tar.gz ./contrib/download_prerequisites cd .. mkdir gcc-build-5.4.0 cd gcc-build-5.4.0 ../gcc-5.4.0/configure --prefix=...(你的安装目录) --enable-checking=release --enable-languages=c,c++ --disable-multilib make -j4 #允许4个编译命令同时执行,加速编译过程 make install
-
安装 readline
wget -c ftp://ftp.gnu.org/gnu/readline/readline-7.0.tar.gz tar -zxvf readline-7.0.tar.gz cd readline-7.0 ./configure --prefix=/home/guochenxu/soft/readline # 指定软件安装路径 make && make installl
-
安装 boost (1.56-1.59)
wget http://sourceforge.net/projects/boost/files/boost/1.56.0/boost_1_56_0.tar.gz tar -xzvf boost_1_56_0.tar.gz cd boost_1_56_0 ./bootstrap.sh --prefix=/home/guochenxu/soft/boost ./b2 ./b2 install
-
安装 curl
wget https://curl.haxx.se/download/curl-7.55.1.tar.gz tar -xzvf curl-7.55.1.tar.gz cd curl-7.55.1 ./configure --prefix=/home/guochenxu/soft/curl make make install
-
安装 cmake 检查版本
cmake --version
若没有则需要安装
wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz tar -xvf cmake-3.6.2.tar.gz && cd cmake-3.6.2/ ./bootstrap --prefix=... make make install
-
安装 pkg-config 检查版本
pkg-config --version
这个系统应该都有安装
-
安装 uuid 从这里 下载压缩包
tar -zxvf libuuid-1.0.3.tar.gz cd libuuid-1.0.3 ./configure --prefix=/home/guochenxu/soft/libuuid make make install
-
安装 jemalloc 从这里 下载 jemalloc
tar -zxvf jemalloc-5.2.1.tar.gz cd jemalloc-5.2.1 ./configure --prefix=/home/guochenxu/soft/jemalloc make make install
-
安装 openssl 从这里 下载 openssl
tar -zxvf openssl-3.1.0.tar.gz cd openssl-3.1.0 ./Configure --prefix=/home/guochenxu/soft/openssl make make install
-
安装 ncurses 从这里 下载 ncurses
tar -zxvf ncurses.6.4.tar.gz cd ncurses.6.4 ./configure --prefix=/home/guochenxu/soft/ncurses make make install
ncurses 装完之后可能会缺一些动态编译文件, 需要从这里 下载后复制到
/prefix/lib
目录下
全部安装完后需要配置环境变量, 打开 ~/.bashrc
, 添加以下环境变量配置 (路径要改成自己安装的路径)
export UUID_LIB_PATH=/home/guochenxu/soft/libuuid/lib/
export UUID_INCLUDE_PATH=/home/guochenxu/soft/libuuid/include/
export LD_LIBRARY_PATH=${UUID_LIB_PATH}:$LD_LIBRARY_PATH
export LIBRARY_PATH=${UUID_LIB_PATH}:$LIBRARY_PATH
export C_INCLUDE_PATH=${UUID_INCLUDE_PATH}:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=${UUID_INCLUDE_PATH}:$CPLUS_INCLUDE_PATH
export PKG_CONFIG_PATH=/home/guochenxu/soft/libuuid/lib/pkgconfig/:$PKG_CONFIG_PATH
export READLINE_LIB_PATH=/home/guochenxu/soft/readline/lib/
export READLINE_INCLUDE_PATH=/home/guochenxu/soft/readline/include/
export LD_LIBRARY_PATH=${READLINE_LIB_PATH}:$LD_LIBRARY_PATH
export LIBRARY_PATH=${READLINE_LIB_PATH}:$LIBRARY_PATH
export C_INCLUDE_PATH=${READLINE_INCLUDE_PATH}:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=${READLINE_INCLUDE_PATH}:$CPLUS_INCLUDE_PATH
export BOOST_LIB_PATH=/home/guochenxu/soft/boost/lib/
export BOOST_INCLUDE_PATH=/home/guochenxu/soft/boost/include/
export LD_LIBRARY_PATH=${BOOST_LIB_PATH}:$LD_LIBRARY_PATH
export LIBRARY_PATH=${BOOST_LIB_PATH}:$LIBRARY_PATH
export C_INCLUDE_PATH=${BOOST_INCLUDE_PATH}:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=${BOOST_INCLUDE_PATH}:$CPLUS_INCLUDE_PATH
export CURL_LIB_PATH=/home/guochenxu/soft/curl/lib/
export CURL_INCLUDE_PATH=/home/guochenxu/soft/curl/include/
export LD_LIBRARY_PATH=${CURL_LIB_PATH}:$LD_LIBRARY_PATH
export LIBRARY_PATH=${CURL_LIB_PATH}:$LIBRARY_PATH
export C_INCLUDE_PATH=${CURL_INCLUDE_PATH}:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=${CURL_INCLUDE_PATH}:$CPLUS_INCLUDE_PATH
export PKG_CONFIG_PATH=/home/guochenxu/soft/curl/lib/pkgconfig/:$PKG_CONFIG_PATH
export OPENSSL_LIB_PATH=/home/guochenxu/soft/openssl/lib64/
export OPENSSL_INCLUDE_PATH=/home/guochenxu/soft/openssl/include/
export LD_LIBRARY_PATH=${OPENSSL_LIB_PATH}:$LD_LIBRARY_PATH
export LIBRARY_PATH=${OPENSSL_LIB_PATH}:$LIBRARY_PATH
export C_INCLUDE_PATH=${OPENSSL_INCLUDE_PATH}:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=${OPENSSL_INCLUDE_PATH}:$CPLUS_INCLUDE_PATH
export PKG_CONFIG_PATH=/home/guochenxu/soft/openssl/lib64/pkgconfig/:$PKG_CONFIG_PATH
export NCURSES_LIB_PATH=/home/guochenxu/soft/ncurses/lib/
export NCURSES_INCLUDE_PATH=/home/guochenxu/soft/ncurses/include/
export LD_LIBRARY_PATH=${NCURSES_LIB_PATH}:$LD_LIBRARY_PATH
export LIBRARY_PATH=${NCURSES_LIB_PATH}:$LIBRARY_PATH
export C_INCLUDE_PATH=${NCURSES_INCLUDE_PATH}:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=${NCURSES_INCLUDE_PATH}:$CPLUS_INCLUDE_PATH
export JEMALLOC_LIB_PATH=/home/guochenxu/soft/jemalloc/lib/
export JEMALLOC_INCLUDE_PATH=/home/guochenxu/soft/jemalloc/include/
export LD_PRELOAD=${JEMALLOC_LIB_PATH}/libjemalloc.so:$LD_PRELOAD
export LD_LIBRARY_PATH=${JEMALLOC_LIB_PATH}:$LD_LIBRARY_PATH
export LIBRARY_PATH=${JEMALLOC_LIB_PATH}:$LIBRARY_PATH
export C_INCLUDE_PATH=${JEMALLOC_INCLUDE_PATH}:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=${JEMALLOC_INCLUDE_PATH}:$CPLUS_INCLUDE_PATH
运行 source ~/.bashrc
让配置的环境变量生效
获取 gstore
在这里 获取 gstore 并进入 gstore 目录
实测上面 github 中的代码有问题 (至少我用了各种方法都没有安装成功), 最后是直接向北大王选实验室 发邮件获取到最新版 (v1.2) 的 gstore 才安装成功
cd gstore
先改一个 bug, 在 makefile
文件的第 59 行加一个 -lncurse
参数, 修改完以后应该是这样:
library = -L/usr/lib64 -L./lib -L/usr/local/lib -L/usr/lib -I/usr/local/include/boost -ljemalloc -lreadline -lncurses -lantlr4-runtime -lgcov -lboost_thread -lboost_system -lboost_regex -lpthread -lcurl -llog4cplus
然后开始编译
# 以下命令可以通过 -j4 加速
make pre # 等待漫长的时候后, 如果没有报错的话就是成功了
make # 若编译顺利完成,最后会出现 Compilation ends successfully! 结果
创建数据库
数据集从这里 下载
在 gstore 根目录下执行
./bin/gbuild -db dbname -f filename
参数含义:
dbname:数据库名称
filename:数据集文件名称
例如:
./bin/gbuild -db CCKS -f /home/guochenxu/CCKS/triple.txt
启动数据库
在 gstore 根目录下执行
./bin/gserver -s
nohup ./bin/ghttp -p 9030 > ghttp.log & #启动 ghttp 服务, 端口号为9030, 并将日志输出到 ghttp.log
启动之后注意看一下日志文件是否启动成功
启动 java 程序
环境配置: java 1.8
数据库配置: GstoreConfiuration 中的配置信息
字段名 | 含义 |
---|---|
IP | 服务器的 ip |
PORT | ghttp 启动的端口号 |
HTTP_TYPE | 连接方式, 此处为ghttp |
USER | 用户名, 默认为 root |
PASSWORD | 密码, 默认为 123456 |
打包并启动:
mvn package
java -jar ./target/gstore-0.0.1-RELEASE.jar
程序执行流程
- 接收请求, 加载数据库, 若加载失败直接返回 null
- 在数据库中进行查询
- 若查询顺利返回格式为解析后的实体
- 若查询超时 (设定定时器为 30 秒), 则返回 null
返回状态码
状态码 | 含义 |
---|---|
200 | 查询正常 |
500 | 数据库连接错误或查询出错 |
1001 | 查询结果为空 |
接口文档可以查看这里