Centos7 cacti percona nginx
centos 7 에서 cacti 설치시 의존성 패키지로 httpd 가 설치 되며 db.php 파일의 권한이 apache 로 되어 있습니다.
db.php 파일의 권한변경이 필요 합니다.
apache web-server 가 아닌 nginx web-server 이용시 /etc/nginx/conf.d/default.conf 설정에 아래 내용을 추가 합니다.
[root@centos74 conf.d]# vi default.conf # cacti settings location /cacti { alias /usr/share/cacti; index index.php; } location ~ ^/cacti.+\.php$ { # fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^/cacti(.+\.php)(.*)$; fastcgi_param SCRIPT_FILENAME /usr/share/cacti/$fastcgi_script_name; include /etc/nginx/fastcgi_params; }
별도의 Domain 이용시 아래 내용참고
[root@centos74 conf.d]# vi cacti.conf server { listen 80; server_name cacti.test2.com; root /usr/share; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } # error_page 500 502 503 504 /50x.html; # location = /50x.html { # root /usr/share/cacti; # } location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
default.conf 파일 수정
[root@centos74 ~]# vi /etc/nginx/conf.d/default.conf #access_log /var/log/nginx/host.access.log main; root /usr/share/nginx/html; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location /server-status { stub_status on; allow 127.0.0.1; #deny all; }
location /server-status 추가
nginx 재시작
[root@centos74 conf.d]# systemctl restart nginx
server-status 확인
[root@centos74 ~]# curl http://localhost/server-status Active connections: 1 server accepts handled requests 2 2 2 Reading: 0 Writing: 1 Waiting: 0 [root@centos74 ~]#
db.php 권한 설정
[root@centos74 ~]# ls -al /etc/cacti/db.php -rw-r----- 1 cacti apache 3137 Dec 27 01:29 /etc/cacti/db.php [root@centos74 ~]# chown cacti:nginx /etc/cacti/db.php
db.php 권한을 apache 에서 nginx 로 변경 하지 않을 경우 cacti 웹 인스톨을 진행할수 없습니다.
참고사항: nginx 로 cacti 설정시 아래와 같이 권한 설정 부분에서 Writable 권한 설정 페이지가 출력됩니다.
디렉토리 권한 변경
[root@centos74 ~]# chown -R nginx:nginx /usr/share/cacti/resource/ [root@centos74 ~]# chown -R nginx:nginx /usr/share/cacti/scripts/ [root@centos74 ~]# chown -R nginx:nginx /usr/share/cacti/cache/ [root@centos74 ~]# chown -R nginx:nginx /usr/share/cacti/log/
권한 변경후 확인
percona temp 설치
[root@centos74 ~]# wget https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.7/binary/redhat/7/x86_64/percona-cacti-templates-1.1.7-2.noarch.rpm [root@centos74 ~]# yum install -y percona-cacti-templates-1.1.7-2.noarch.rpm
Nginx 템플릿 추가
[root@centos74 ~]# php /usr/share/cacti/cli/import_template.php --filename=/usr/share/cacti/resource/percona/templates/cacti_host_template_percona_nginx_server_ht_0.8.6i-sver1.1.7.xml Read 42607 bytes of XML data Import ResultsCacti has imported the following items for the Template: CDEF [success] Percona Turn Into Bits CDEF [new] [success] Percona Negate CDEF [new] GPRINT Preset [success] Percona Nginx Server Checksum c5c20ca1d61ee9ccbb45854a46ce6fe8 [new] [success] Percona Nginx Server Version t1.1.7:s1.1.7 [new] [success] Percona Normal [new] Data Input Method [success] Percona Get Nginx Stats/Nginx Requests IM [new] [success] Percona Get Nginx Stats/Nginx Accepts/Handled IM [new] [success] Percona Get Nginx Stats/Nginx Scoreboard IM [new] Data Template [success] Percona Nginx Requests DT [new] [success] Percona Nginx Accepts/Handled DT [new] [success] Percona Nginx Scoreboard DT [new] Graph Template [success] Percona Nginx Requests GT [new] [success] Percona Nginx Accepts/Handled GT [new] [success] Percona Nginx Scoreboard GT [new] Device Template [success] Percona Nginx Server HT [new] [root@centos74 ~]#
Data Collection -> Data Input Methods 로 이동합니다.
Nginx 를 검색하여 Input String 을 수정 합니다.
수정전
<path_php_binary> -q <path_cacti>/scripts/ss_get_by_ssh.php --host <hostname> --type nginx --items hx,hy --server <server> --url <url> --http-user <http-user> --http-password <password>
수정후
<path_php_binary> -q <path_cacti>/scripts/ss_get_by_ssh.php --host <hostname> --type nginx --items hx,hy --server <server> --url <url> --http-user <http-user> --http-password <password>
–server <server> –url <url> –http-user <http-user> –http-password <password> 옵션을 삭제 하시면 됩니다.
Management -> Device 로 이동하여 nginx device 를 생성 합니다.
Device Template 에서 Percona Nginx Server HT 를 선택 합니다.
ss_get_by_ssh.php 설정의 경우 apache 설정과 동일하게 설정 하시면 됩니다.
참고: http://dev.crois.net/2017/12/23/monitoring-centos7-cacti-percona-apache/
스크립트 동작 확인
[root@centos74 scripts]# su - cacti Last login: Wed Dec 27 17:19:05 KST 2017 from localhost on pts/1 -bash-4.2$ php /usr/share/cacti/scripts/ss_get_by_ssh.php --type nginx --host 127.0.0.1 --items hw,hx hw:1 hx:6 -bash-4.2$
Create Graphs for this Device 를 클릭하여 그래프를 생성 합니다.
약 5~10 분이 지나면 아래와 같은 그래프를 볼수 있습니다.