RANCID と gitweb で作るコンフィグ履歴管理システム

提供: hkatou_Lab
ナビゲーションに移動 検索に移動

ネットワーク機器のコンフィグの履歴を管理・追跡するソフトウェアとして、遅くとも 2003 年ごろから RANCID が存在しています。

最近の Web を見ていると他の OSS も登場していますが、RANCID + git で構築している例はあまり無いようです。

筆者も 2010 年頃に RANCID + CVS + ViewVC で構築していたのですが、git で新たに構築したので方法を記録しておきます。


うまく構築できると、以下のようにコンフィグ差分をブラウザから確認することができるようになります。

gitweb 差分比較

できること

Cisco を代表とするネットワーク機器のコンフィグを自動で取得し、差分があれば cvs / svn / git リポジトリに記録してくれます。

記録した差分はリポジトリビューアである gitweb により、外部 PC の Web ブラウザから確認できます。

外部の github / gitlab に頼らず単一のサーバで完結するため、OSS 間の相互接続・トラブルシュート・セキュリティをあまり考慮せずに作ることができます。

メリット

デフォルトで様々なメーカーに対応しており、ネットワーク機器側にはログインの設定を行う程度で、特別な設定は必要ありません。

  • ネットワーク機器側で設定の変更を行うだけで、自動的に変更履歴が RANCID のリポジトリに保存されていきます
  • ネットワーク機器の追加は、RANCID にホスト名や IP アドレス、ログイン情報を追加するだけです

RANCID はスクリプトで各機器のコマンドを取得しているため、取得するコマンドをカスタマイズすることもできます。

複数人で構築を行う場合、自動でコンフィグ差分が記録されていくと、障害発生時に追跡しやすく便利です。

  • 構築中は大体その日の事前 / 事後ログくらいしか取らないので、障害に気づかないと日単位でしか記録に残らない


使用する主要なソフトウェア

RANCID
ネットワーク機器で実行するコマンドのスクリプトなどを担当します。
git
通常はソフトウェア開発でバージョン管理に使用します。RANCID では、ネットワーク機器の設定を保存する役割を担います。
httpd (apache)
言わずとしれた Apache Software Foundation のWeb サーバです。
gitweb
httpd (apache) と連携し、git リポジトリの内容を表示します。
cvs / svn の頃に使われた ViewVC に近いです。
crond (cronie)
定期的に処理を行うソフトです。RANCID のスクリプトを定期的に実行します。

RANCID に関連する設定ファイル

/etc/rancid/rancid.conf

一番重要な設定ファイルです。 グループ名や、CVS / SVN / git の指定などを行います。


/var/rancid/.cloginrc

監視対象のネットワーク機器のホスト名や IP アドレス、RANCID からネットワーク機器にログインするためのユーザ名やパスワードなどを保存します。セキュリティ上危険なので、ファイルのアクセス権限に気をつけます。


/var/lib/rancid/<グループ名>/router.db

監視対象のネットワーク機器のホスト名や IP アドレス、動作状況を保存します。


/etc/cron.d/rancid

/etc/aliases

/etc/httpd/conf.d/viewvc.conf

クライアントのブラウザで表示させる際の、Web サーバの設定ファイルです。

RANCID の主なスクリプト

/usr/bin/rancid-cvs

/usr/bin/rancid-run

/usr/libexec/rancid/control_rancid

構築環境

EVE-NG 上に CentOS 8 と CSR1000V を建てて検証環境を構築しています。

CentOS 8 はリンク先のイメージを利用させてもらいました。

起動前に Linux を右クリック Edit から NIC を 4 つ + vnc -> telnet に変更してあります。

RANCID 検証環境


実際のトポロジではルータの配下にサーバが接続されることになるでしょうが、CSR1000V はライセンスなしだとスループットが制限されるため、上記のトポロジへアレンジしています。

構築手順

CentOS の設定

これ以降、

Linux

  • $ は user or rancid ユーザ
  • # はルートユーザでログイン

CSR

  • $ は exec モード
  • # は特権モード

にしていることを示します。

ルートパスワード変更・ルートログイン

上述の Serial Console telnet 対応の CentOS 8 イメージは、user / Test123 でログインできます。


root パスワードを任意に変更します。

Linux
$ sudo passwd root
$ su -

sudo でやっても良いですが、筆者はめんどいので root でやりました。

現用機に構築する際は sudo でやるべきです。

インターフェースの確認と有効化

EVE-NG 上の e3 は CentOS 8 の ens6 になっており、Internet には DHCP で Source NAT される環境と Bridge されています。

筆者と同じように構築するには、EVE-NG の External Connect 設定が必要です。

CentOS 8 の要件としては dnf / yum が実施できないといけないため、

  • ping 8.8.8.8
  • ping www.google.co.jp


で外部疎通と Global な名前解決ができれば良いです。

Linux
# nmcli -t device
# nmcli general status
# nmcli con up id ens6


ちょっと分かりづらいですが、NIC は以下の対応になっています。

NIC の表記対応
NIC1 NIC2 NIC3 NIC4
EVE-NG e0 e1 e2 e3
CenOS 8 ens3 ens4 ens5 ens6


CentOS の参照する DNF リポジトリを修正

CentOS 8 は Stream に移行したため、そのままでは dnf / yum が動作しません。

このため dnf / yum の参照リポジトリを書き換える必要があります。

ここの記事を参考にさせてもらいました。

Linux
# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*


RANCID のインストール

EPEL リポジトリを有効化

RANCID は CentOS の Base リポジトリに入っていません。まずは EPEL リポジトリを追加します。

Linux
# dnf install epel-release

RANCID 関連パッケージをインストール

RANCID / Apache などをインストールします。crond は Minimum でもインストール済みです。

Linux
# dnf install rancid git gitweb httpd telnet mlocate vim glibc-langpack-en
# updatedb


セキュリティ機能の停止

Firewall の確認・停止

検証環境として構築したので、Firewalld は今回止めています。

Linux
# systemctl status firewalld
# systemctl stop firewalld
# systemctl disable firewalld

必要なら適切に設定してください。

SELinux の確認と無効化

検証環境として構築したので、SELinux でも以下略。停止します。

Linux
# cat /etc/selinux/config
# cp -p /etc/selinux/config /etc/selinux/config.`date "+%Y%m%d-%H%M%S"`
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# diff -c /etc/selinux/config.[0-9]* /etc/selinux/config
# reboot

SELinux の設定差分です。

*** /etc/selinux/config.20220916-210032 2020-06-27 09:00:09.058770191 -0400
--- /etc/selinux/config 2022-09-16 21:02:05.016796511 -0400
***************
*** 4,10 ****
  #     enforcing - SELinux security policy is enforced.
  #     permissive - SELinux prints warnings instead of enforcing.
  #     disabled - No SELinux policy is loaded.
