CentOS6.x SNMPv2 详细配置与获取SNMP数据

CentOS6.x SNMPv2 详细配置与获取SNMP数据
简单网络管理协议(SNMP) Simple Network Manage Protocol 使用UDP协议,端口号161、162
snmpd 占用161号端口
snmptrapd 占用162号端口

SNMP共有三个版本
SNMPv1
SNMPv2c ,community (SNMPv2u ,user)
SNMPv3

MIB数据库http://a.hiphotos.baidu.com/baike/c0%3Dbaike116%2C5%2C5%2C116%2C38/sign=e53d3b44f1deb48fef64a98c9176514c/810a19d8bc3eb1352b3d169ea41ea8d3fd1f4418.jpg
SNMP协议使用MIB数据库保存数据信息
MIB使用树状结构组织管理数据
MIB使用OID定位数据

OID:.1.3.6.1.2.1.1 #从上到下,.0代表所包含的元素


GET 获取数据
GET NEXT 获取下一个
GET BULK 获取大量数据
SET 设置数据信息,可以修改主机名等待

监控设备 被监控设备

TRAPS 反馈给监控设备
INFORM 反馈给监控设备,监控设备会发送接收完毕的反馈信息
RESPONSE

安装 net-snmp
yum -y install net-snmp net-snmp-devel net-snmp-libs net-snmp-utils
或者
yum install -y net-snmp*

cd /etc/snmp/
[root@vultr snmp]# ls
snmpd.conf snmptrapd.conf snmptt.conf snmptt.ini
161端口 162端口

service snmpd restart #启动net-snmp
netstat -tulpn TCP、UDP、programs、listenin、numeric #查看snmpd运行状态已经占有的端口号

udp 0 0 0.0.0.0:161 0.0.0.0:* 30021/snmpd

添加开机启动
chkconfig --list | grep snmp
snmpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
snmptrapd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
chkconfig snmpd on

/etc/snmp/snmpd.conf #配置文件
community = password

cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bck
vi /etc/snmp/snmpd.conf

# sec.name source community
com2sec yonghuming default mima

# groupName securityModel securityName
group yonghuzu v2c yonghuming

# Finally, grant the group read-only access to the systemview view.

# group context sec.model sec.level prefix read write notif 指定组的权限到一个权限视图
access yonghuzu "" any noauth exact systemview none none

# Make at least snmpwalk -v 1 localhost -c public system fast again. 设置systemview能访问那些权限
# name incl/excl subtree mask(optional)
view systemview included .1.3.6.1.2.1.1
view systemview included .1 #所有都能访问

service snmpd restart #重启snmp服务

-----------

如果需要获取更多的数据,可以把系统视图权限修改为所有权限

access yonghuzu "" any noauth exact systemview none none
修改为
access yonghuzu "" any noauth exact all none none

修改对all的定义
## incl/excl subtree mask
view all included .1 80

service snmpd restart #重启snmp服务

snmpget获取一个指定OID的数据
snmpget -v 2c -c mima 108.61.247.227 1.3.6.1.2.1.1.1.0

snmpwalk获取从一个OID开始后所有的数值
snmpwalk -v 2c -c mima 108.61.247.227 .1

SNMP错误提示
Timeout: No Response from 108.61.247.227.
解决办法:
1 查看密码是否设置正确
2 配置防火墙允许SNMP数据通过
iptables -I INPUT -p udp --dport 161 -j ACCEPT
service iptables save;service iptables restart;

CentOS6.x 更新系统默认Python版本带来的yum异常:File “/usr/bin/yum”, line 30

CentOS6.x 更新系统默认Python版本带来的yum异常:File "/usr/bin/yum", line 30

CentOS6.x 升级Python到 Python3.4.3,并更新系统默认Python版本,当使用yum安装或升级软件的时候提示下列错误

#yum update -y
File "/usr/bin/yum", line 30
except KeyboardInterrupt, e:
^
SyntaxError: invalid syntax

