Ossian Story
article thumbnail

[Cacti] Install - CentOS 6.x


Cacti란?


Cacti는 서비스의 상태체크를 하고 그 결과를 그래프로 표시해 주는 모니터링 서비스입니다.


Cacti는 RRDtool과 SNMP를 기반으로하여 모니터링을 합니다.

SNMP를 통해 장비가 가지고 있는 MIB를 추출하고 추출된 MIB 값을 RRDTool이 데이터베이스를 만들어 저장하고 그래프로 만들어줍니다.


Cacti를 사용할 경우 네트워크 사용률, 시스템의 하드웨어 상황, 프로세스 상황 등을 웹상에서 쉽게 모니터링 할 수 있습니다.




Cacti 설치하기


Cacti 설치 포스팅은 GCP(Google Cloud Platform) Instence 및 CentOS 6.x 환경에서 설치가 진행됩니다.


GCP Instence Root 권한으로 변경

- 이미 Root 권한일 경우엔 진행하지 않아도 무방합니다.

# Root 암호 생성
[jake.nam88@cacti-master ~]$ sudo passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
 
# Root 로그인
[jake.nam88@cacti-master ~]$ su
Password:
[root@cacti-master jake.nam88]#




Selinux 해제

vi /etc/selinux/config
 
------------------------------------------------------------------
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     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 two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
------------------------------------------------------------------
 
setenforce 0




Cacti 설치에 필요한 패키지 설치

yum -y install gcc gd gd-devel libart_lgpl libart_lgpl-devel zlib zlib-devel patch libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel fontconfig fontconfig-devel gmp gmp-devel mhash mhash-devel libmcrypt libmcrypt-devel freetype freetype-devel perl-devel net-snmp-* pango-devel help2man



Installed:
  fontconfig.x86_64 0:2.8.0-5.el6          fontconfig-devel.x86_64 0:2.8.0-5.el6      freetype.x86_64 0:2.3.11-17.el6
  freetype-devel.x86_64 0:2.3.11-17.el6    gcc.x86_64 0:4.4.7-18.el6                  gd.x86_64 0:2.0.35-11.el6
  gd-devel.x86_64 0:2.0.35-11.el6          gmp-devel.x86_64 0:4.3.1-12.el6            help2man.noarch 0:1.36.4-6.el6
  libart_lgpl.x86_64 0:2.3.20-5.1.el6      libart_lgpl-devel.x86_64 0:2.3.20-5.1.el6  libjpeg-turbo-devel.x86_64 0:1.2.1-3.el6_5
  libmcrypt.x86_64 0:2.5.8-9.el6           libmcrypt-devel.x86_64 0:2.5.8-9.el6       libpng-devel.x86_64 2:1.2.49-2.el6_7
  libxml2-devel.x86_64 0:2.7.6-21.el6_8.1  mhash.x86_64 0:0.9.9.9-3.el6               mhash-devel.x86_64 0:0.9.9.9-3.el6
  net-snmp.x86_64 1:5.5-60.el6             net-snmp-devel.x86_64 1:5.5-60.el6         net-snmp-libs.x86_64 1:5.5-60.el6
  net-snmp-perl.x86_64 1:5.5-60.el6        net-snmp-python.x86_64 1:5.5-60.el6        net-snmp-utils.x86_64 1:5.5-60.el6
  pango-devel.x86_64 0:1.28.1-11.el6       patch.x86_64 0:2.6-6.el6                   perl-devel.x86_64 4:5.10.1-144.el6
  zlib-devel.x86_64 0:1.2.3-29.el6




RRD Toool 설치

yum -y install rrdtool



Installed:
  rrdtool.x86_64 0:1.3.8-10.el6




Apache 설치

yum -y install httpd httpd-devel



Installed:
  httpd.x86_64 0:2.2.15-60.el6.centos.6   httpd-devel.x86_64 0:2.2.15-60.el6.centos.6




Cacti 설치

cd /usr/local/src
wget https://www.cacti.net/downloads/cacti-1.1.28.tar.gz
tar -zxvf cacti-1.1.28.tar.gz
cp -Rf cacti-1.1.28 /usr/local/cacti
ln -/usr/local/cacti /var/www/html/cacti




