Rhel7.8编译安装suricata

发布时间 2023-04-17 13:42:24作者: 凉城旧巷

Rhel7.8编译安装suricata

1、安装依赖

yum install -y libpcap-devel libnet-devel pcre-devel gcc-c++ automake autoconf libtool make libyaml-devel zlib-devel file-devel jansson-devel nss-devel lua-devel 
yum install -y rustc cargo python3 git

 

2、下载suricata源码

下载链接:https://github.com/OISF/suricata/tags

 

3、安装suricata-6.0.0

1 [root@localhost 16:21 /<path>]# tar -zxvf suricata-6.0.0.tar.gz
2 [root@localhost 16:22 /<path>]# cd suricata-6.0.0/
3 [root@localhost 16:23 /<path>/suricata-suricata-6.0.0]# ./autogen.sh   # 原生没有configure,需要该脚本来生成configure
4 [root@localhost 16:24 /<path>/suricata-suricata-6.0.0]# ./configure --disable-gccmarch-native --localstatedir=/var --prefix=/usr/ --sysconfdir=/etc --enable-lua --enable-geoip
# --localstatedir 指定日志保存位置
# --prefix 指定安装位置
# --sysconfdir 指定配置文件保存位置


##### 如果报出一下错误,根据提示,在当前目录下执行git clone https://github.com/OISF/libhtp,并重新执行./autogen.sh
##########################################################################################
#ERROR: Libhtp is not bundled. Get libhtp by doing:
#	git clone https://github.com/OISF/libhtp
#Then re-run Suricata's autogen.sh and configure script.
#Or, if libhtp is installed in a different location,
#pass --enable-non-bundled-htp to Suricata's configure script.
#Add --with-libhtp-includes=<dir> and --with-libhtp-libraries=<dir> if
#libhtp is not installed in the include and library paths.
##########################################################################################
# 5、6用以解决LibHtp的报错
5 [root@localhost 16:27 /<path>/suricata-suricata-6.0.0]# git clone https://github.com/OISF/libhtp
6 [root@localhost 16:28 /<path>/suricata-suricata-6.0.0]# ./autogen.sh


# 再次执行configure
7 [root@localhost 16:29 /<path>/suricata-suricata-6.0.0]# ./configure --disable-gccmarch-native --localstatedir=/var --prefix=/usr/ --sysconfdir=/etc --enable-lua --enable-geoip


# 后续报错,缺什么依赖包,根据提示安装什么依赖包


###################### 如果抛出以下错误,根据提示安装cbindgen,并加到PATH中 ######################
##########################################################################################
#Warning: cbindgen too old or not found, it is required to 
#      generate header files.
#  To install: cargo install --force cbindgen
#configure: error: cbindgen required
##########################################################################################

8 [root@localhost 16:30 /<path>/suricata-suricata-6.0.0]# cargo install --force cbindgen   # 该步骤需要联网
9 [root@localhost 16:40 /<path>/suricata-suricata-6.0.0]# export PATH=/root/.cargo/bin:$PATH


# 再次执行configure

# 编译安装
11 [root@localhost 16:45 /<path>/suricata-suricata-6.0.0]# make -j 4 && make install


# 拷贝htp的库到lib中,直接cp或者 ln软链接都可以
12 [root@localhost 17:45 /<path>/suricata-suricata-6.0.0]# cp -d libhtp/htp/.libs/libhtp.so* /lib64/
12 [root@localhost 17:45 /<path>/suricata-suricata-6.0.0]# cp -d libhtp/htp/.libs/libhtp.so* /lib64/
########################### 如果不执行该步骤,在执行suricata命令时会报以下错误######################################
# [root@localhost ~]# suricata
# suricata: error while loading shared libraries: libhtp.so.2: cannot open shared object file: No such file or directory
############################################################################################################ 


# 生成conf目录、log目录等目录
13 [root@localhost 17:47 /<path>/suricata-suricata-6.0.0]# make install-conf
#install -d "/etc/suricata/"
#install -d "/var/log/suricata/files"
#install -d "/var/log/suricata/certs"
#install -d "/var/run/"
#install -m 770 -d "/var/run/suricata"

 

5、生成规则文件

  • suricata-6.0.0引擎程序和规则是分开来安装的,因此需要单独安装suricata-update程序进行规则的安装。由于该程序是python写的,因此linux环境最好支持python同时安装pip工具
  • 安装完suricata-update,直接运行该程序,则会到指定的网站下载rules,下载到/var/lib/suricata/rules/
yum -y install epel-release
yum -y install python3-pip   # 由于在安装依赖时已经安装python3,所以可以忽略此步
pip3 install --upgrade pip   # 升级pip

# 安装suricata-update
pip3 install --upgrade suricata-update
# 执行,下载规则文件,会自动下载到/var/lib/suricata/rules中,执行该步骤后,不需要再执行make install-rules
suricate-update


# 修改/etc/suricata/suricata.yaml文件,将default-rule-path修改为/var/lib/suricata/rules
# 一定要修改,因为默认使用/etc/suricata/rules作为规则目录


# 简单测试suricata
suricata -T

 

6、测试suricata

suricata -c /etc/suricata/suricata.yaml -i ens161