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 분이 지나면 아래와 같은 그래프를 볼수 있습니다.

 

 

 

 

 

Centos7 LEMP install

Nginx php mariadb install

 

 

nginx 설치전 system update 를 진행 합니다.

[root@centos74 ~]# yum update -y

 

 

nginx repo file 생성

[root@centos74 ~]# vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

참고페이지: http://nginx.org/en/linux_packages.html#stable

 

yum list 확인

[root@centos74 ~]# yum clean all && yum list
[root@centos74 ~]# yum search nginx
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.neowiz.com
 * extras: ftp.neowiz.com
 * updates: ftp.neowiz.com
============================================================================================================================= N/S matched: nginx ==============================================================================================================================
nginx-debug.x86_64 : debug version of nginx
nginx-debuginfo.x86_64 : Debug information for package nginx
nginx-module-geoip.x86_64 : nginx GeoIP dynamic modules
nginx-module-geoip-debuginfo.x86_64 : Debug information for package nginx-module-geoip
nginx-module-image-filter.x86_64 : nginx image filter dynamic module
nginx-module-image-filter-debuginfo.x86_64 : Debug information for package nginx-module-image-filter
nginx-module-njs.x86_64 : nginx nginScript dynamic modules
nginx-module-njs-debuginfo.x86_64 : Debug information for package nginx-module-njs
nginx-module-perl.x86_64 : nginx Perl dynamic module
nginx-module-perl-debuginfo.x86_64 : Debug information for package nginx-module-perl
nginx-module-xslt.x86_64 : nginx xslt dynamic module
nginx-module-xslt-debuginfo.x86_64 : Debug information for package nginx-module-xslt
nginx-nr-agent.noarch : New Relic agent for NGINX and NGINX Plus
pcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metrics for the Nginx Webserver
nginx.x86_64 : High performance web server

  Name and summary matches only, use "search all" for everything.
[root@centos74 ~]#

 

nginx 

nginx install

[root@centos74 ~]# yum install -y nginx

 

 php71 

php71 install

[root@centos74 ~]# yum install -y epel-release
[root@centos74 ~]# rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@centos74 ~]# yum clean all && yum list
[root@centos74 ~]# yum update -y
[root@centos74 ~]# init 6
[root@centos74 ~]# yum-config-manager --enable remi-php71
[root@centos74 ~]# yum install -y php php-opcache php-mysql php-fpm php-gd \
php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap curl curl-devel

 

mariadb

 

mariadb repo 확인 https://downloads.mariadb.org/mariadb/repositories/#mirror=kaist&distro=CentOS&distro_release=centos7-amd64–centos7&version=10.1

mariadb.repo 생성

[root@centos74 ~]# vi /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
[root@centos74 ~]# yum clean all && yum list

 

mariadb 10.1 설치

[root@centos74 ~]# yum install -y mariadb mariadb-server

 

mariadb 10.1 start & enable 

[root@centos74 ~]# systemctl start mariadb.service
[root@centos74 ~]# systemctl enable mariadb.service

 

mariadb secure_installation 실행

[root@centos74 ~]# /usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] y
 ... 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? [Y/n] y
 ... Success!

By default, MariaDB 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? [Y/n] y
 - 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? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@centos74 ~]#

 

nginx 

 

nginx enable & start

[root@centos74 ~]# systemctl enable nginx
[root@centos74 ~]# systemctl start nginx

 

nginx 동작 확인

[root@centos74 ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2017-12-24 13:57:28 KST; 2min 16s ago
     Docs: http://nginx.org/en/docs/
 Main PID: 27786 (nginx)
   CGroup: /system.slice/nginx.service
           ├─27786 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           └─27787 nginx: worker process

Dec 24 13:57:28 centos74 systemd[1]: Starting nginx - high performance web server...
Dec 24 13:57:28 centos74 nginx[27782]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Dec 24 13:57:28 centos74 nginx[27782]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Dec 24 13:57:28 centos74 systemd[1]: Started nginx - high performance web server.
[root@centos74 ~]#

 

접속 확인

 

nginx 설정

nginx.conf 파일 

위치: /etc/nginx/nginx.conf (nginx main 설정 파일)

[root@centos74 nginx]# cat nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
[root@centos74 nginx]#

 

 

 

default.conf 파일

위치: /etc/nginx/conf.d/default.conf (nginx Default Server 설정 파일)

추가 도메인이 있을경우 /etc/nginx/conf.d/ 디렉토리에 $file_name.conf 로 파일을 생성하시면 됩니다.

[root@centos74 ~]# cat /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #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;
    }


    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


[root@centos74 ~]#

sock 방식을 사용할 경우 해당 라인의 주석을 제거합니다. fastcgi_pass unix:/run/php-fpm/php-fpm.sock;

www.conf 파일을  listen = /run/php-fpm/php-fpm.sock; 로 listen = 127.0.0.1:9000 라인을 수정 해야 합니다.

 

php-fpm 설정

[root@centos74 html]# vi /etc/php-fpm.d/www.conf
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx


listen.owner = nginx
listen.group = nginx
listen.mode = 0666
[root@centos74 ~]# systemctl enable php-fpm.service
[root@centos74 ~]# systemctl start php-fpm.service
[root@centos74 ~]# systemctl restart nginx

 

phpinfo() 확인

[root@centos74 ~]# vi /usr/share/nginx/html/info.php
<?php phpinfo(); ?>

 

 

VirtualHost 

default 파일 수정

[root@centos74 ~]# vi /etc/nginx/conf.d/default.conf
server {
    listen       80 default_server;
    server_name  localhost;

 

/etc/nginx/sites-enabled 디렉토리 생성 없이 /etc/nginx/conf.d 디렉토리에 $domain.conf 파일로 생성 합니다.

test2.com 파일을 생성 합니다.

[root@centos74 ~]# vi /etc/nginx/conf.d/test2.conf
server {
    listen       80;
    server_name  www.test2.com test2.com;
    root   /var/www/test2.com;
    index  index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        autoindex on;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /var/www/test2.com;
    }

    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;
    }
}

 

test2.com 의 root 디렉토리는 /home/test/public_html 입니다.

phpinfo 페이지 파일을 생성 합니다.

[root@centos74 ~]# vi /var/www/test2.com/test.php
<?php phpinfo(); ?>

 

nginx 재시작후 확인 합니다.

[root@centos74 ~]# systemctl restart nginx