[Up]常用資訊

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

2020年6月1日 星期一

[Debian] 使用 TIG 安裝 在Debian 10上

[Debian] 使用 TIG 安裝 在Debian 10上

 
#Step: 01 – TIG 安裝 在Debian 10上
說明


Debian 10(buster)
Step 1 - Install InfluxDB

curl -sL https://repos.influxdata.com/influxdb.key | apt-key add -

fot Debian 10
echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

apt update
apt install influxdb -y 

systemctl start influxdb
systemctl enable influxdb


Step 2 - Create InfluxDB Database and User

influx

create database telegraf
create user telegraf with password 'Str0nGPass'

show databases
show users

Step 3 - Install Telegraf Agent

apt install telegraf -y

sudo systemctl start telegraf
sudo systemctl enable telegraf


##

[global_tags]


# Configuration for telegraf agent
[agent]
    interval = "10s"
    debug = false
#    hostname = "server-hostname"
    hostname = ""
    round_interval = true
    flush_interval = "10s"
    flush_jitter = "0s"
    collection_jitter = "0s"
    metric_batch_size = 1000
    metric_buffer_limit = 10000
    quiet = false
    logfile = ""
    omit_hostname = false
	precision = ""

###############################################################################
#                                  OUTPUTS                                    #
###############################################################################

[[outputs.influxdb]]
    urls = ["http://127.0.0.1:8086"]
    database = "telegraf"
    timeout = "0s"
    username = "telegraf"
    password = "Str0nGPass"
    retention_policy = ""

###############################################################################
#                                  INPUTS                                     #
###############################################################################

[[inputs.cpu]]
    percpu = true
    totalcpu = true
    collect_cpu_time = false
    report_active = false
[[inputs.disk]]
  ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
[[inputs.diskio]]
[[inputs.io]]
[[inputs.mem]]
[[inputs.net]]
[[inputs.system]]
[[inputs.swap]]
[[inputs.netstat]]
[[inputs.processes]]
[[inputs.kernel]]

  
  
Step 6 - Install Grafana

apt-get install -y software-properties-common

curl https://packagecloud.io/gpg.key | apt-key add -

add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"

wget -q -O - https://packages.grafana.com/gpg.key | apt-key add -
 
rm /etc/apt/sources.list.d/grafana_stable.list
 
apt update
apt install grafana -y

netstat -plntu

apt install nginx -y

systemctl restart nginx.service

systemctl restart grafana-server.service

netstat -plntu

修改  vi /etc/grafana/grafana.ini

# ;root_url = %(protocol)s://%(domain)s:%(http_port)s/
to
# root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/

vi /etc/nginx/sites-available/default

 55     location /grafana/ {
 56     ¦   proxy_pass http://localhost:3000/;
 57     ¦   proxy_set_header Host $host;
 58     ¦   proxy_set_header X-Real-IP $remote_addr;
 59     ¦   proxy_set_header X-Forwarded-Host $host;
 60     ¦   proxy_set_header X-Forwarded-Server $host;
 61     ¦   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 62     }

新增 html

vi /var/www/html/index.html





<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="refresh" content="0;url=./grafana/" />
  </head>
  <body>
    <p>Please follow <a href="./grafana#feature">this link</a>.</p>
  </body>
</html>

##

#!/bin/bash

ip="$1"

hostname=`hostname`

mtr='mtr --no-dns -4 --report'
fields='trace_ip loss   snt   last   avg  best  wrst stdev'

timetamp=`date -d now +"%s%N"`

$mtr ${ip} |grep -v '???'|grep -Ev 'Start|Loss'|\
awk '{$1="";print}'|\
while read ${fields}
do
    echo "mtr,hostname=${hostname},domain=${ip},trace_ip=${trace_ip} loss=${loss},snt=${snt},last=${last},avg=${avg},best=${best},wrst=${wrst},stdev=${stdev} ${timetamp}"
done|sed 's/%//g'

##



<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="refresh" content="0;url=./grafana/" />
  </head>
  <body>
    <p>Please follow <a href="./grafana#feature">this link</a>.</p>
  </body>
</html>
 
# nginx 設定檔
說明


##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
#server {
#       listen 80 default_server;
#       listen [::]:80 default_server;
server {
        listen 80 default_server;
        listen [::]:80 default_server;

  # 導向至 HTTPS
  rewrite ^(.*) https://$host$1 permanent;
}
server {
  # SSL 設定
  listen 443 ssl default_server;
  listen [::]:443 ssl default_server;

  # 憑證與金鑰的路徑
  ssl_certificate /etc/nginx/ssl/nginx.crt;
  ssl_certificate_key /etc/nginx/ssl/nginx.key;
  client_max_body_size 100M;
        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

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

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

#
    location /grafana/ {
        proxy_pass http://localhost:3000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

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


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

沒有留言:

張貼留言