CentOS7安装了MariaDB10以后,无法使用yum安装snmp服务,会提示mariadb-libs与mariadb-common 10的冲突提示。翻墙在谷歌上查到有人说在特定版本的mariadb上fix了这个bug,但是不是全版本通用,所以很麻烦。
最后测试可以通过编译安装snmp解决这个问题。记录如下:
1、准备环境
yum -y installmake gcc gcc-c++ gcc-g77 openssl openssl-devel
2、编译和安装
首先我们需要下载Net-SNMP的源代码,
官方地址:
http://sourceforge.net/projects/net-snmp/files/net-snmp/
下载:net-snmp-5.7.3.tar.gz
接下来对下载的源代码包进行解压缩,
tar xzvfnet-snmp-5.7.3.tar.gz
然后通过configure来生成编译规则,
cdnet-snmp-5.7.3
./configure \
--prefix=/usr/local/snmp \
--with-mib-modules=ucd-snmp/diskio\
--with-default-snmp-version="2" \
--with-sys-contact=Robin \
--with-sys-location="shanghai"\
--with-logfile="/server/snmp/log/snmpd.log"\
--with-persistent-directory="/var/net-snmp"
注意,以上的
--with-mib-modules=ucd-snmp/diskio
选项,可以让服务器支持磁盘I/O监控。
回车出现下面问题,可以直接回车而不用回答,系统会采用默认信息,其中日志文件默认安装在/var/log/snmpd.log.数据存贮目录默认存放在/var/net-snmp下。
配置默认snmp协议版本(1,2c,3),配置为v3版的话,支持登录验证功能,相对来说更安全了
--with-default-snmp-version="2"
配置该设备的联系人信息,也可以是邮箱地址
--with-sys-contact=robin
配置该系统设备的地理位置
--with-sys-location="shanghai"
配置日志文件位置
--with-logfile="/server/snmp/log/snmpd.log"
配置数据存储目录
--with-persistent-directory="/var/net-snmp"
接下来,开始编译和安装:
make&& make install
到现在为止,我们已经有了可以运行的SNMP代理程序,它位于/server/snmp/sbin/snmpd,在启动它之前,我们还要进行一些必要的设置。
当然,路径什么的,可以根据需要调整。
3.创建并配置snmp配置文件
Vi/etc/snmpd/snmpd.conf #创建并编辑snmpd配置文件
代码如下:
###############################################################################
#
# EXAMPLE.conf:
# An example configuration file forconfiguring the ucd-snmp snmpd agent.
#
###############################################################################
#
# This file isintended to only be an example. If,however, you want
# to use it, itshould be placed in /usr/local/net-snmp/etc/snmp/snmpd.conf.
# When the snmpdagent starts up, this is where it will look for it.
#
# You might beinterested in generating your own snmpd.conf file using
# the"snmpconf" program (perl script) instead. It's a nice menu
# based interface towriting well commented configuration files. Try it!
#
# Note: This file isautomatically generated from EXAMPLE.conf.def.
# Do NOT read theEXAMPLE.conf.def file! Instead, after you have run
# configure &make, and then make sure you read the EXAMPLE.conf file
# instead, as itwill tailor itself to your configuration.
# All linesbeginning with a '#' are comments and are intended for you
# to read. All other lines are configuration commandsfor the agent.
#
# PLEASE: read thesnmpd.conf(5) manual page as well!
#
###############################################################################
# Access Control
###############################################################################
# YOU SHOULD CHANGETHE "COMMUNITY" TOKEN BELOW TO A NEW KEYWORD ONLY
# KNOWN AT YOURSITE. YOU *MUST* CHANGE THE NETWORKTOKEN BELOW TO
# SOMETHINGREFLECTING YOUR LOCAL NETWORK ADDRESS SPACE.
# By far, the mostcommon question I get about the agent is "why won't
# it work?",when really it should be "how do I configure the agent to
# allow me to accessit?"
#
# By default, theagent responds to the "public" community for read
# only access, ifrun out of the box without any configuration file in
# place. The following examples show you other ways ofconfiguring
# the agent so thatyou can change the community names, and give
# yourself writeaccess as well.
#
# The followinglines change the access permissions of the agent so
# that the COMMUNITYstring provides read-only access to your entire
# NETWORK (EG:10.10.10.0/24), and read/write access to only the
# localhost(127.0.0.1, not its real ipaddress).
#
# For moreinformation, read the FAQ as well as the snmpd.conf(5)
# manual page.
####
# First, map thecommunity name (COMMUNITY) into a security name
# (local andmynetwork, depending on where the request is coming
# from):
# sec.name source community
#com2sec mynetwork 127.0.0.1 public
com2sec mynetwork default public
#com2sec mynetwork 60.195.252.107 public
#com2sec mynetwork 60.195.252.110 public
####
# Second, map thesecurity name into a group name:
# groupName securityModel securityName
#group notConfigGroup v1 notConfigUser
#group notConfigGroup v2c notConfigUser
group my_group v1 mynetwork
group my_group v2c mynetwork
####
# Third, create aview for us to let the group have rights to:
# Make at least snmpwalk -v 1 localhost -c public system fastagain.
# name incl/excl subtree mask(optional)
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
view all included .1 80
####
# Finally, grant thegroup read-only access to the systemview view.
# group context sec.model sec.level prefixread write notif
#access notConfigGroup "" any noauth exact systemview none none
access my_group "" any noauth exact all none none
#-----------------------------------------------------------------------------
4.创建snmp服务
进入源码目录,如/usr/local/src/net-snmp-5.7.3目录,将启动配置文件范例复制到/etc/init.d/目录:
cp/usr/local/src/net-snmp-5.7.3/dist/snmpd-init.d /etc/init.d/snmpd
修改/etc/init.d/snmpd文件
将其中的
vi /etc/init.d/snmpd
prog="/usr/local/sbin/snmpd"
修改为
prog="/usr/local/snmp/sbin/snmpd"
将其中的
[ -x $prog -a -f/usr/local/share/snmp/snmpd.conf ] || exit 0
修改为
[ -x $prog -a -f/etc/snmp/snmpd.conf ] || exit 0
groupaddsnmp #添加apache用户组及用户
useradd -g snmp -s/usr/sbin/nologin apache
chown -R snmp:snmp/usr/local/apache2
chmod +x/etc/init.d/snmpd
chkconfig--add snmpd #增加执行权限
chkconfig--level 2345 snmpd on #设置开机启动
chkconfig--list snmpd #查看是否设置成功
snmpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
5.配置snmpd服务启动
systemctlenable snmpd #设置开机启动
systemctlstart snmpd #启动snmpd服务
其他的不多说了