Install Rancid and ViewVC on Centos 7
In this post I want to walk though the steps to install Rancid on CentOS 7 minimal. Rancid is a great tool to help monitor a device configuration for any changes. It also keeps track of them by using CVS (Concurrent Version System) for backups, so you can go back and compare versions or revert to a previous configuration. Rancid supports multiple hardware from Cisco, HP, Dell, Juniper and more. This is all open-source so you can create custom scripts or add commands to really make this a personal repository that fits your company. During this install guide several things are required when we install Rancid, I have tired to make this as simple as possible but its not just a type and watch it install. You have to customize some of the scripts to make Rancid work like it should. Read it though and follow along.
So I'm already assuming that you have CentOS 7 minimal installed, with connection to the internet, and have just the root account with a password. You can pick up the latest CentOS at http://www.centos.org/ Login as the root account and let's update this thing and accept any updates before we do anything else.
yum update
yum install nano wget ftp telnet mariadb-server mariadb perl tcl expect gcc cvs rcs httpd autoconf php-common php-gd php-pear php-pecl-memcache php-mysql php-xml mod_ssl MySQL-python
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
systemctl enable httpd.service systemctl start httpd.service
groupadd netadm
useradd -g netadm -c "Networking Backups" -d /home/rancid rancid
mkdir /home/rancid/tar
cd /home/rancid/tar/
wget ftp://ftp.shrubbery.net/pub/rancid/rancid-3.4.1.tar.gz
tar -zxvf rancid-3.4.1.tar.gz
cd rancid-3.4.1
./configure --prefix=/usr/local/rancid
make install
cp cloginrc.sample /home/rancid/.cloginrc
chmod 0640 /home/rancid/.cloginrc
chown -R rancid:netadm /home/rancid/.cloginrc
chown -R rancid:netadm /usr/local/rancid/
chmod 775 /usr/local/rancid/
nano /usr/local/rancid/etc/rancid.conf
...
# list of rancid groups
LIST_OF_GROUPS="Routers Switches"
# more groups...
#LIST_OF_GROUPS="$LIST_OF_GROUPS noc billybobisp"
#
...
su -rancid
/usr/local/rancid/bin/rancid-cvs
No conflicts created by this import
cvs checkout: Updating Routers
Directory /usr/local/rancid/var/CVS/Routers/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: /usr/local/rancid/var/CVS/Routers/router.db,v
done
Checking in router.db;
/usr/local/rancid/var/CVS/Routers/router.db,v -- router.db
initial revision: 1.1
done
No conflicts created by this import
cvs checkout: Updating Switches
Directory /usr/local/rancid/var/CVS/Switches/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: /usr/local/rancid/var/CVS/Switches/router.db,v
done
Checking in router.db;
/usr/local/rancid/var/CVS/Switches/router.db,v -- router.db
initial revision: 1.1
done
[rancid@rancid ~]$
cd /home/rancid/tar
wget http://viewvc.tigris.org/files/documents/3330/49471/viewvc-1.1.24.tar.gz
tar -zxvf viewvc-1.1.24.tar.gz
cd viewvc-1.1.24 ./viewvc-install
nano /usr/local/viewvc-1.1.24/viewvc.conf
...
## Example:
## cvs_roots = cvsroot: /opt/cvs/repos1,
## anotherroot: /usr/local/cvs/repos2
##
#cvs_roots = cvs:
## svn_roots: Specifies each of the Subversion roots (repositories) on
## your system and assigns names to them. Each root should be given by
...
## Example:
## root_parents = /opt/svn: svn,
## /opt/cvs: cvs
##
root_parents = /usr/local/rancid/var/CVS : cvs
## default_root: This is the name of the default root. Valid names
...
## Example:
## rcs_dir = /usr/bin/
##
rcs_dir = /usr/local/bin
## cvsnt: Location of cvsnt program. ViewVC can use CVSNT (www.cvsnt.org)
...
## use_rcsparse: Use the rcsparse Python module to retrieve CVS
## repository information instead of invoking rcs utilities [EXPERIMENTAL]
##
use_rcsparse = 1
...
cp /usr/local/viewvc-1.1.24/bin/cgi/*.cgi /var/www/cgi-bin
chmod +x /var/www/cgi-bin/*.cgi
chown apache:apache /var/www/cgi-bin/*.cgi
nano /etc/httpd/conf/httpd.conf
# Custom Rancid Config
<VirtualHost *:80>
DocumentRoot /var/www
ScriptAlias /cgi-bin/ "/var/www/cgi-bin"
ScriptAlias /viewvc /var/www/cgi-bin/viewvc.cgi
ScriptAlias /query /var/www/cgi-bin/query.cgi
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
systemctl enable mariadb
systemctl start mariadb
sudo mysql_secure_installation
mysql -u root -p
CREATE USER 'VIEWVC'@'localhost' IDENTIFIED BY 'YourPasswordHere';
GRANT ALL PRIVILEGES ON *.* TO 'VIEWVC'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
quit
/usr/local/viewvc-1.1.24/bin/make-database
MySQL Hostname (leave blank for default):
MySQL Port (leave blank for default):
MySQL User: VIEWVC
MySQL Password: YourPasswordHere
ViewVC Database Name [default: ViewVC]:
Database created successfully. Don't forget to configure the
[cvsdb] section of your viewvc.conf file.
mysql -u root -p
CREATE USER 'VIEWVCRO'@'localhost' IDENTIFIED BY 'YourROPasswordHere';
GRANT SELECT ON ViewVC.* TO 'VIEWVCRO'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
quit
nano /usr/local/viewvc-1.1.24/viewvc.conf
##---------------------------------------------------------------------------
[cvsdb]
## enabled: Enable database integration feature.
##
enabled = 1
## host: Database hostname. Leave unset to use a local Unix socket
## connection.
##
host = localhost
## post: Database listening port.
##
port = 3306
## database_name: ViewVC database name.
##
database_name = ViewVC
## user: Username of user with read/write privileges to the database
## specified by the 'database_name' configuration option.
##
user = VIEWVC
## passwd: Password of user with read/write privileges to the database
## specified by the 'database_name' configuration option.
##
passwd = YourPasswordHere
## readonly_user: Username of user with read privileges to the database
## specified by the 'database_name' configuration option.
##
readonly_user = VIEWVCRO
## readonly_passwd: Password of user with read privileges to the database
## specified by the 'database_name' configuration option.
##
readonly_passwd = YourROPasswordHere
/usr/local/viewvc-1.1.24/bin/cvsdbadmin rebuild /usr/local/rancid/var/CVS/CVSROOT/

If you see the groups that we created we looking good so far. To finish this installation off we need to setup Rancid to send emails. Usually you have to add the Rancid to the allowed senders list on your email infrastructure. Rancid uses aliases to send emails we need to edit the aliases file.
nano /etc/aliases
# Custom Rancid Configuration (Put an Email Here)
rancid: emailaddress@goeshere.com
# Custom Rancid Configuration
rancid-admin-Routers: rancid
rancid-Routers: rancid
rancid-admin-Switches: rancid
rancid-Switches: rancid
newaliases
nano /etc/postfix/main.cf
relayhost = mycompanydomain.com
relayhost = email.mycompanydomain.com
#relayhost = [mailserver.isp.tld]
#relayhost = uucphost
#relayhost = [an.ip.add.ress]
systemctl start postfix
systemctl enable postfix