! SELINUX=enforcing
  # SELINUXTYPE= can take one of these three values:
  #     targeted - Targeted processes are protected,
  #     minimum - Modification of targeted policy. Only selected processes are protected.
--- 4,10 ----
  #     enforcing - SELinux security policy is enforced.
  #     permissive - SELinux prints warnings instead of enforcing.
  #     disabled - No SELinux policy is loaded.
! SELINUX=disabled
  # SELINUXTYPE= can take one of these three values:
  #     targeted - Targeted processes are protected,
  #     minimum - Modification of targeted policy. Only selected processes are protected.
[root@centos8 ~]#


RANCID の構築 その 1

RANCID ディレクトリの作成と権限変更

root で実施します。

mysql / mariadb などでは /var/lib 配下に DB が保存されるため、RANCID でも倣って作成しました。

Linux
# mkdir -p /var/lib/rancid
# chown rancid:apache /var/lib/rancid

RANCID の設定

rancid.conf を日付付きでバックアップ、編集します。

Linux
# cp -p /etc/rancid/rancid.conf /etc/rancid/rancid.conf.`date "+%Y%m%d-%H%M%S"`
# vi /etc/rancid/rancid.conf
# diff -c /etc/rancid/rancid.conf.`date "+%Y%m%d-%H%M"`* /etc/rancid/rancid.conf

diff コマンドではファイルを日時指定で比較元としていますが、同日に作業していない場合は、適宜ファイル名を変更して実施してください。

行先頭の "!" や "+" は diff コマンドがつけているものなので、設定では記載しないようにしてください。

  • ! = 差分があることを示す
  • + = 追加されたことを示す
  • - = 削除されたことを示す

rancid.conf の変更差分は以下です。

*** /etc/rancid/rancid.conf.20220916-210843     2022-02-07 17:52:49.000000000 -0
--- /etc/rancid/rancid.conf     2022-09-16 21:12:27.710460964 -0400
***************
*** 25,31 ****
  TMPDIR=/tmp; export TMPDIR
  # Be careful changing this, it affects CVSROOT below.  It should be a FQPN, nt
  # relative.
! BASEDIR=/var; export BASEDIR
  PATH=/usr/libexec/rancid:/usr/bin:/usr/sbin:/usr/local/bin; export PATH
  #
  # Check that the effective UID is not root, which could lead to permissions
--- 25,32 ----
  TMPDIR=/tmp; export TMPDIR
  # Be careful changing this, it affects CVSROOT below.  It should be a FQPN, nt
  # relative.
! #BASEDIR=/var; export BASEDIR
! BASEDIR=/var/lib/rancid; export BASEDIR
  PATH=/usr/libexec/rancid:/usr/bin:/usr/sbin:/usr/local/bin; export PATH
  #
  # Check that the effective UID is not root, which could lead to permissions
***************
*** 56,69 ****
  #   - for git, it is likely easiest to leave CVSROOT as a local path, use
  #     rancid-cvs to create the repository for groups, then move those
  #     repositories to the remote and update the group's .git/config.
! CVSROOT=$BASEDIR/CVS; export CVSROOT
  # Location of log files produced by rancid-run(1).
  LOGDIR=$BASEDIR/logs; export LOGDIR
  #
  # Select which RCS system to use, "cvs" (default), "svn" or "git".  Do not
  # change this after CVSROOT has been created with rancid-cvs.  Changing betwen
  # these requires manual conversions.
! RCSSYS=cvs; export RCSSYS
  #
  # if ACLFILTERSEQ is NO, prefix-list/access-list sequence numbers will NOT be
  # filtered.  this option implies ACLSORT=NO for lists with sequence numbers.
--- 57,72 ----
  #   - for git, it is likely easiest to leave CVSROOT as a local path, use
  #     rancid-cvs to create the repository for groups, then move those
  #     repositories to the remote and update the group's .git/config.
! #CVSROOT=$BASEDIR/CVS; export CVSROOt
! CVSROOT=$BASEDIR/GIT; export CVSROOT
  # Location of log files produced by rancid-run(1).
  LOGDIR=$BASEDIR/logs; export LOGDIR
  #
  # Select which RCS system to use, "cvs" (default), "svn" or "git".  Do not
  # change this after CVSROOT has been created with rancid-cvs.  Changing betwen
  # these requires manual conversions.
! #RCSSYS=cvs; export RCSSYS
! RCSSYS=git; export RCSSYS
  #
  # if ACLFILTERSEQ is NO, prefix-list/access-list sequence numbers will NOT be
  # filtered.  this option implies ACLSORT=NO for lists with sequence numbers.
***************
*** 79,84 ****
--- 82,88 ----
  # if NOCOMMSTR is set to YES, snmp community strings will be stripped from the
  # configs.
  #NOCOMMSTR=YES; export NOCOMMSTR
+ NOCOMMSTR=ALL; export NOCOMMSTR
  #
  # FILTER_OSC determines if oscillating data such as keys, passwords, etc are
  # filtered from configs by the value set (NO | YES | ALL).  FILTER_PWDS may
***************
*** 105,110 ****
--- 109,115 ----
  #LIST_OF_GROUPS="sl joebobisp"; export LIST_OF_GROUPS
  # more groups...
  #LIST_OF_GROUPS="$LIST_OF_GROUPS noc billybobisp"; export LIST_OF_GROUPS
+ LIST_OF_GROUPS="TKY"
  #
  # Define an alternate filter for the output of the RCS diff.  The filter
  # should read from stdin and write to stdout.  The default is defined in
[root@centos8 ~]#

各項目の役割は以下のとおりです。

BASEDIR=
RANCID のベースとなるディレクトリ指定します。
CVSROOT=
cvs / svn / git で設定履歴を保存するディレクトリを指定します。
LOGDIR=
RANCID のログを保存するディレクトリを指定します。Fedora や CentOS では /var/log 以下が標準で使用するログのディレクトリなので、変更しても良いでしょう。


以下の設定はセキュリティ上重要な項目です。Cisco 機器などでは設定ファイルからパスワードが解読できるため、RANCID の設定が不適切な場合、パスワードが漏れる可能性があります。

FILTER_PWDS=
ALL を指定することで、ネットワーク機器の設定ファイルの、username <> password <> や、enable secret <> <> などのパスワードを <removed> に置換します。
NOCOMMSTR=
ネットワーク機器の設定ファイルの、snmp-server のコミュニティ名を <removed> に置換します。
LIST_OF_GROUPS=
ネットワーク機器をまとめるグループ名を指定します。ネットワーク機器のメーカー名や、L2_switch や FW などの役割を指定するといいでしょう。筆者の現用環境では拠点をグループとして設定しています。ここでは Tokyo を意味する TKYを指定します。
複数指定する場合は、TKY YKH のようにスペースで区切ります。