PHP 설치

yum -y install php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli php-snmp php-posix php-ldap



Installed:
  php.x86_64 0:5.3.3-49.el6                   php-cli.x86_64 0:5.3.3-49.el6            php-common.x86_64 0:5.3.3-49.el6
  php-devel.x86_64 0:5.3.3-49.el6             php-gd.x86_64 0:5.3.3-49.el6             php-ldap.x86_64 0:5.3.3-49.el6
  php-mbstring.x86_64 0:5.3.3-49.el6          php-mysql.x86_64 0:5.3.3-49.el6          php-pear.noarch 1:1.9.4-5.el6
  php-process.x86_64 0:5.3.3-49.el6           php-snmp.x86_64 0:5.3.3-49.el6




PHP 설정 변경

vi /etc/httpd/conf.d/php.conf
 

# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
  LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
  LoadModule php5_module modules/libphp5-zts.so
</IfModule>
 
#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php .htm .html
AddType application/x-httpd-php-source .phps .php .htm .html
 
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
 
#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps



vi /etc/php.ini
 
 
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
 
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = Asia/Seoul
 
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.default-latitude
;date.default_latitude = 31.7667
 
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.default-longitude
;date.default_longitude = 35.2333




Apache 설정 변경

vi /etc/httpd/conf/httpd.conf
 
----------------------------------------------------------------------------
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
#    AllowOverride None
    AllowOverride all
 
#
---------------------------------------------------------------------------
 
---------------------------------------------------------------------------
# The index.html.var file (a type-map) is used to deliver content-
# negotiated documents.  The MultiViews Option can be used for the
# same purpose, but it is much slower.
#
 
DirectoryIndex index.php index.html index.html.var
 
---------------------------------------------------------------------------
 
---------------------------------------------------------------------------
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
AddType application/x-httpd-php .htm .html .php .ph .php3 .php4 .phtml .inc
AddType application/x-httpd-php-source .phps
AddHandler cgi-script .cgi
 
#
---------------------------------------------------------------------------




Apache Service 재시작

service httpd restart
 
Stopping httpd:                [  OK  ]
Starting httpd:                [  OK  ]




SNMP 설정 변경

vi /etc/snmp/snmpd.conf
 
---------------------------------------------------------------------------
# First, map the community name "public" into a "security name"
 
#       sec.name  source          community
#com2sec notConfigUser  default       public
com2sec  public         default       public
 
####
---------------------------------------------------------------------------
 
---------------------------------------------------------------------------
# Second, map the security name into a group name:
 
#       groupName      securityModel securityName
#group   notConfigGroup v1           notConfigUser
#group   notConfigGroup v2c           notConfigUser
group   public          v1           public
group   public          v2c          public
####
---------------------------------------------------------------------------
 
---------------------------------------------------------------------------
# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)
#view    systemview    included   .1.3.6.1.2.1.1
#view    systemview    included   .1.3.6.1.2.1.25.1.1
view    all             included  .1
 
####
---------------------------------------------------------------------------
 
---------------------------------------------------------------------------
# Finally, grant the group read-only access to the systemview view.
 
#       group          context sec.model sec.level prefix read   write  notif
#access  notConfigGroup ""      any       noauth    exact  systemview none none
access  public          ""      any       noauth    exact  all        none none
---------------------------------------------------------------------------




SNMP Service 시작

# service snmpd start
Starting snmpd:       [  OK  ]




MySQL 설치 및 환경설정

MySQL은 5.6 버전부터 Yum을 통한 설치를 지원하며 MySQL repo에 연결하여 리눅스와 맞는 버전의 저장소 RPM을 다운받아 설치합니다.