错误原因:

这是因为yum采用python作为命令解释器,这可以从/usr/bin/yum文件中第一行#!/usr/bin/python发现。而python版本之间兼容性不太好,使得2.6版本与3.4版本之间存在语法不一致问题。而CentOS 6自带的yum采用的是

python2.6.6,当系统将python升级到3.x后,出现语法解释错误。

解决办法:
修改yum的解释器为旧版本python2.6(如果你没有采用覆盖升级的话)。

#vi /usr/bin/yum
将第一行"#!/usr/bin/python" 改为 "#!/usr/bin/python2.6"即可。

yum_error

yum_error2

CentOS6.x下Python-Pip以及Python-gevent的安装使用

CentOS6.x下Python-Pip以及Python gevent的安装使用
CentOS6.5安装 gevent可以提高服务器的性能

Pip是安装Python包的工具,提供了安装、列举已安装包、升级以及卸载包的功能。Pip 是对easy_install的取代,提供了和easy_install相同的查找包的功能,因此可以使用easy_install安装的包也同样可以使用pip进行安装。
目前有很多Python程序都是可以直接通过Pip来一键安装了,比如众所周知的Django、Markdown、Shadowsocks等。
安装Pip之前必须要先安装setuptools,安装setuptools之前,必须要安装了Python,这之间的安装过程存在依赖关系,缺一不可。
1、检查Python版本
#python --version
CentOS6.5默认安装的Python版本是2.6.6,返回值为:Python 2.6.6
2、安装setuptools
#yum install -y python-setuptools
安装完毕后,easy_install命令就可以使用了。
3、安装pip //pip-8.0.2
#easy_install pip
通过easy_install安装pip是最为简单的方法。pip默认安装到/usr/bin目录下。
4、安装shadowsocks
#pip install shadowsocks
5、安装 gevent
安装 gevent可以提高 Shadowsocks 的性能。CentOS下安装gevent依赖libevent和greenlet。
安装libevent:
#yum install -y libevent

安装greenlet:
#yum groupinstall "Development Tools" -y
#pip install greenlet

安装gevent:
pip install gevent 或者easy_install gevent //error: Setup script exited with error: command 'gcc' failed with exit status 1 可能会报错

简要介绍一下Pip的用法(以安装gevent举例):
1、安装package
pip install gevent

2、列出已安装的packages
pip freeze

3、安装特定版本的package
pip install gevent==1.0.2
pip install gevent>=1.0.2,<=1.0.2

4、升级已安装的package到最新版本
pip install -U gevent

5、卸载已安装的package
pip uninstall gevent

6、查询已安装的package
pip search "gevent"

https://teddysun.com/339.html
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6


CentOS6.x 安装升级Python2.7.x Python3.4.x

CentOS 6, Debian, Ubuntu, CentOS 7, FreeBSD, CoreOS, 进入单用户模式(重新设置root密码),单用户模式修改密码

CentOS 6, Debian, Ubuntu, CentOS 7, FreeBSD, CoreOS, 进入单用户模式(重新设置root密码),单用户模式修改密码
CentOS 6, Debian, Ubuntu, CentOS 7, FreeBSD, CoreOS, 进入单用户模式修改密码

To reset the root password of your server, you will need to boot into single user mode.要重置您的服务器的root密码,您将需要引导进入单用户模式。

Access the Manage section of your server in the customer portal and follow these steps. The option depends on the bootloader version on the machine:

CentOS 6 进入单用户模式修改密码

  1. Click [View Console] to access the console and click the send CTRL+ALT+DEL button on the top right. Alternatively, you can also click [RESTART] to restart the server.
  2. You will see a GRUB boot prompt telling you to press any key - you have only a few seconds to press a key to stop the automated booting process. (If you miss this prompt you will need to restart the VM again)
  3. At the GRUB prompt, type "a" to append to the boot command.
  4. Add the text "single" and press enter.
  5. System will boot and you will see the root prompt. Type "passwd" to change the root-password and then reboot again.