英語ですが、詳細な説明は rancid.conf - rancid environment configuration file にあります。man rancid.conf で確認しましょう。

cloginrc のコピー

Linux
# cp -p /usr/share/doc/rancid/cloginrc.sample /var/rancid/.cloginrc
# vi /var/rancid/.cloginrc
# diff -c /usr/share/doc/rancid/cloginrc.sample /var/rancid/.cloginrc

cloginrc は既存の行をコメントアウトして、新規に行を作成します。

*** /usr/share/doc/rancid/cloginrc.sample       2019-05-11 22:29:06.000000000 -0
--- /var/rancid/.cloginrc       2022-09-16 21:17:52.451049484 -0400
***************
*** 86,128 ****
  # customer x
  # these routers ask for a username and password.  we automatically get
  # enable access after successful authentication.
! add user *.custx.net          roger
! add password *.custx.net      {doger}
! add autoenable *.custx.net    1

  # customer y
  # this is the normal cisco login.  a password followed by and enable password.
  # try ssh first, then rlogin.
! add password *.custy.net      {vector}        {victor}
! add method *.custy.net                ssh rlogin

  # customer z; they use ssh only.
! add user *.custz.net          shirley
! add password *.custz.net      {jive}          {surely}
! add method *.custz.net                ssh

  # the route-server's do not provide enable access.  cmdline -noenable
  # equivalent.
! add noenable route-server*    1

  # all our routers, i.e.: everything else
! add password *                        {clearance}     {clarence}

  # set ssh encryption type, dflt: 3des
! add cyphertype *              {3des}

  # set the username prompt to "router login:"
  #add userprompt *             {"router login:"}

  # ssh identity for a juniper; used with jlogin
! add identity  my.juniper      $env(HOME)/.ssh/juniper

  # riverstone / enterasys / cabletron (rivlogin) example
  # these boxes are 'back-to-front' from cisco (i.e., ask
  # for vty password always, then tac+/radius if configured).
  #
  # vty password and last resort (enable) password for rivlogin
! add password rs3000           {vtypass}       {lastresort}
  # if using tac+ or radius login, include these lines
! add user rs3000                       {monster}
! add userpassword rs3000               {scary}
--- 86,134 ----
  # customer x
  # these routers ask for a username and password.  we automatically get
  # enable access after successful authentication.
! #add user *.custx.net         roger
! #add password *.custx.net     {doger}
! #add autoenable *.custx.net   1

  # customer y
  # this is the normal cisco login.  a password followed by and enable password.
  # try ssh first, then rlogin.
! #add password *.custy.net     {vector}        {victor}
! #add method *.custy.net               ssh rlogin

  # customer z; they use ssh only.
! #add user *.custz.net         shirley
! #add password *.custz.net     {jive}          {surely}
! #add method *.custz.net               ssh

  # the route-server's do not provide enable access.  cmdline -noenable
  # equivalent.
! #add noenable route-server*   1

  # all our routers, i.e.: everything else
! #add password *                       {clearance}     {clarence}

  # set ssh encryption type, dflt: 3des
! #add cyphertype *             {3des}

  # set the username prompt to "router login:"
  #add userprompt *             {"router login:"}

  # ssh identity for a juniper; used with jlogin
! #add identity my.juniper      $env(HOME)/.ssh/juniper

  # riverstone / enterasys / cabletron (rivlogin) example
  # these boxes are 'back-to-front' from cisco (i.e., ask
  # for vty password always, then tac+/radius if configured).
  #
  # vty password and last resort (enable) password for rivlogin
! #add password rs3000          {vtypass}       {lastresort}
  # if using tac+ or radius login, include these lines
! #add user rs3000                      {monster}
! #add userpassword rs3000              {scary}
!
! add user        *       user
! add password    *       password      password
! add method      *       telnet
!
!
[root@centos8 ~]#

user を設定しましたが、今回は IOS-XE でユーザ認証を使用していない (vty + enable だけ) ため、使いませんでした。。 ネットワーク機器へ SSH などでログインするように設定したい場合、以下を参考にしてみてください。

# vi /var/rancid/.cloginrc
#ログインパスワードと特権パスワードの例
#+add password <ホスト名> <ログインパスワード> <特権パスワード>

#ログインしたときに自動的に特権、な例
#+add autoenable <ホスト名> 1
#+add password <ホスト名> <パスワード>

#ログインしたときにユーザ名を聞かれるケースで、自動的な特権はナシ
#+add user <ホスト名> <ユーザ名>
#+add autoenable <ホスト名> 0
#+add password <ホスト名> <ログインパスワード> <特権パスワード>

#telnetでなく、 sshを優先させる例
#+add method <ホスト名> {ssh}
#+add user <ホスト名> <ユーザ名>
#+add autoenable <ホスト名> 1
#+add password <ホスト名> <パスワード>

CentOS の CSR1000V 設定

CSR1000V を hosts に登録

IP アドレスでアクセスすると、ホストの役割がわからなかったり IP アドレスを変更した際にリポジトリの一貫性を保つのが難しくなります。ここでは RANCID からホスト名でアクセスさせるようにします。

Linux
# cp -p /etc/hosts /etc/hosts.`date "+%Y%m%d-%H%M%S"`
# vi /etc/hosts
# diff -c /etc/hosts.`date "+%Y%m%d-%H%M"`* /etc/hosts

以下の変更を行いました。

*** /etc/hosts.20220916-213253  2018-09-10 07:51:03.000000000 -0400
--- /etc/hosts  2022-09-16 21:33:45.827406503 -0400
***************
*** 1,2 ****
--- 1,3 ----
  127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
  ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
+ 10.0.0.1    csr1000v
[root@centos8 ~]#

今回は /etc/hosts でローカルで名前解決させましたが、現用環境ではもちろん DNS サーバで名前解決させても良いです。

筆者の現用環境は /etc/hosts でやっています。

実際の環境にはネットワーク機器の管理ポートか、Routing が Failover したときにもアクセスできる Loopback アドレスを指定するほうが良いでしょう。

CSR1000V にログイン・IP アドレス・ホスト名を設定

CSR
# enable
(config)#line vty 0 15
(config-line)#password password
(config-line)#login
(config-line)#transport input telnet
(config-line)#exit
(config)#enable secret password
(config)#interface GigabitEthernet1
(config-if)#ip address 10.0.0.1 255.255.255.0
(config-if)#no shutdown
(config)#hostname csr1000v
(config)#end

CentOS にも e0 / ens3 へ 10.0.0.2/24 を設定し、ping が飛ぶことを確認します。

CentOS から telnet 確認

