Cài đặt SNMP trên CentOS 7

Tác giả NetworkEngineer, T.Bảy 10, 2019, 03:07:51 CHIỀU

« Chủ đề trước - Chủ đề tiếp »

0 Thành viên và 2 Khách đang xem chủ đề.

Cài đặt SNMP trên CentOS 7


1. Giới thiệu.

SNMP, hoặc Giao thức quản lý mạng đơn giản, được sử dụng rộng rãi để liên lạc và giám sát các thiết bị mạng, máy chủ và hơn thế nữa, tất cả thông qua IP. Trong trường hợp này, chúng tôi sẽ cài đặt một SNMP agent trên máy chủ CentOS 6.5, cho phép thu thập dữ liệu từ máy chủ của chúng tôi và cung cấp thông tin cho trình quản lý SNMP từ xa.

2. Cài đặt SNMP.

Mã nguồn [Chọn]
yum -y install net-snmp net-snmp-utils
3. Cấu hình SNMP.

Mã nguồn [Chọn]
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig
cat <<'EOF' > /etc/snmp/snmpd.conf

Mã nguồn [Chọn]
###################################################################
#          SNMP configuration - Customzie by Sam KUON             #
###################################################################
# Agent address
agentaddress    udp:161
agentaddress    udp6:161

## Access control
#@@ Firstly, Map the community into a security name
#           sec.name            source                  community
#com2sec    <sec.name>          <monitor_server>        <community_password>
#com2sec6   <sec.name>          <monitor_server_ipv6>   <community_password>
com2sec     AllowSpecific       192.168.50.10           only4spec!
com2sec     AllowAll            192.168.50.10           not4you!

#@@ Secondly, Map the security name into a group
# group.name sec.model               sec.name
#group      <group_name>        <security_mode>         <security_name>
group       SpecificGroup       v2c                     AllowSpecific
group       AllGroup            v2c                     AllowAll

#@@ Thirdly, Create a view to let group have rights to:
#@@ Open up the whole tree for ro, make the RFC 1213 required ones rw.
# Define 'SystemView', which includes everything under .1.3.6.1.2.1.1 (or .1.3.6.1.2.1.25.1)
# Define 'AllView', which includes everything under .1
#           view.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        AllView             included                .1

#@@ Finally, Grant right to group
# Give 'SpecificGroup' read access to objects in the view 'SystemView'
# Give 'AllGroup' read access to objects in the view 'AllView'
#           group.name      context model   level   prefix  read        write   notify
access      SpecificGroup   ""      any     noauth  exact   SystemView  none    none
access      AllGroup        ""      any     noauth  exact   AllView     none    none

## System contact information
#syslocation    <location set>
#syscontact     <contact_info>
syslocation     Infrastructure, PNH, KH
syscontact      Sam KUON, Email:[email protected], Mob: 086231646

## <<<<<<<<<<<<<<<<<<<<<<<<<<<< End of config >>>>>>>>>>>>>>>>>>>>>>>>>>>>#
EOF

4. Cấu hình tường lửa IPTABLES.

Mã nguồn [Chọn]
echo '-A INPUT -m state --state NEW -m udp -p udp --dport 161 -j ACCEPT' >> /etc/sysconfig/iptables.extra
lokkit --custom-rules=ipv4:filter:/etc/sysconfig/iptables.extra

5. Kích hoạt và khởi động dịch vụ SNMP.

Mã nguồn [Chọn]
systemctl enable snmpd
systemctl start snmpd

6. Kiểm tra thử cấu hình của SNMP.

Mã nguồn [Chọn]
snmpwalk -v 2c -c <community> -O e <servername or IP address>
snmpwalk -v 2c -c not4you! -O e 192.168.50.20
snmpwalk -v 2c -c allowfromall! -O e 192.168.50.20

Nếu các bạn thích bài viết này thì hãy chia sẻ và lưu lại nó.