How to Install and Configure RANCID v2.3.8 on CentOS 6.x with CVSWeb

RANCID (Really Awesome New Cisco confIg Differ) is a software created by Shubbery Networks Inc. that monitors network device configs for changes and saves all information in a CVS or Subversion system for backups.
RANCID can be found at
http://www.shrubbery.net/rancid/
The reason why we use v2.3.8 is because some device types are not compatible with rancid v3.0+.
From the Rancid 3.0 Release Notes
Not all of the device types have been converted to libraries yet, just
the prominent ones or those prominent to us: Cisco, Juniper, Compass,
Arbor, MRV.  We also still have suggestions from users about this new
process to consider and/or implement.

Install Pre-requisites

  • Download  specific version of RANCID from shrubbery.net – ftp://ftp.shrubbery.net/pub/rancid/rancid-2.3.8.tar.gz
  • expect >= 5.40, gcc, make, cvs, wget

1. Install and Configure

  • Download rancid-2.3.8.tar.gz to your home folder wget ftp://ftp.shrubbery.net/pub/rancid/rancid-2.3.8.tar.gz ~
  • Extract rancid-2.3.8.tar.gz with tar xvf ~/rancid-2.3.8.tar.gz 
  • A folder called rancid-2.3.8 will be created in your home folder containing rancid
  • We will be installing rancid in the /opt folder
  • Go into rancid-2.3.8 folder
  • Preconfigure rancid with ./configure –prefix=/opt/rancid/
  • Compile rancid with make install
  • Copy sample cloginrc to rancid cp cloginrc.sample /opt/rancid/.cloginrc
  • Modify permissions on .cloginrc chmod 0640 /opt/rancid/.cloginrc
  • Change ownership chown -R rancid:netadm /opt/rancid/
  • Modify rancid folder permissions chmod 770 /opt/rancid/

2. Add rancid user and netadm group

  • Create group netadm with groupadd netadm
  • Create user with useradd -g netadm -c “Networking Backups” -d /opt/rancid rancid

3. Configure rancid group and email

  • edit /opt/rancid/etc/rancid.conf, uncomment and edit the following
    • LIST_OF_GROUPS=”networking
  • edit /etc/aliases and add/edit the following
    • rancid-admin-networking: rancid-networking
      rancid-networking: noc
      noc: your@email.com
  • Run newaliases to commit the modified aliases file

4. Turn on CVS Versioning

  • Switch over to the rancid user for this step with su – rancid 
  • Execute /opt/rancid/bin/rancid-cvs to initiate cvs repository