Linux
# telnet csr1000v
Trying 10.0.0.1...
Connected to 10.0.0.1.
Escape character is '^]'.
User Access Verification
Password:
CSR1000V>ena
CSR1000V>enable
Password:
CSR1000V#
CSR1000V#
CSR1000V#
CSR1000V#exit
Connection closed by foreign host.

RANCID 構築 その 2

RANCID ユーザでリポジトリを作成

RANCID 構築時の一番のハマりポイントは、ここです。

  1. git リポジトリは、git init コマンドなどで作成しないでください RANCID が正常に動作しません RANCID に専用の rancid-cvs コマンドが用意されているため、このコマンドを使用してリポジトリを作成します
  2. rancid にユーザを変更して、専用の rancid-cvs コマンドを使って作成します 他のユーザで作成すると、権限が異なってしまい、正常に作成されません
Linux

ユーザを rancid に変更し、コンフィグを保存する git リポジトリを作成します。

# su - rancid
$ cd /var/lib/rancid/
$ locate rancid-
$ /usr/bin/rancid-cvs

上記の例では、locate コマンドで rancid のスクリプトを index 検索しています。

何も出てこない場合は、root ユーザで updatedb 後に再度実行してみてください。

git リポジトリ作成時のログは以下です。

Initialized empty Git repository in /var/lib/rancid/GIT/TKY/
Cloning into '.'...
warning: You appear to have cloned an empty repository.
done.
[master (root-commit) 224dc87] new
 1 file changed, 3 insertions(+)
 create mode 100644 configs/.gitignore
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Writing objects: 100% (4/4), 258 bytes | 14.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
To /var/lib/rancid/GIT/TKY
 * [new branch]      master -> master
[master 9ab589c] new
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 router.db
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 260 bytes | 12.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To /var/lib/rancid/GIT/TKY
   224dc87..9ab589c  master -> master
   
$ ls -al
total 4
drwxr-xr-x   5 rancid apache   40 Sep 16 21:29 .
drwxr-xr-x. 32 root   root   4096 Sep 16 21:06 ..
drwxr-x---   3 rancid rancid   17 Sep 16 21:29 GIT
drwxr-x---   2 rancid rancid   33 Sep 16 21:29 logs
drwxr-x---   4 rancid rancid  107 Sep 16 21:29 TKY
[rancid@centos8 rancid]$

rancid.conf の LIST_OF_GROUPS、CVSROOT、LOGDIR の内容にそってディレクトリが作成されました。

うまくいかない場合は、/var/lib/rancid の権限や、/etc/rancid/rancid.conf の設定を見直してみると良いでしょう。

RANCID の router.db を変更

router.db を編集して、ホスト名・機器の種類・状態を設定します。

ネットワーク機器のリストを以下の書式で設定します。

<書式>
dns 名 か ip アドレス;デバイスタイプ;ステータス

実際に追加してみます。

Linux
$ cp -p /var/lib/rancid/TKY/router.db.`date "+%Y%m%d-%H%M%S"` /var/lib/rancid/TKY/router.db
$ vi /var/lib/rancid/TKY/router.db
$ diff -c  /var/lib/rancid/TKY/router.db.`date "+%Y%m%d"`* /var/lib/rancid/TKY/router.db

今回の設定は以下を行いました。

*** TKY/router.db.20220916-213118       2022-09-16 21:29:53.035959126 -0400
--- TKY/router.db       2022-09-16 21:34:30.128061058 -0400
***************
*** 0 ****
--- 1 ----
+ csr1000v;cisco;up
[rancid@centos8 rancid]$

router.db は IP アドレスでも DNS 名を指定しても大丈夫です。ここはリポジトリで表示する際のホスト名になるので、分かりやすい名前がよいでしょう。 今回は、DNS 名で設定しています。

ログインテスト

clogin からログインテスト

RANCID は *loginrc というログインスクリプトを使用してログインを行います。c が先頭に付く場合は Cisco を意味しています。

clogin / .cloginrc / hosts ファイルを用いられて、自動でネットワーク機器にログインできるかテストします。

Linux
$ /usr/libexec/rancid/clogin csr1000v
Error: /var/rancid//.cloginrc must not be world readable/writable

.cloginrc の権限が適切でない場合、上記のように失敗します。

root ユーザから .cloginrc 権限変更

.cloginrc はセキュリティ上重要であるため、他ユーザから読めてはいけません。

また、httpd で git ディレクトリとして公開している、/var/lib/rancid とは必ず別のディレクトリに配置するべきです。

この環境では rancid ユーザのホーム ディレクトリに保存しています。

以下のように権限を変更します。

Linux
# chmod 600 /var/rancid//.cloginrc
# chown rancid:rancid /var/rancid//.cloginrc
[root@centos8 rancid]# ls -al /var/rancid//.cloginrc
-rw------- 1 rancid rancid 4073 Sep 16 21:17 /var/rancid//.cloginrc

筆者は Linux セキュリティが素人同然であるため、上記は不適切な例である可能性があります。

rancid ユーザに変更して再テスト

Linux
# su - rancid

$ /usr/libexec/rancid/clogin csr1000v
csr1000v
spawn telnet -K csr1000v
Trying 10.0.0.1...
Connected to csr1000v.
Escape character is '^]'.

User Access Verification

Password:
csr1000v>enable
Password:
csr1000v#
csr1000v#
telnet> quit
Connection closed.
[rancid@centos8 ~]$

Ctrl + ] して telnet プロンプトを呼び出し -> quit で抜けられます。

コンフィグ取得テスト

手動でコンフィグ取得

実際には cron でコンフィグを取得しますが、まずは手動で取得してみます。

Linux
$ rancid-run

/var/lib/rancid/logs/<GROUPS>.YYMMDD.HHMMSS にログが記録されます。以下は csr1000v を初回取得したときのログです。

# cat /var/lib/rancid/logs/TKY.20220916.213939
starting: Fri Sep 16 21:39:39 EDT 2022

/usr/libexec/rancid/control_rancid: line 431: /usr/sbin/sendmail: No such file or directory
[master a1886b6] new router
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 configs/csr1000v
Added csr1000v



Trying to get all of the configs.
All routers successfully completed.

[master 71199e4] updates
 3 files changed, 287 insertions(+)
 create mode 100644 .gitignore
To /var/lib/rancid/GIT/TKY
   9ab589c..71199e4  master -> master
/usr/libexec/rancid/control_rancid: line 722: /usr/sbin/sendmail: No such file or directory

ending: Fri Sep 16 21:45:06 EDT 2022
[root@centos8 rancid]#


自動でコンフィグ取得

2022/09 時点の CentOS 8 + EPEL リポジトリの rancid.x86_64 3.13-3.el8 では、cron の登録が自動で行われます。

