20150206

Установка и настройка связки Rancid+ViewVC

Статья переехала -> https://mykb.ru/doku.php?id=topic:rancid


Rancid
-- Доставляем необходимые пакеты
# yum install cvs expect gcc MySQL-python telnet

-- Скачиваем и распаковываем свежую версию Rancid.
# wget ftp://ftp.shrubbery.net/pub/rancid/rancid-3.1.tar.gz
# tar -zxvf rancid-3.1.tar.gz

-- Добавляем группу netadm в которую впоследствии будет добавлен пользователь apache.
# groupadd netadm

-- Создаем пользователя rancid и задаем ему пароль.
# useradd -g netadm -d /home/rancid rancid
# passwd rancid

-- Компилируем и устанавлваем rancid.
# pwd
/root/src/rancid-3.1

# ./configure --prefix=/home/rancid
# make install

-- Копируем файл в котором будут содержаться пароли от сетевого оборудования и выставляем права.
# cp /root/src/rancid-3.1/cloginrc.sample /home/rancid/.cloginrc
# chmod 0640 /home/rancid/.cloginrc
# chown -R rancid:netadm /home/rancid/
# chmod 770 /home/rancid/

-- В файле rancid.conf определяем группы сетевого оборудование.
# su - rancid
$ cp ~/etc/rancid.conf ~/etc/rancid.conf.orig
$ joe ~/etc/rancid.conf
...
# list of rancid groups
#LIST_OF_GROUPS="sl joebobisp"
# more groups...
#LIST_OF_GROUPS="$LIST_OF_GROUPS noc billybobisp"
LIST_OF_GROUPS="cisco juniper"
#
...

-- Создаем CVS репозиторий для ранее определенных групп.
$ /home/rancid/bin/rancid-cvs

-- Прописываем оборудование с которых будем снимать конфигурацию.
$ joe ~/var/juniper/router.db
...
srx-test;juniper;up

...
## Обращаем внимание, что в версиях rancid после 3.x в качестве разделителя используется ";".

-- Задаем пользователя, пароль и ip адрес для захода на сетевое оборудование
$ joe ~/.cloginrc
...
add method srx-test ssh
add user srx-test srx-user
add password srx-test srx-passwd
...

# joe /etc/hosts
...
x.x.x.x    srx-test
...

-- Вручную запускаем rancid (от пользователя rancid) и проверяем, что конфигурация снялась.
$ rancid-run -r srx-test
$ ll ~/var/juniper/configs/
total 484
drwxr-x---. 2 rancid netadm   4096 Feb  30 23:59 CVS
-rw-r-----  1 rancid netadm 488712 Feb  30 23:59 srx-test

-- Пишем правило cron для rancid.
$ crontab -e
...
# #############################################
# Crontab for rancid on myserver
# #############################################
# Hourly Check
1 * * * * /home/rancid/bin/rancid-run

# Daily Clean Up of Diff Files at 11 50 pm
50 23 * * * /usr/bin/find /home/rancid/var/logs -type f -mtime +2 -exec rm {} \;

# Daily Clean Up of .SITE.run.lock Files at 11 50 pm
50 23 * * * rm /tmp/.*.lock
...

###
### Написать про почту
###

ViewVC
-- Скачиваем и распаковываем свежую версию ViewVC.
# wget http://viewvc.tigris.org/files/documents/3330/49392/viewvc-1.1.23.tar.gz
# tar zxvf viewvc-1.1.23.tar.gz

-- Устанавливаем viewvc.
# cd viewvc-1.1.23
# ./viewvc-install
...
ViewVC file installation complete.

Consult the INSTALL document for detailed information on completing the
installation and configuration of ViewVC on your system.  Here's a brief
overview of the remaining steps:

  1) Edit the /usr/local/viewvc-1.1.23/viewvc.conf file.

  2) Either configure an existing web server to run
     /usr/local/viewvc-1.1.23/bin/cgi/viewvc.cgi.
     
     Or, copy /usr/local/viewvc-1.1.23/bin/cgi/viewvc.cgi to an
     already-configured cgi-bin directory.
     
     Or, use the standalone server provided by this distribution at
     /usr/local/viewvc-1.1.23/bin/standalone.py.
...

-- Настраиваем viewvc для работы с CVS репозиторием.
# cd /usr/local/viewvc-1.1.23/
# joe viewvc.conf
...
## Example:
## cvs_roots = cvsroot: /opt/cvs/repos1,
##             anotherroot: /usr/local/cvs/repos2
##
#cvs_roots =

