[Up]常用資訊

[重點文章] 重點文章 [重點文章] 重點文章

2020年5月26日 星期二

[Debian] 如何安裝 cacti 監控伺服器在 debian 和 nginx

[Debian] 如何安裝 cacti 監控伺服器在 debian 和 nginx

 
#Step: 01 – 更新系統

sudo apt udpate 
 
#Step: 02 – 安裝所需套件

apt install software-properties-common
apt install nginx
apt install curl vim acl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full python-memcache python-mysqldb snmp snmpd whois php-snmp rrdtool librrds-perl
 
#Step: 03 – 安裝 php 和 php 延伸套件


apt -y install php php-common
apt -y install php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd  php-mbstring php-curl php-xml php-pear php-bcmath php-gmp php-ldap

 
#Step: 04 – 設定資料庫
安裝部分已經設定


sudo systemctl enable mysql
sudo systemctl restart mysql
sudo mysql -u root -p


CREATE DATABASE cacti;
CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'Your_strong_password';
GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost';
FLUSH PRIVILEGES;
EXIT

mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql

登入
mysql -u root -p

Give Permissions to the cacti user.

GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
 ALTER DATABASE cacti CHARACTER SET = 'utf8mb4'  COLLATE = 'utf8mb4_unicode_ci'
 flush privileges;
 exit


vim /etc/mysql/mariadb.conf.d/50-server.cnf

[mysqld]
 ……..
collation-server = utf8mb4_unicode_ci
init-connect = 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci'
character-set-server  = utf8mb4
max_heap_table_size = 128M
tmp_table_size = 256M
join_buffer_size = 256M
innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_buffer_pool_size = 2GB
innodb_buffer_pool_instances = 30
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16
innodb_io_capacity = 5000
innodb_io_capacity_max = 10000

 
要檢查下面是否有 相同 collation-server 設定

完成後請重新啟動 

systemctl restart mysql

 
#Step: 05 – 設定 php 加速器

vi /etc/php/7.3/fpm/php.ini
和
/etc/php/7.3/cli/php.ini
設定時間選項

date.timezone = Asia/Taipei

systemctl restart php7.3-fpm

[root@MiWiFi-R1D html]# cat index.php
 
#Step: 06 – 設定 Nginx Web 伺服器

vi /etc/nginx/sites-enabled/default
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html index.php;

        server_name _;
		
        access_log  /var/www/html/log/cactiacess.log;
        error_log   /var/www/html/log/cacti.log;
        charset utf-8;
        gzip on;
        gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
        location /api/v0 {
            try_files $uri $uri/ /api_v0.php?$query_string;
        }
        location ~ .php {
            include fastcgi.conf;
            fastcgi_split_path_info ^(.+.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        }
        location ~ /.ht {
            deny all;
        }
} 

#
確認後重啟 nginx

systemctl restart nginx 

 
#Step: 07 – 安裝 Cacti 和 cacti-spine


curl -O https://www.cacti.net/downloads/cacti-latest.tar.gz

tar -zxvf cacti-latest.tar.gz

sudo mv cacti-1* /var/www/html/
sudo mv /var/www/html/cacti-*/ /var/www/html/cacti

chown -R www-data:www-data /var/www/html

mysql -u root -p cacti < /var/www/html/cacti/cacti.sql

vi /var/www/html/cacti/include/config.php

修改以下資訊
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "Your_strong_password"; 
$database_port = "3306";
$database_ssl = false;

確認後重新啟動
systemctl restart nginx.

安裝 cacti-spine

---------------- On Debian 10 ---------------- 
# apt install build-essential dos2unix dh-autoreconf help2man libssl-dev librrds-perl libsnmp-dev libmariadb-dev libmariadbclient-dev -y
# apt install build-essential dos2unix dh-autoreconf help2man libssl-dev librrds-perl libsnmp-dev libmariadb-dev libmariadbclient-dev -y

# wget https://www.cacti.net/downloads/spine/cacti-spine-latest.tar.gz
# tar xfz cacti-spine-latest.tar.gz 
# cd cacti-spine-1.*/

安裝
# ./bootstrap 
# ./configure 
# make
# make install

修改 spine 權限

# chown root:root /usr/local/spine/bin/spine 
# chmod +s /usr/local/spine/bin/spine

vi /usr/local/spine/etc/spine.conf

DB_Host localhost
DB_Database cacti
DB_User cactiuser
DB_Pass Your_strong_password
DB_Port 3306
DB_PreG 0

 
#Step: 08 – 編輯排程檔案


$ vi /etc/crontab

*/1 * * * * www-data php /var/www/html/cacti/poller.php > /dev/null 2>&1

 
#Step: 09 – 設定 Cacti Dashboard

連接 網頁
http://IP/cacti/

進行安裝cacti 設定


ansible 範例

ssh-copy-id root@192.168.96.110
ssh 'root@192.168.96.110'

ansible -i hosts.yml -m shell -a "reboot" serverlab4

ansible -i hosts.yml -m apt -a "name=sudo" serverlab4

ansible-playbook -i hosts.yml deploy_Debian_host.yml -e VMhost=serverlab4

沒有留言:

張貼留言