Linux
# cat /etc/cron.d/rancid
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/var/rancid
# Run config differ hourly
1 * * * * rancid /usr/libexec/rancid/rancid-run
3 3 * * * rancid /usr/bin/find /var/log/rancid -type f -mtime +30 -exec /usr/bin/rm {} \;
[root@centos8 rancid]#

1 * * * * は 1 時間を表しており、毎時間コンフィグを取得する設定になっています。

保存したネットワーク機器のコンフィグ表示

長いので折りたたみにしてあります。

機器によっては 1h ごとに毎回差分が出てしまうコマンドがデフォルトで RANCID で登録されているため、取得コマンドをアレンジしたほうが良い機器も存在します。

RANCID で取得した csr1000v の最新コンフィグ
cat /var/lib/rancid/TKY/configs/csr1000v
[root@centos8 rancid]# cat /var/lib/rancid/TKY/configs/csr1000v

!RANCID-CONTENT-TYPE: cisco

!

!Chassis type: CSR1000V

!CPU: VXE

!

!Memory: main 2071829K/3075K

!Memory: physical 3978432K

!Memory: nvram 32768K

!

!Processor ID: 9N5KGWYZ34V

!

!Image: Software: X86_64_LINUX_IOSD-UNIVERSALK9-M, 17.3.4a, RELEASE SOFTWARE (fc3)

!Image: Compiled: Tue 20-Jul-21 04:59 by mcpre

!Image: bootflash:packages.conf

!Image: [ R0 ] Active Package(s) Information:

!Image: State (St): I - Inactive, U - Activated & Uncommitted,

!Image:             C - Activated & Committed, D - Deactivated & Uncommitted

!Image: --------------------------------------------------------------------------------

!Image: Type  St   Filename/Version

!Image: --------------------------------------------------------------------------------

!Image: IMG   C    17.03.04a.0.5574

!Image: --------------------------------------------------------------------------------

!Image: Auto abort timer: inactive

!Image: --------------------------------------------------------------------------------

!

!

!BootFlash: BOOT variable does not exist

!BootFlash: CONFIG_FILE variable does not exist

!BootFlash: BOOTLDR variable does not exist

!BootFlash: Configuration register is 0x2102

!

!BootFlash: BOOT variable does not exist

!BootFlash: CONFIG_FILE variable does not exist

!BootFlash: BOOTLDR variable does not exist

!BootFlash: Configuration register is 0x2102

!

! UDI: PID:CSR1000V,SN:9N5KGWYZ34V

!

! Smart Licensing is ENABLED

! Registration:

!   Status: UNREGISTERED

!   Export-Controlled Functionality: NOT ALLOWED

! License Authorization:

!   Status: No Licenses in Use

!   License                 Entitlement Tag

!   ------------------------------------------------------

!   No licenses in use

!

!

!Flash: nvram: Directory of nvram:/

!Flash: nvram: ----              318                    <no date>  persistent-data

!Flash: nvram: ----                4                    <no date>  private-KS1

!Flash: nvram: ----                0                    <no date>  private-config

!Flash: nvram: -rw-                0                    <no date>  startup-config

!Flash: nvram: -rw-                                     <no date>  underlying-config

!Flash: nvram: ----               31                    <no date>  vudi

!Flash: nvram: 32 MB total (99% free)

!

!Flash: bootflash: Directory of bootflash:/

!Flash: bootflash: drwx             4096  Sep 17 2022 00:35:37 +00:00  .dbpersist

!Flash: bootflash: drwx             4096  Sep 17 2022 01:22:33 +00:00  .installer

!Flash: bootflash: drwx             4096  Sep 17 2022 00:48:24 +00:00  .prst_sync

!Flash: bootflash: drwx             4096  Sep 17 2022 00:35:18 +00:00  .rollback_timer

!Flash: bootflash: drwx             4096  Sep 17 2022 00:35:12 +00:00  bootlog_history

!Flash: bootflash: drwx             4096  Sep 17 2022 00:35:17 +00:00  core

!Flash: bootflash: -rw-        469742684  Jul 20 2021 17:02:43 +00:00  csr1000v-mono-universalk9.17.03.04a.SPA.pkg

!Flash: bootflash: -rw-         48414762  Jul 20 2021 17:02:43 +00:00  csr1000v-rpboot.17.03.04a.SPA.pkg

!Flash: bootflash: -rw-              209  Sep 17 2022 01:20:10 +00:00  csrlxc-cfg.log

!Flash: bootflash: -rw-                0  Sep 17 2022 00:47:39 +00:00  cvac.log

!Flash: bootflash: drwx             4096  Sep 17 2022 00:35:20 +00:00  gs_script

!Flash: bootflash: drwx             4096  Sep 17 2022 00:56:50 +00:00  guest-share

!Flash: bootflash: -rw-            20109  Sep 17 2022 00:35:26 +00:00  ios_core.p7b

!Flash: bootflash: drwx             4096  Sep 17 2022 00:57:47 +00:00  iox_host_data_share

!Flash: bootflash: drwx             4096  Sep 17 2022 01:20:40 +00:00  license_evlog

!Flash: bootflash: -rw-              419  Sep 17 2022 00:35:20 +00:00  mode_event_log

!Flash: bootflash: drwx             4096  Sep 17 2022 00:59:25 +00:00  onep

!Flash: bootflash: -rw-             1105  Jul 20 2021 17:02:43 +00:00  packages.conf

!Flash: bootflash: drwx             4096  Sep 17 2022 00:54:40 +00:00  pnp-info

!Flash: bootflash: drwx             4096  Sep 17 2022 01:21:26 +00:00  pnp-tech

!Flash: bootflash: -rw-                                                throughput_monitor_params

!Flash: bootflash: drwx                                                tracelogs

!Flash: bootflash: -rwx             1314  Sep 17 2022 00:35:26 +00:00  trustidrootx3_ca.ca

!Flash: bootflash: drwx             4096  Sep 17 2022 00:36:21 +00:00  virtual-instance

!Flash: bootflash: 5 GB total (86% free)

!

!

! Hw-programmable versions

! Slot              CPLD version              FPGA version

! -----------------------------------------------------------

! R0                00000000                  N/A

! F0                00000000                  N/A

!

!NAME: "Chassis",               DESCR: "Cisco CSR1000V Chassis"

!PID: CSR1000V

!VID: V00

!SN: 9N5KGWYZ34V

!NAME: "module R0",             DESCR: "Cisco CSR1000V Route Processor"

!PID: CSR1000V

!VID: V00

!SN: JAB1303001C

!NAME: "NME R0",                DESCR: "Network Management Ethernet"

!NAME: "GigabitEthernet1",      DESCR: "Mapped to eth0 on VXE"