Debian, Ubuntu, CentOS 7 进入单用户模式修改密码

  1. Click [View Console] to access the console and click the send CTRL+ALT+DEL button on the top right. Alternatively, you can also click [RESTART] to restart the server.
  2. As soon as the boot process starts, press ESC to bring up the GRUB boot prompt. You may need to turn the system off from the control panel and then back on to reach the GRUB boot prompt.
  3. You will see a GRUB boot prompt - press "e" to edit the first boot option. (If you do not see the GRUB prompt, you may need to press any key to bring it up before the machine boots)
  4. Find the kernel line (starts with "linux /boot/") and add init="/bin/bash" at the end of the line
  5. Press CTRL-X or F10 to boot.
  6. System will boot and you will see the root prompt. Type "mount -rw -o remount /" and then "passwd" to change the root password and then reboot again.

FreeBSD 进入单用户模式修改密码

The boot menu has an option to boot into single-user mode. Press the key for single user mode (2). At the root prompt, type "passwd" to change the root password and then reboot again.

CoreOS 进入单用户模式修改密码

CoreOS by default uses SSH key authentication. On Vultr, a root user and password are created. If an SSH key is selected when creating the VPS, this SSH key can be used to login as user "core".

It is possible to reset the standard root login by executing "sudo passwd" as user "core". Login as "core" using the SSH key first.

If you lost your SSH key, then you can login as the "core" user by editing the grub loader. Follow these steps:

  1. Click [View Console] to access the console and click the send CTRL+ALT+DEL button on the top right. Alternatively, you can also click [RESTART] to restart the server.
  2. You will see a GRUB boot prompt - press "e" to edit the first boot option. (If you do not see the GRUB prompt, you may need to press any key to bring it up before the machine boots)
  3. At the end of the line that begins with "linux$" add " coreos.autologin=tty1" (no quotes).
  4. Press CTRL-X or F10 to boot. You will be logged in as "core" when the system boots.
  5. Remember to reboot your server after you have reset your login.

完成

CentOS 6.x下安装(RPM和编译)aria2

CentOS 6.x下安装(RPM和编译)aria2
aria2 是一款 Linux 下轻量级的多线程下载工具,支持Http/Https、Ftp、BitTorrent、Metalink协议。
官网地址:http://aria2.sourceforge.net ,首页有简略使用教程(Usage Examples)
repo 里没有 aria2 ,因此需要到 http://pkgs.repoforge.org/aria2/ 去下载 rpm 包安装即可。

CentOS 6.x 32 位下安装
wget -c http://pkgs.repoforge.org/aria2/aria2-1.16.4-1.el6.rf.i686.rpm
rpm -ivh aria2-1.16.4-1.el6.rf.i686.rpm

CentOS 6.x 64 位下安装
wget -c http://pkgs.repoforge.org/aria2/aria2-1.16.4-1.el6.rf.x86_64.rpm
rpm -ivh aria2-1.16.4-1.el6.rf.x86_64.rpm

在安装过程有可能会出现缺少 libnettle.so.4 的错误提示。
因此需要先到 http://pkgs.repoforge.org/nettle/ 去下载安装 nettle 即可。
CentOS 6.x 32 位下安装
wget -c http://pkgs.repoforge.org/nettle/nettle-2.2-1.el6.rf.i686.rpm
wget -c http://pkgs.repoforge.org/nettle/nettle-devel-2.2-1.el6.rf.i686.rpm
rpm -ivh nettle-2.2-1.el6.rf.i686.rpm
rpm -ivh nettle-devel-2.2-1.el6.rf.i686.rpm

CentOS 6.x 64 位下安装
wget -c http://pkgs.repoforge.org/nettle/nettle-2.2-1.el6.rf.x86_64.rpm
wget -c http://pkgs.repoforge.org/nettle/nettle-devel-2.2-1.el6.rf.x86_64.rpm
rpm -ivh nettle-2.2-1.el6.rf.x86_64.rpm
rpm -ivh nettle-devel-2.2-1.el6.rf.x86_64.rpm

