社工库搭建
- 网络安全
- 2017-02-21
社工库想必大家伙都懂!
一、技术选型
Elasticsearch + javaWeb
社工库主要用来检索用户数据,数据量一般在数十亿甚至数百亿,只有写入(导入)和查询,写入次数少,查询次数多,频率高。
与数据库比起来,es支持的数据量更大,更方便水平扩展,天生高可用,检索更快(实际测试5亿数据毫秒级响应),各原始数据的导入更方便。
对于前端交互用java或者python或者php本质上没有多少区别,比较社工库的用户量不大,前端开发工作量也不大。
二、系统搭建
1.硬件
磁盘1T 内存16G * 3
2.软件
centos6.5 + jdk1.8 + elasticsearch2.3.3
3.elasticsearch集群配置
node1
cluster.name: sgk node.name: node33 node.attr.cluster: true network.host: 172.22.1.33 discovery.zen.minimum_master_nodes: 2 discovery.zen.ping.unicast.hosts: ["172.1.1.33","172.1.1.21","172.1.1.44"]
node2和node3
cluster.name: sgk node.name: node22 network.host: 172.1.1.22 discovery.zen.minimum_master_nodes: 2 discovery.zen.ping.unicast.hosts: ["172.1.1.33","172.1.1.21","172.1.1.44"]
插件安装
./bin/plugin install mobz/elasticsearch-head
4.数据导入
社工库的原始数据,一般是mysql、mssql数据库备份数据,或者是大文本文件。
a.文本数据,通过python读文本,使用es库写索引
b.数据库备份文件,首先还原到对应数据库中,然后通过elasticsearch-jdbc或logstash写索引
bin=/root/elasticsearch-jdbc-2.3.3.1/bin lib=/root/elasticsearch-jdbc-2.3.3.1/lib echo '{ "type" : "jdbc", "jdbc": { "url":"jdbc:sqlserver://111.111.111.111:1433;databaseName=new", "user":"sa", "password":"111111", "sql": "select * from sgk", "index" : "user-index", "type" : "user", "elasticsearch" : { "cluster" : "eagleeye", "host" : "172.22.1.33", "port" : 9300 }, "index_settings" : { "index" : { "number_of_shards" : 3, "number_of_replica" : 1 } } } }' | java \ -cp "${lib}/*" \ -Dlog4j.configurationFile=${bin}/log4j2.xml \ org.xbib.tools.Runner \ org.xbib.tools.JDBCImporter
三、数据检索
完成步骤二后,访问“http://172.1.1.33:9200/_plugin/head/”
head插件提供了基础的数据查询,状态展示等功能,基础的社工库功能已实现。
在对外提供服务时,设计页面,完成elasticsearch查询接口实现。