!NAME: "GigabitEthernet2",      DESCR: "Mapped to eth1 on VXE"

!NAME: "GigabitEthernet3",      DESCR: "Mapped to eth2 on VXE"

!NAME: "GigabitEthernet4",      DESCR: "Mapped to eth3 on VXE"

!NAME: "cpu R0/0",              DESCR: "CPU 0 of module R0"

!NAME: "module F0",             DESCR: "Cisco CSR1000V Embedded Services Processor"

!PID: CSR1000V

!NAME: "qfp F0/0",              DESCR: "QFP 0 of module F0"

!

!DOT1x: Sysauthcontrol                Disabled

!DOT1x: Dot1x Protocol Version               3

!

!

!DEBUG: IOSXE Conditional Debug Configs:

!DEBUG: Conditional Debug Global State: Stop

!DEBUG: IOSXE Packet Tracing Configs:

!DEBUG: Packet Infra debugs:

!DEBUG: Ip Address                                               Port

!DEBUG: ------------------------------------------------------|----------

!

config-register 0x2102

!

version 17.3

service timestamps debug datetime msec

service timestamps log datetime msec

! Call-home is enabled by Smart-Licensing.

service call-home

platform qfp utilization monitor load 80

platform punt-keepalive disable-kernel-core

platform console serial

!

hostname csr1000v

!

boot-start-marker

boot-end-marker

!

enable secret 9 $9$Vy9L.J1VDPyXPk$mZMvDQzqZ1Pq0SsuIYucGR7w9O8.gMOh6XAFRVnjZS.

!

no aaa new-model

!

login on-success log

!

subscriber templating

!

multilink bundle-name authenticated

!

crypto pki trustpoint TP-self-signed-3254920258

enrollment selfsigned

subject-name cn=IOS-Self-Signed-Certificate-3254920258

revocation-check none

rsakeypair TP-self-signed-3254920258

!

crypto pki trustpoint SLA-TrustPoint

enrollment pkcs12

revocation-check crl

!

crypto pki certificate chain TP-self-signed-3254920258

certificate self-signed 01

  30820330 30820218 A0030201 02020101 300D0609 2A864886 F70D0101 05050030

  31312F30 2D060355 04031326 494F532D 53656C66 2D536967 6E65642D 43657274

  69666963 6174652D 33323534 39323032 3538301E 170D3232 30393137 30313238

  30395A17 0D333230 39313630 31323830 395A3031 312F302D 06035504 03132649

  4F532D53 656C662D 5369676E 65642D43 65727469 66696361 74652D33 32353439

  32303235 38308201 22300D06 092A8648 86F70D01 01010500 0382010F 00308201

  0A028201 0100D790 A1522D3F 92BB5D28 630DAE86 338763AD D87198F3 836A9F1D

  39778AB1 905EABA8 261F9E20 92170F42 C0CC5F13 E11022AC 1491E3A8 6ABEF613

  7FC394E2 52FA96EC F27B7975 B31741DC 546B40A8 119EDD7C 58E88141 ACDB9A67

  DD9B25C2 CC5D6FD4 D396B7C7 533B08FF 5E601FCC 8E2FE078 6DF8C802 538312AA

  F15B8719 C215E037 01904FDB 47822163 152D269A D0FCA329 7A5E63B6 7CFB9B2D

  16E894E3 3A21FBBC B0A9E001 7ECCCC12 A5B7F724 5849DD30 6C6CF094 FE37921C

  3D5AF7C0 2D44CD06 9F4D44C8 CF43F9A5 15F63B0F CD20E0B8 9307B945 F20EF0D4

  57CE7B5A CB556C54 FBA27CFD 8B648EB1 5A1D5A1B A7FB270A 3B8C0B9D 8773EB9F

  ACA13022 183D0203 010001A3 53305130 0F060355 1D130101 FF040530 030101FF

  301F0603 551D2304 18301680 14CCCCE1 FFC3C637 DE737A4A 651B8EF4 D559567B

  AB301D06 03551D0E 04160414 CCCCE1FF C3C637DE 737A4A65 1B8EF4D5 59567BAB

  300D0609 2A864886 F70D0101 05050003 82010100 5D87464B E227F8FF 4EFF1078

  70B7F122 E6786FCE 79F1BFF4 C9BF9897 B77865E6 43B26DAA D48914FA C842A07A

  DE6CF434 B1C22FD2 599BF9ED 704619C9 8B79175A F5790184 A46372FD A84008CD

  E967F7BC DF1090DC 3BEC5C92 8B0BDE61 E7444D1B 784966BC 1CB0EC52 5CEC6D38

  1F108F3E F70D8A58 D569CC50 956ABDD9 CAC7C793 4397F876 63BC4C6E 52673D6F

  9257776D 672A00B6 8E9CAC52 63491ADB 2A4DE0CE 0C0E691C 7F4A8B0B 8C33CE5A

  DD3288A5 85B2047B 614FED1D 86A67A73 586D0345 BBC96CAD F9ECFDC8 727E03EF

  1E757CC9 62DE993D 8E56D3DF 3A349DC7 B7652AA1 4E6AACE0 DF61963D 86FDF82E

  DCADA130 FDFC880A 6C4F36E3 ACA00374 8DED00FC

        quit

crypto pki certificate chain SLA-TrustPoint

certificate ca 01

  30820321 30820209 A0030201 02020101 300D0609 2A864886 F70D0101 0B050030

  32310E30 0C060355 040A1305 43697363 6F312030 1E060355 04031317 43697363

  6F204C69 63656E73 696E6720 526F6F74 2[ 4163.360603] serial8250: too much work for irq4