(참고 사이트 : https://www.lesstif.com/pages/viewpage.action?pageId=24445108)

rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
 
Retrieving https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
warning: /var/tmp/rpm-tmp.F2V92n: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql57-community-relea########################################### [100%]
 
 
yum install -y mysql-community-server mysql-devel



MySQL 서비스를 시작하면 설치가 진행됩니다. 설치완료 후 로그를 통해서 임시로 설정된 Root 암호를 확인합니다.

service mysqld start
 
Initializing MySQL database:                               [  OK  ]
Starting mysqld:                                           [  OK  ]
 
 
sudo grep 'temporary password' /var/log/mysqld.log
 
2017-12-27T07:31:11.692995Z 1 [Note] A temporary password is generated for root@localhost: sN7z1i/MAg(G



MySQL Secure Install을 실행하여 설정을 진행합니다. Root 암호는 위에서 확인한 암호를 입력합니다.

mysql_secure_installation
 
------------------------------------------------------------------------------------------------------
Securing the MySQL server deployment.
Enter password for user root:
 
The existing password for the user account root has expired. Please set a new password.
 
New password:
Re-enter new password:
 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
 
Estimated strength of the password: 100
Change the password for root ? ((Press y|for Yes, any other key for No) : Yes
 
New password:
Re-enter new password:
 
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|for Yes, any other key for No) : Yes
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
 
Remove anonymous users? (Press y|for Yes, any other key for No) : Yes
Success.
 
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
 
Disallow root login remotely? (Press y|for Yes, any other key for No) : No
 
 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
 
 
Remove test database and access to it? (Press y|for Yes, any other key for No) : Yes
 - Dropping test database...
Success.
 
 - Removing privileges on test database...
Success.
 
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
 
Reload privilege tables now? (Press y|for Yes, any other key for No) : Yes
Success.
 
All done!




MySQL 접속 및 데이터베이스 생성

신규로 설정한 암호를 입력합니다.

mysql -u root -p mysql
Enter password:



mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)
 
mysql> grant all on cacti.* to cactiuser@localhost identified by 'Cactiuser123!';
Query OK, 0 rows affected, 1 warning (0.00 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> quit;
Bye




Cacti Database 환경설정

Cacti Config에 MySQL Cacti 계정 설정

vi /usr/local/cacti/include/config.php
 
 
/* make sure these values reflect your actual database/host/user/password */
 
$database_type     = 'mysql';
$database_default  = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cactiuser';
$database_password = 'Cactiuser123!';
$database_port     = '3306';
$database_ssl      = false;
 
/* when the cacti server is a remote poller, then these entries point to
 * the main cacti server.  otherwise, these variables have no use.
 * and must remain commented out. */
 
#$rdatabase_type     = 'mysql';




Cacti 스키마 MySQL에 넣기

아래와 같이 Cacti 데이터베이스에 테이블이 정상적으로 등록되었는지 확인합니다.

cd /usr/local/cacti/
 
---------------------------------------
mysql -u root -p cacti < cacti.sql
Enter password:
 
---------------------------------------
 
 
---------------------------------------
mysql -u root -p
Enter password:
---------------------------------------
 
 
---------------------------------------
mysql> use cacti;
mysql> show tables;
 
+-------------------------------------+
| Tables_in_cacti                     |
+-------------------------------------+
| aggregate_graph_templates           |
| aggregate_graph_templates_graph     |
| aggregate_graph_templates_item      |
| aggregate_graphs                    |
| aggregate_graphs_graph_item         |
| aggregate_graphs_items              |
| ...
 
 
---------------------------------------




Cacti SPINE 설치 및 환경설정

Cacti Spine 다운로드 및 압축해제 합니다.

cd /usr/local/src/
wget http://www.cacti.net/downloads/spine/cacti-spine-latest.tar.gz
tar -zxvf cacti-spine-latest.tar.gz
cd /usr/local/src/cacti-spine-1.1.29/



Configure 및 Make를 통한 인스톨을 진행합니다.

./configure
 
make
 
make install



아래와 같이 버전확인 시 버전이 표기된다면 정상적으로 설치된 것입니다.

/usr/local/spine/bin/spine --version
 
SPINE 1.1.29  Copyright 2004-2017 by The Cacti Group



SPINE 환경설정에 Cacti 데이터베이스 정보를 입력합니다.

vi /usr/local/spine/etc/spine.conf.dist
 
 
--------------------------------------------------------------------------------
# | RDB_Pass        The remote database password.                           |
# +-------------------------------------------------------------------------+
 
DB_Host                 localhost
DB_Database             cacti
DB_User                 cactiuser
DB_Pass                 Cactiuser123!
DB_Port                 3306
 
--------------------------------------------------------------------------------



아래는 Cacti 환경설정 시 입력해야 되는 SPINE 경로이므로 기록해 둡니다.

Spine Binary File Location = /usr/local/spine/bin/spine
Spine Config File Path = /usr/local/spine/etc/spine.conf.dist




Cacti Log 파일 생성

Cacti Log가 저장될 수 있는 로그파일을 생성합니다.

touch /usr/local/cacti/log/cacti.log




Cacti 환경설정


Cacti 및 관련 패키지 설치가 완료되었다면 웹브라우저를 통해 환경설정을 진행합니다.


웹브라우저에서 아래와 같이 URL을 입력합니다.

(크롬에선 정상적으로 실행되지 않을 수 있습니다.)

http://"Cacti Server IP"/cacti/install/



Accept 체크 후 Next를 클릭합니다.


아래와 같이 MySQL TimeZone 및 기타 설정과 관련한 오류를 확인할 수 있습니다.

설정 변경을 통하여 Cacti에서 요구하는 환경설정으로 변경을 진행합니다.


Cacti MySQL TimeZone 설정 후 Cacti 환경설정 웹페이지 새로고침 합니다.

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
Enter password:

cd /var/www/html/cacti/cli
 
php repair_database.php --force
 
php upgrade_database.php
 
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
Enter password:

mysql -uroot -p
Enter password:
 
mysql> use mysql;

mysql> GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
 
mysql> flush privileges;
 
mysql> quit;



새로고침하여 MySQL TimeZone Error가 해결된 것을 확인합니다.


My.cnf에서 아래와 같이 MySQL의 환경설정을 변경합니다.

vi /etc/my.cnf
 
------------------------------------------------------------------------------
# Disabling symbolic-links is recommended to prevent assorted security risks
collation-server = utf8mb4_unicode_ci
character-set-server = utf8mb4
max_heap_table_size = 182M
max_allowed_packet = 16777216
tmp_table_size = 64M
join_buffer_size = 64M
innodb_buffer_pool_size = 905M
innodb_doublewrite = OFF
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16
 
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
------------------------------------------------------------------------------
 
service mysqld restart
 
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]



새로고침하여 MySQL Variable Setting Error가 해결 된 것을 확인 후 Next를 클릭합니다.


Primary Server를 선택 후 Next를 클릭합니다.


SPINE Binary 경로는 다시 지정할 예정이므로 Next를 클릭합니다.


Apache가 Cacti Resource를 접근할 수 있도록 권한을 부여합니다.


아래와 같이 Cacti 디렉토리에 Apache에 대한 권한을 부여합니다.

chown -R apache.apache /usr/local/cacti/resource/
chown -R apache.apache /usr/local/cacti/scripts
chown -R apache.apache /usr/local/cacti/log
chown -R apache.apache /usr/local/cacti/cache
 
service httpd restart
 
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]



crontab에 아래와 같이 등록합니다.

vi /etc/cron.d/cacti
 
------------------------------------------------------------------------------
 
*/1 * * * * root /usr/bin/php /usr/local/cacti/poller.php > /dev/null 2>&1
 
------------------------------------------------------------------------------



새로고침하여 쓰기권한을 확인 후 Next를 클릭합니다.


템플릿 설정 여부를 체크 후 Finish를 클릭합니다.


최초 로그인 아이디와 패스워드는 " admin / admin " 입니다.


암호 변경 후 SAVE를 클릭합니다.


Configuration > Settings > Paths > Alternate poller Path로 이동하여 위에서 기록해놓은 SPINE Binary와 Config File 경로를 입력 후 저장합니다.

Spine Binary File Location = /usr/local/spine/bin/spine
Spine Config File Path = /usr/local/spine/etc/spine.conf.dist




Configuration > Settings > Poller로 이동하여 아래와 같이 SPINE 값으로 변경합니다.



이것으로 Cacti의 기본설치는 모두 완료되었습니다.

다음 포스팅을 통하여 Cacti의 플러그인 설치 및 모니터링에 대한 포스팅을 진행하도록 하겠습니다.




profile

Ossian Story

@ossians