编译安装aria2
wget http://iweb.dl.sourceforge.net/project/aria2/stable/aria2-1.19.0/aria2-1.19.0.tar.gz
tar zxvf aria2-1.19.0.tar.gz
cd aria2-1.19.0
./configure
make
make install

man aria2c //查看 aria2c manual

aria2c http://cachefly.cachefly.net/100mb.test && rm -f 100mb.test
aria2c -c http://a/f.iso ftp://b/f.iso //-c 选项可以断点续传文件
aria2c http://example.org/mylinux.torrent
aria2c 'BitTorrent Magnet URI' -d test/ //-d test/是指明下载文件保存在test目录
aria2c http://example.org/mylinux.metalink
aria2c -i uris.txt //Download URIs found in text file

完成

Red Hat Enterprise Linux7.x(RHEL7.x)更换CentOS YUM源

Red Hat Enterprise Linux7.x(RHEL7.x)更换CentOS YUM源
Red Hat Enterprise Linux7.x(RHEL7.x) change CentOS YUM repository
Red Hat Enterprise Linux 7.1.1503(RHEL 7.1.1503)更换CentOS YUM源
由于RHEL的yum在线更新是收费的,RedHat在没有订阅授权的情况下是不能通过yum下载任何软件的,想使用RHEL系统,还想用yum源来在线安装软件,就需要更换成CentOS YUM源。
#cat /etc/redhat-release //查看版本
Red Hat Enterprise Linux Server release 7.1 (Maipo)

1、删除RHEL原有的yum
rpm -aq|grep yum|xargs rpm -e --nodeps //删除RHEL原有的yum
sudo rpm -ivh http://mirrors.ustc.edu.cn/centos/7.1.1503/os/x86_64/Packages/wget-1.14-10.el7_0.1.x86_64.rpm //安装wget

2、安装CentOS的yum
下载
wget http://mirrors.ustc.edu.cn/centos/7.1.1503/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7.1.1503/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7.1.1503/os/x86_64/Packages/yum-3.4.3-125.el7.centos.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7.1.1503/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-29.el7.noarch.rpm
安装
rpm -ivh python-iniparse-0.4-9.el7.noarch.rpm
rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -ivh yum-3.4.3-125.el7.centos.noarch.rpm yum-plugin-fastestmirror-1.1.31-29.el7.noarch.rpm

3、下载源文件(CentOS 7)
https://lug.ustc.edu.cn/wiki/mirrors/help/centos //下载页面,根据需要进行下载

4、编辑源文件 CentOS-Base.repo

$releasever 替换成相应的版本号
$basearch 替换成想要的系统位数
编辑源文件 CentOS-Base.repo
http://mirrors.ustc.edu.cn/centos/7.1.1503/ //$releasever替换为7.1.1503 $basearch替换为x86_64,建议国内用户使用
http://mirror.vtti.vt.edu/centos/7.1.1503/ //$releasever替换为7.1.1503 $basearch替换为x86_64,建议国外用户使用

5、导入GPG key
sudo rpm --import http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7 //导入GPG key
sudo rpm --import http://mirror.vtti.vt.edu/centos/RPM-GPG-KEY-CentOS-7 //导入GPG key

6、安装扩展源
yum -y install epel-release //安装 Extra Packages for Enterprise Linux (EPEL)
yum clean all //清除YUM缓存
yum makecache //创建YUM缓存
yum repolist all //列出全部repository列表

http://mirrorlist.centos.org/?release=7.1.1503&arch=x86_64&repo=os
发现最适合自己的源
完成

CentOS6.x\Red Hat\Fedora\Linux 安装Wine 1.7.48 桌面运行环境教程