0434130 1E170D31 33303533 30313934

  3834375A 170D3338 30353330 31393438 34375A30 32310E30 0C060355 040A1305

  43697363 6F312030 1E060355 04031317 43697363 6F204C69 63656E73 696E6720

  526F6F74 20434130 82012230 0D06092A 864886F7 0D010101 05000382 010F0030

  82010A02 82010100 A6BCBD96 131E05F7 145EA72C 2CD686E6 17222EA1 F1EFF64D

  CBB4C798 212AA147 C655D8D7 9471380D 8711441E 1AAF071A 9CAE6388 8A38E520

  1C394D78 462EF239 C659F715 B98C0A59 5BBB5CBD 0CFEBEA3 700A8BF7 D8F256EE

  4AA4E80D DB6FD1C9 60B1FD18 FFC69C96 6FA68957 A2617DE7 104FDC5F EA2956AC

  7390A3EB 2B5436AD C847A2C5 DAB553EB 69A9A535 58E9F3E3 C0BD23CF 58BD7188

  68E69491 20F320E7 948E71D7 AE3BCC84 F10684C7 4BC8E00F 539BA42B 42C68BB7

  C7479096 B4CB2D62 EA2F505D C7B062A4 6811D95B E8250FC4 5D5D5FB8 8F27D191

  C55F0D76 61F9A4CD 3D992327 A8BB03BD 4E6D7069 7CBADF8B DF5F4368 95135E44

  DFC7C6CF 04DD7FD1 02030100 01A34230 40300E06 03551D0F 0101FF04 04030201

  06300F06 03551D13 0101FF04 05300301 01FF301D 0603551D 0E041604 1449DC85

  4B3D31E5 1B3E6A17 606AF333 3D3B4C73 E8300D06 092A8648 86F70D01 010B0500

  03820101 00507F24 D3932A66 86025D9F E838AE5C 6D4DF6B0 49631C78 240DA905

  604EDCDE FF4FED2B 77FC460E CD636FDB DD44681E 3A5673AB 9093D3B1 6C9E3D8B

  D98987BF E40CBD9E 1AECA0C2 2189BB5C 8FA85686 CD98B646 5575B146 8DFC66A8

  467A3DF4 4D565700 6ADF0F0D CF835015 3C04FF7C 21E878AC 11BA9CD2 55A9232C

  7CA7B7E6 C1AF74F6 152E99B7 B1FCF9BB E973DE7F 5BDDEB86 C71E3B49 1765308B

  5FB0DA06 B92AFE7F 494E8A9E 07B85737 F3A58BE1 1A48A229 C37C1E69 39F08678

  80DDCD16 D6BACECA EEBC7CF9 8428787B 35202CDC 60E4616A B623CDBD 230E3AFB

  418616A9 4093E049 4D10AB75 27E86F73 932E35B5 8862FDAE 0275156F 719BB2F0

  D697DF7F 28

        quit

!

license udi pid CSR1000V sn 9N5KGWYZ34V

diagnostic bootup level minimal

memory free low-watermark processor 71489

!

spanning-tree extend system-id

!

redundancy

!

interface GigabitEthernet1

description centos8_ens3

ip address 10.0.0.1 255.255.255.0

negotiation auto

no mop enabled

no mop sysid

!

interface GigabitEthernet2

no ip address

shutdown

negotiation auto

no mop enabled

no mop sysid

!

interface GigabitEthernet3

no ip address

shutdown

negotiation auto

no mop enabled

no mop sysid

!

interface GigabitEthernet4

no ip address

shutdown

negotiation auto

no mop enabled

no mop sysid

!

ip forward-protocol nd

ip http server

ip http authentication local

ip http secure-server

!

control-plane

!

line con 0

stopbits 1

line vty 0 4

password password

login

transport input telnet

line vty 5 15

password password

login

transport input telnet

!

call-home

! If contact email address in call-home is configured as sch-smart-licensing@cisco.com

! the email address configured in Cisco Smart License Portal will be used as contact email address to send SCH notifications.

contact-email-addr sch-smart-licensing@cisco.com

profile "CiscoTAC-1"

  active

  destination transport-method http

!

end

[root@centos8 rancid]#

CentOS で httpd / gitweb の構築

root で httpd の gitweb 設定を変更

conf.d 配下の gitweb.conf は dnf / yum でインストールすると、自動で作成されています。

編集して設定を変更します。

Linux
# cp -p /etc/httpd/conf.d/gitweb.conf /etc/httpd/conf.d/gitweb.conf.`date "+%Y%m%d-%H%M%S"`
# vi /etc/httpd/conf.d/gitweb.conf
# diff -c /etc/httpd/conf.d/gitweb.conf.`date "+%Y%m%d-%H"`* /etc/httpd/conf.d/gitweb.conf
/httpd/conf.d/gitweb.conf
-bash: command substitution: line 1: unexpected EOF while looking for matching `"'
-bash: command substitution: line 2: syntax error: unexpected end of file
*** /etc/httpd/conf.d/gitweb.conf.20220916-215040       2020-07-20 15:30:33.000000000 -0400
--- /etc/httpd/conf.d/gitweb.conf       2022-09-16 22:27:41.334710015 -0400
***************
*** 1,7 ****
! Alias /git /var/www/git

! <Directory /var/www/git>
!   Options +ExecCGI
!   AddHandler cgi-script .cgi
!   DirectoryIndex gitweb.cgi
! </Directory>
--- 1,12 ----
! #Alias /git /var/www/git
! Alias /git /var/lib/rancid

! <VirtualHost *:80>
!         <Directory /var/lib/rancid>
!           Options +ExecCGI
!           AddHandler cgi-script .cgi
!           DirectoryIndex gitweb.cgi
!           Require all denied
!           Require ip 10.0.0.0/8
!         </Directory>
! </VirtualHost>
[root@centos8 rancid]#

apache 配下に git ディレクトリのエイリアス、10.0.0.0/8 からのアクセスを許可しています。

ブラウザでアクセスさせたい PC の IP セグメントを Require ip に記載してください。また、複数行書いても動作します。


gitweb の設定を変更

gitweb は RANCID 専用というわけではないため、カスタマイズする必要があります。

まずは設定ファイルの変更を行います。

Linux
# cp -p /etc/gitweb.conf /etc/gitweb.conf.`date "+%Y%m%d-%H%M%S"`
# vi /etc/gitweb.conf
# diff -c /etc/gitweb.conf.`date "+%Y%m%d-%H"`* /etc/gitweb.conf

以下が変更点です。

-bash: command substitution: line 1: unexpected EOF while looking for matching `"'
-bash: command substitution: line 2: syntax error: unexpected end of file
*** /etc/gitweb.conf.20220916-215509    2020-07-20 15:34:28.000000000 -0400
--- /etc/gitweb.conf    2022-09-16 21:57:37.351537362 -0400
***************
*** 8,13 ****
--- 8,14 ----
  # Set the path to git projects.  This is an absolute filesystem path which will
  # be prepended to the project path.
  #our $projectroot = "/var/lib/git";
+ our $projectroot = "/var/lib/rancid";

  # Set the list of git base URLs used for URL to where fetch project from, i.e.
  # the full URL is "$git_base_url/$project". By default this is empty
***************
*** 41,47 ****
  #
  # Allow projects to override the default setting via git config file.
  # Example: gitweb.grep = 0|1;
! #$feature{'grep'}{'override'} = 1;

  # Disable the pickaxe search, which will list the commits that modified a given
  # string in a file. This can be practical and quite faster alternative to
--- 42,48 ----
  #
  # Allow projects to override the default setting via git config file.
  # Example: gitweb.grep = 0|1;
! $feature{'grep'}{'override'} = 1;

  # Disable the pickaxe search, which will list the commits that modified a given
  # string in a file. This can be practical and quite faster alternative to