[rancid@rancid-server ~]$ /opt/rancid/bin/rancid-cvs
No conflicts created by this import
cvs checkout: Updating networking
Directory /opt/rancid/var/CVS/networking/configs added to the repository
cvs commit: Examining configs
cvs add: scheduling file `router.db’ for addition
cvs add: use ‘cvs commit’ to add this file permanently
RCS file: /opt/rancid/var/CVS/networking/router.db,v
done
Checking in router.db;
/opt/rancid/var/CVS/networking/router.db,v <– router.db
initial revision: 1.1
done

5. Create Crontab job to poll devices hourly and prune logs daily

  • Run crontab -e under rancid user
  • Add the following to the crontab
0 3 * * * /opt/rancid/bin/rancid-run # daily rancid run
0 1 * * * find /opt/rancid/var/logs -type f -mtime +30 -exec rm {} \; # Prune logs > 30 days at 1am daily

 6. Add a network device to Rancid

  • Modify vi /opt/rancid/var/networking and enter in network device and type
#host:type:status
# make sure you use : instead of ;
192.168.0.100:arista:up
192.168.0.101:force10:up
Device types can be found at http://www.shrubbery.net/rancid/man/router.db.5.html
  • Modify /opt/rancid/.cloginrc and add the following for the device entry above
#Make method SSH only for 192.168.0.100 device
#Remove or comment out ALL other entries in default .cloginrc or it may fail
add method 192.168.0.100 ssh
add user 192.168.0.100 USERNAME
add password 192.168.0.100 PASSWORD ENABLEPASSWORD
  •  Test login by running /opt/rancid/bin/clogin 192.168.0.100

7. Install CVSWeb and Dependencies

  • Do all commands under root
  • Install CVSWeb and Dependencies by running yum install perl-IPC-Run perl-URI rcs httpd -y
  • Download cvsweb by running wget http://people.freebsd.org/~scop/cvsweb/cvsweb-3.0.6.tar.gz ~
  • Extract cvsweb by running tar xvf ~/cvsweb-3.0.6.tar.gz
  • Make cvsweb folder and css folder mkdir -p /usr/local/etc/cvsweb /var/www/html/css/
  • Copy cvsweb files to needed locations and set permissions
cp -a ~/cvsweb-3.0.6/cvsweb.conf /usr/local/etc/cvsweb/
cp -a ~/cvsweb-3.0.6/cvsweb.cgi /var/www/cgi-bin/
cp -a ~/cvsweb-3.0.6/css/cvsweb.css /var/www/html/css/cvsweb.css
chmod 755 /var/www/cgi-bin/cvsweb.cgi
  • Modify cvsweb.conf in /usr/local/etc/cvsweb
[…] @CVSrepositories =
( ‘local’ => [‘Local Repository’, ‘/opt/rancid/var/CVS’], );
[…]
  • Restart apache service httpd restart
  • Add apache user to netadm group useradd -G netadm rancid
  • Add rancid user to netadm group useradd -G netadm rancid
Make sure you open up port 80 on iptables if iptables is on
Visit your webpage by going to: http://your-server-ip/cgi-bin/cvsweb.cgi/

(http://www.richardyau.com/?p=11)
Đọc thêm..

Auto restart server if virtual memory is too low

  1. Check how much memory is left on the VPS.
  2. If 500M memory is left , reboot the VPS.
This could be done as follow
  1. Write a script that checks how much memory is left and reboot the VPS
  2. Add this script to crontab and for automatization
e.g
#!/bin/bash

mem=$(free -m | awk '/Mem:/{print $4}')

(( mem <= 500 )) && reboot
Make the script executable
chmod +x scriptname // note don't add an extension
Add the script to the cron
crontab -e
* * * * * user_to_run_the_script /path/to/the/script
Đọc thêm..

Setup SSMTP để Naigos sử dụng email ID gmail gửi mail alert


Setup SSMTP để Naigos sử dụng email ID gmail gửi mail alert

- Stop dịch vụ smtp mặc định

service sendmail stop   
chkconfig sendmail off
hoặc
service postfix stop   
chkconfig postfix off

- Download và cập nhật database các phần mềm mới

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm

- Cài đặt SSMTP

yum install ssmtp mailx

- Cấu hình ssmtp
+ Edit /etc/ssmtp/ssmtp.conf

FromLineOverride=YES
root=nagios
mailhub=smtp.gmail.com:587
UseTLS=YES
UseSTARTTLS=YES
AuthUser=abc@email.com
AuthPass=<pass plaintext>

- Thay đổi MTA mặc định

alternatives --config mta

*+ 1           /usr/sbin/sendmail.postfix
  2           /usr/sbin/sendmail.ssmtp

Enter to keep the current selection[+], or type selection number:

chọn 2

- Gửi mail test

echo "Testing outgoing email" | mailx -s "Testing" abc@domain.com
Đọc thêm..

Setup Nagios 4x trên Centos 6.5


Setup Nagios 4x trên Centos 6.5
- Cài đặt các gói  packages cần thiết trước khi cài đặt nagios.

#yum install httpd php gcc glibc glibc-common gd gd-devel openssl-devel wget perl make

- Tạo user nagios/password

#useradd -m nagios
#passwd nagios    

- Tạo group nagcmd. Chuyển user nagios và apache vào groups nagcmd

#groupadd nagcmd
#usermod -a -G nagcmd nagios
#usermod -a -G nagcmd apache

- Taọ thư mục tạm để chứa gói cài đặt nagios

#mkdir nagiossource
#cd nagiossource

- Download gói cài đặt nagios và nagios plugins


- Giải nén gói cài đặt nagios

#tar zxvf nagios-4.0.2.tar.gz
#cd nagios-4.0.2

- Cài đặt nagios

#./configure --with-command-group=nagcmd
#make all
#make install
#make install-init
#make install-config
#make install-commandmode
#make install-webconf



- Tạo account nagiosadmin để login vào website

#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

- Khởi động dịch vụ web

#service httpd start

- Cài đặt plugins nagios
#tar zxvf nagios-plugins-1.5.tar.gz
#cd nagios-plugins-1.5
#./configure --with-nagios-user=nagios --with-nagios-group=nagios
#make
#make install

- Cấu hình nagios autostart

#chkconfig --add nagios
#chkconfig nagios on

- Cấu hình Selinux cho nagios

#chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
#chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

- Cấu hình iptables cho phép truy xuất port 80

#vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT


Cấu hình Nagios

- Cấu hình file /usr/local/nagios/etc/nagios.cfg
+ comment các dòng sau:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg



+ Thêm vào các dòng cấu hình sau:
############# Hinh Duong Dan Den Cac File Define ######################
cfg_file=/usr/local/nagios/etc/contacts.cfg
cfg_file=/usr/local/nagios/etc/commands.cfg
cfg_file=/usr/local/nagios/etc/generic-host.cfg
cfg_file=/usr/local/nagios/etc/generic-service.cfg
cfg_file=/usr/local/nagios/etc/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/services.cfg
cfg_file=/usr/local/nagios/etc/timeperiods.cfg
cfg_dir=/usr/local/nagios/etc/servers

- Tạo các file: contacts.cfg, commands.cfg, generic-host.cfg, generic-service.cfg, hostgroups.cfg, services.cfg, timeperiods.cfg (các file nay có file mẫu trong /usr/local/nagios/etc/objects/ )

- Cấu hình server cần giám sát
+ Tạo file /usr/local/nagios/etc/servers/hcm.cfg
############## Server nagios #############
define host{
              use                     generic-host            
        host_name         Nagios-server
     alias                    Nagios Server
       address              IP server
        hostgroups         hcm-servers
}
define host{
              use                     generic-host            
        host_name         Server1-hcm
     alias                    Server1 HCM
       address              IP server
        hostgroups         hcm-servers
}
+ Tạo file /usr/local/nagios/etc/servers/danang.cfg
############## Server nagios #############
define host{
              use                     generic-host            
        host_name         server1-danang
     alias                    Server1 Da Nang
       address              IP server
        hostgroups         danang-servers
}


- Cấu hình file hostgroups.cfg
define hostgroup{
     hostgroup_name         hcm-servers
alias                    HCM Servers
       members                  Nagios-server, win-server
    }

- Cấu hình file servicegroups.cfg
define servicegroup{
     servicegroup_name    ping-services
   alias                    Ping Services
     members                  win-server,PING,Nagios-server,PING
        }


- Các service check trên windows được hỗ trợ bởi Nagios

define service{
use                  generic-service
host_name            remote-windows-host
service_description NSClient++ Version
check_command        check_nt!CLIENTVERSION
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description Uptime
check_command        check_nt!UPTIME
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description CPU Load
check_command        check_nt!CPULOAD!-l 5,80,90
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description Memory Usage
check_command        check_nt!MEMUSE!-w 80 -c 90
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description C:\ Drive Space
check_command        check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description W3SVC
check_command        check_nt!SERVICESTATE!-d SHOWALL -l W3SVC  # check The Internet Information Services (IIS) World Wide Web Publishing Service
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description Explorer
check_command        check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe  # có thể check các dịch vụ khác, thay explorer.exe bằng tên dịch vụ được hiển thị trong task manager
}
Đọc thêm..