cvs_roots = cvsroot: /home/rancid/var/CVS 
...
## Example:
## root_parents = /opt/svn: svn,
##                /opt/cvs: cvs
##
#root_parents =

root_parents = /home/rancid/var/CVS : cvs
...
## Example:
## rcs_dir = /usr/bin/
##
#rcs_dir =

rcs_dir = /usr/local/bin
...
## use_rcsparse: Use the rcsparse Python module to retrieve CVS
## repository information instead of invoking rcs utilities [EXPERIMENTAL]
##
use_rcsparse = 1
...

-- Копируем файлы query.cgi и viewvc.cgi в рабочую папку веб-сервера.
# cp /usr/local/viewvc-1.1.23/bin/cgi/*.cgi /var/www/cgi-bin
# ll /var/www/cgi-bin
total 8
-rwxr-xr-x. 1 root root 1782 Feb 30 23:59 query.cgi
-rwxr-xr-x. 1 root root 1781 Feb 30 21:59 viewvc.cgi

-- Правим /etc/https/conf.d/vhosts.conf
# joe /etc/https/conf.d/vhosts.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>
...

-- Добавляем пользователя apache в группу netadm.
# joe /etc/group
...
netadm:x:5000:apache
...

-- Создаем mysql базу данных и пользователей.
# mysql -u root -p
mysql> create database viewvc_db;
mysql> create user 'viewvc_user'@'localhost' identified by 'pass1';
mysql> grant all privileges on viewvc_db.* to 'viewvc_user'@'localhost' with grant option;
mysql> create user 'viewvc_rouser'@'localhost' identified by 'pass2';
mysql> grant all privileges on viewvc_db.* to 'viewvc_rouser'@'localhost' with grant option;
mysql> flush privileges;

-- Создаем структуру базы данных viewvc_db.
# cd /usr/local/viewvc-1.1.23/bin/
# ./make-database
./make-database:20: DeprecationWarning: The popen2 module is deprecated.  Use the subprocess module.
  import popen2
MySQL Hostname (leave blank for default): 
MySQL Port (leave blank for default): 
MySQL User: viewvc_user
MySQL Password: pass1
ViewVC Database Name [default: ViewVC]: viewvc_db

Database created successfully.  Don't forget to configure the 
[cvsdb] section of your viewvc.conf file.

-- Настраиваем viewvc для работы с mysql.
# joe /usr/local/viewvc-1.1.23/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_db

## user: Username of user with read/write privileges to the database
## specified by the 'database_name' configuration option.
##
user = viewvc_user

## passwd: Password of user with read/write privileges to the database
## specified by the 'database_name' configuration option.
##
passwd = pass1

## readonly_user: Username of user with read privileges to the database
## specified by the 'database_name' configuration option.
##
readonly_user = viewvc_rouser

## readonly_passwd: Password of user with read privileges to the database
## specified by the 'database_name' configuration option.
##
readonly_passwd = pass2
...

-- Заполняем базу данных. 
# cd /usr/local/viewvc-1.1.23/bin/
# ./cvsdbadmin rebuild /home/rancid/var/CVS/CVSROOT/
Using repository root `/home/rancid/var/CVS'
Purging existing data for repository root `/home/rancid/var/CVS'
[CVSROOT/loginfo [0 commits]]
[CVSROOT/editinfo [0 commits]]
[CVSROOT/config [0 commits]]
[CVSROOT/notify [0 commits]]
[CVSROOT/verifymsg [0 commits]]
[CVSROOT/cvswrappers [0 commits]]
[CVSROOT/rcsinfo [0 commits]]
[CVSROOT/modules [0 commits]]
[CVSROOT/commitinfo [0 commits]]
[CVSROOT/checkoutlist [0 commits]]
[CVSROOT/taginfo [0 commits]]

-- Пробуем зайти на веб-интерфейс
http://x.x.x.x/viewvc

Все должно быть хорошо.

## Нормальной работе мне мешал selinux, в чем проблема не разбирался, просто отключил.

###
###Написать про https и пароли
checking Socket.pm version... Socket version 2.006 required--this is only version 1.82 at -e line 1.
BEGIN failed--compilation aborted at -e line 1.
configure: error: Socket.pm is older than 2.006; upgrade from http://metacpan.org/pod/Socket

cpan App::cpanminus
cpanm Socket



###

--- 

При написании заметки использовались материалы:
http://www.cj-gerow.com/ceg/?p=1900
http://ciscoskills.net/2015/01/03/install-rancid-and-viewvc-on-centos-7/

Комментариев нет:

Отправить комментарий