***************
*** 50,53 ****
  #
  # Allow projects to override the default setting via git config file.
  # Example: gitweb.pickaxe = 0|1;
! #$feature{'pickaxe'}{'override'} = 1;
--- 51,54 ----
  #
  # Allow projects to override the default setting via git config file.
  # Example: gitweb.pickaxe = 0|1;
! $feature{'pickaxe'}{'override'} = 1;
[root@centos8 rancid]#

gitweb の projectroot を /var/lib/rancid に、いくつかのコメントアウトを解除して有効化します。

他にも有効な設定がありそうですが、筆者は開拓できていません。

gitweb のファイルを rancid ディレクトリにコピー

cgi などのファイルを apache で公開する rancid のディレクトリにコピーします。

Linux
# cp -p /var/www/git/gitweb.cgi /var/lib/rancid/
# cp -pr /var/www/git/static /var/lib/rancid/
# ls /var/lib/rancid/static/
git-favicon.png  git-logo.png  gitweb.css  gitweb.js

rancid ユーザと apache ユーザのグループ相互追加

RANCID のファイルは、User:rancid,group:rancid で作成されるので、 apache で読み取れず、gitweb で表示できません。 ここでは、RANCID と apache ユーザ間でグループに相互追加します。

Linux
# usermod -aG rancid apache
# usermod -aG apache rancid

# groups rancid
rancid : rancid apache
# groups apache
apache : apache rancid

ここはあまり考えていないため、もっと適切なやり方があると思います。

rancid ディレクトリの権限変更

chown -R で apache のグループ権限を付与して、httpd がアクセスできるようにします。

Linux
# ls -al
total 4
drwxr-xr-x   5 rancid apache   40 Sep 16 21:29 .
drwxr-xr-x. 32 root   root   4096 Sep 16 21:06 ..
drwxr-x---   3 rancid rancid   17 Sep 16 21:29 GIT
drwxr-x---   2 rancid rancid   60 Sep 16 21:39 logs
drwxr-x---   4 rancid rancid  174 Sep 16 21:45 TKY
# chown -R rancid:apache /var/lib/rancid/*
# ls -al
total 4
drwxr-xr-x   5 rancid apache   40 Sep 16 21:29 .
drwxr-xr-x. 32 root   root   4096 Sep 16 21:06 ..
drwxr-x---   3 rancid apache   17 Sep 16 21:29 GIT
drwxr-x---   2 rancid apache   60 Sep 16 21:39 logs
drwxr-x---   4 rancid apache  174 Sep 16 21:45 TKY
[root@centos8 rancid]#

httpd サーバプロセスを起動 + 自動起動

start で起動、enable で再起動後に自動起動させます。

Linux
# systemctl status httpd
# systemctl start httpd
# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.


gitweb 動作確認

PC のブラウザから httpd + gitweb にアクセス

http://<CentOS_8_IP>/git/


うまく行けば、以下のようなページが表示されます。

PC
gitweb トップページ

RSS で更新時にブラウザに通知を表示させたりできます。

検索ボックスはいまいち何が対象になるのかわかりません・・・


apache の root ディレクトリはテストページが表示されるため、現用にする際は無効にしたほうが良いです。

差分表示

上記のトップページから、TKY 行の summary -> commit diff をクリックします。

下記の例では、初回コンフィグ取得 -> 後述の description 変更 -> 再取得を行ったものになっています。

PC
commmit diff


初期構築・取得後は、まだリポジトリにコンフィグがまったくないため、すべてが差分として記録されます。

RANCID 初期構築時・コンフィグ初回取得後


csr1000v で interface description を追加し、/usr/bin/rancid-run を実行して、差分が増えていないか確認します。

csr1000v
enable
!
configure terminal
!
interface GigabitEthernet1
 description centos8_ens3
!
end
Linux
# su - rancid
$ locate rancid-run
/usr/bin/rancid-run
/usr/libexec/rancid/rancid-run
/usr/share/man/man1/rancid-run.1.gz
$ /usr/bin/rancid-run

先ほどクリックした commit diff の、もう一個上の新しい commit diff をクリックしてみましょう。

PC
interface description 追加後

interface GigabitEthernet1 に description が追加されたことが、gitweb で確認できました。

複数人で検証環境を構築していて、「hh:mm から障害が起きてるんだけどなんか変更した ?」 というときに見に行くと非常に便利です。

なお、NTP で RANCID のサーバを時刻同期していないと使いものにならないため、同期しておきましょう。

差分の横並び比較

上部にある side by side をクリックすることで、Winmerge のような横並び比較をすることが可能です。

PC
差分の横並び比較

行中の差分はわからないため、その場合は各時刻の raw でコンフィグを取得して PC の Winmerge で差分を取ると良いでしょう。

特に Juniper では display set したコンフィグが非常に長い行になるため、side by side の比較は辛い場合が多いです。


その他

昔、筆者が Shrubbery Networks に送ったスクリプトの差分です。

RANCID は password , enable , SNMP community などがマスクされるのですが、ppp と dot11 ssid がマスクされなかったので、随分前に追加してもらいました。

# diff -c /usr/libexec/rancid/rancid.rpmdef /usr/libexec/rancid/rancid_20100224
*** /usr/libexec/rancid/rancid.rpmdef   2011-01-23 23:30:02.000000000 +0900
--- /usr/libexec/rancid/rancid_20100224 2011-02-24 10:23:04.427575427 +0900
***************
*** 1669,1675 ****
            ProcessHistory("","","","! neighbor $1 password <removed>\n");
            next;
        }
!       if (/^(ppp .* password) 7 .*/ && $filter_pwds >= 1) {
            ProcessHistory("","","","!$1 <removed>\n"); next;
        }
        if (/^(ip ftp password) / && $filter_pwds >= 1) {
--- 1669,1678 ----
            ProcessHistory("","","","! neighbor $1 password <removed>\n");
            next;
        }
!       if (/^( ppp .* password) 7 .*/ && $filter_pwds >= 1) {
!           ProcessHistory("","","","!$1 <removed>\n"); next;
!       }
!       if (/^( wpa-psk .*) 7 .*/ && $filter_pwds >= 1) {
            ProcessHistory("","","","!$1 <removed>\n"); next;
        }
        if (/^(ip ftp password) / && $filter_pwds >= 1) {

公式マニュアル

/usr/share/rancid/README

man rancid-run

man rancid-cvs

man rancid.conf

リファレンス

Shrubbery Networks

Using RANCID

telnet で接続できる CentOS 7/8 の eve-ng 用 Linux ノードイメージを作った

Fedora Wiki 昔筆者が書いてたサイト DB が吹っ飛んで無くなった リンクは Web Archive のもの

RANCID+ViewVCでコンフィグ管理