Open Source Software for running Windows applications on other operating systems
Wine (“Wine Is Not an Emulator” 的首字母缩写)是一个能够在多种 POSIX-compliant 操作系统(诸如 Linux,Mac OSX 及 BSD 等)上运行 Windows 应用的兼容层。 Wine 不是像虚拟机或者模拟器一样模仿内部的 Windows 逻辑,而是將 Windows API 调用翻译成为动态的 POSIX 调用,免除了性能和其他一些行为的内存占用,让你能够干净地集合 Windows 应用到你的桌面。
CentOS6.x\Red Hat\Fedora\Linux 安装Wine 1.7.48 桌面运行环境教程
主要分为两种安装方式:
1:yum 安装
2:源码编译安装(32和64位系统分别安装)

事先安装图形界面GNOME

Red Hat / CentOS / Fedora yum 安装

#yum -y install epel-release
#yum clean all //清空YUM缓存
#yum makecache //生成YUM缓存
yum repolist //确认EPEL状态
#yum -y install wine //安装wine
#yum upgrade wine //升级wine

Red Hat / CentOS / Fedora 源码编译 安装
CwntOS 32位系统安装

#yum -y install wget gcc make vim screen bzip2-devel epel-release zlib-devel libxcb-devel
#yum groupinstall "Development tools" -y
#yum clean all //清空YUM缓存
#yum makecache //生成YUM缓存
#yum repolist //确认EPEL状态
#yum -y update
#reboot
#wget http://nchc.dl.sourceforge.net/project/wine/Source/wine-1.7.48.tar.bz2 //下载wine
#tar -jxvf wine-1.7.48.tar.bz2 //解压
#cd wine-1.7.48
#./configure

configure: error: X development files not found. Wine will be built
#yum -y install libX11-devel freetype-devel
#./configure //配置
#make //编译
#make install //安装
#wine xxx.exe //运行32位软件

CentOS 64位系统安装

#yum groupinstall "Development tools" -y
#yum -y install wget gcc make vim screen bzip2-devel epel-release zlib-devel libxcb-devel
#yum -y update
#reboot
#wget http://nchc.dl.sourceforge.net/project/wine/Source/wine-1.7.48.tar.bz2 //下载wine
#tar -jxvf wine-1.7.48.tar.bz2 //解压
#cd wine-1.7.48
#./configure

configure: error: Cannot build a 32-bit program, you need to install 32-bit development libraries.

#./configure --enable-win64 //配置
configure: Finished. Do 'make' to compile Wine.

configure: error: X development files not found. Wine will be built

#yum -y install libX11-devel
#./configure --enable-win64

configure: error: FreeType development files not found. Fonts will not be built.
Use the --without-freetype option if you really want this.
#yum -y install freetype-devel
#./configure --enable-win64
configure: Finished. Do 'make' to compile Wine.
#make //编译
Wine build complete.
#make install //安装
#wine64 xxx.exe //运行64位软件
完成

linux的NetworkManager服务

linux (CentOS)配置IP地址信息,重启后网络配置失效。
经多次查找发现这种是NetworkManager的问题,NetworkManager试图将DHCP中获取的DNS信息写入/etc/resolv.conf,导致原文件被覆盖,
打开/etc/resolv.conf文件 会发现 Crate by networkmanager。

1:在配置文件添加 PEERDNS=no 这个选项可令/etc/resolv.conf 在系统重启后不会被重写,
重新启动后仍任被NetworkManager 重新创建了/etc/resolv.conf,该方法无效。

2:在文件属性中设置i参数避免文件被修改
#chattr +i /etc/resolv.conf

#chattr -i /etc/resolv.conf //如果你要修改此文件,移除i参数
重新启动后仍任被NetworkManager 重新创建了/etc/resolv.conf,该方法无效。

3:关闭该服务。
service NetworkManager stop 临时关闭:
chkconfig NetworkManager off 永久关闭:

关闭后正常

网络管理器最初由 Redhat 公司开发,现在由 GNOME 管理。

为CentOS 6.x安装图形界面GNOME