Ubuntu 22.04에서 흑연 모니터링 시스템을 설치 및 구성하는 방법
이 페이지에서
- 전제 조건
- 1단계 - 방화벽 구성\n
- 2단계 - 필수 패키지 설치\n
- 3단계 - Graphite 및 Graphite 웹 설치
- 4단계 - PostgreSQL 설치 및 구성
- 5단계 - Graphite Carbon 및 웹 구성
- 탄소 구성
- 그래파이트 웹 구성
Graphite는 컴퓨터 시스템의 성능을 추적하고 그래프로 표시하는 데 사용되는 오픈 소스 도구입니다. 이를 사용하여 웹 사이트, 애플리케이션, 비즈니스 서비스 및 네트워크 서버의 성능을 추적할 수 있습니다. 매우 유연하며 추적 중인 메트릭의 성능 및 상태에 대한 자세한 표현과 광범위한 개요의 이점을 모두 얻을 수 있도록 구성할 수 있습니다.
Graphite는 웹 애플리케이션, Carbon이라는 스토리지 백엔드, 그리고 귓속말이라는 데이터베이스 라이브러리 등 여러 구성 요소로 구성됩니다. 이 튜토리얼에서는 Ubuntu 22.04 서버에 Graphite를 설치하고 구성하는 방법을 배웁니다.
전제 조건
-
A server running Ubuntu 22.04.
-
A Fully Qualified domain name (FQDN) pointing to the server. For our tutorial, we will use the
graphite.example.com
domain. -
A non-root user with sudo privileges.
-
The uncomplicated Firewall(UFW) is enabled and running.
-
Make sure everything is updated.
$ sudo apt update && sudo apt upgrade
-
Install basic utility packages. Some of them may already be installed.
$ sudo apt install wget curl nano unzip -y
1단계 - 방화벽 구성
패키지를 설치하기 전에 첫 번째 단계는 HTTP 및 HTTPS 연결을 허용하도록 방화벽을 구성하는 것입니다.
방화벽의 상태를 확인하십시오.
$ sudo ufw status
다음과 같은 내용이 표시되어야 합니다.
Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6)
HTTP 및 HTTP 포트를 허용합니다.
$ sudo ufw allow http $ sudo ufw allow https
상태를 다시 확인하여 확인하십시오.
$ sudo ufw status Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere 80/tcp ALLOW Anywhere 443 ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) 80/tcp (v6) ALLOW Anywhere (v6) 443 (v6) ALLOW Anywhere (v6)
2단계 - 필수 패키지 설치
PIP Python 패키지 관리자를 사용하여 Graphite를 설치합니다. 첫 번째 단계는 설치에 필요한 패키지를 설치하는 것입니다.
$ sudo apt install vim python3-dev python3-pip libcairo2-dev libffi-dev build-essential
3단계 - Graphite 및 Graphite 웹 설치
/opt/graphite
디렉토리에 Graphite를 설치합니다.$ export PYTHONPATH="/opt/graphite/lib/:/opt/graphite/webapp/" $ sudo pip install --no-binary=:all: https://github.com/graphite-project/whisper/tarball/master $ sudo pip install --no-binary=:all: https://github.com/graphite-project/carbon/tarball/master $ sudo pip install --no-binary=:all: https://github.com/graphite-project/graphite-web/tarball/master
4단계 - PostgreSQL 설치 및 구성
PostgreSQL의 공식 APT 리포지토리를 사용하여 설치합니다. 다음 명령을 실행하여 PostgreSQL GPG 키를 추가합니다.
$ curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /usr/share/keyrings/postgresql-key.gpg >/dev/null
소스 목록에 APT 저장소를 추가하십시오.
$ sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/postgresql-key.gpg arch=amd64] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
시스템 저장소를 업데이트하십시오.
$ sudo apt update
이제 다음 명령을 사용하여 PostgreSQL 및 도우미 패키지를 설치할 수 있습니다.
$ sudo apt install postgresql postgresql-contrib libpq-dev
PostgreSQL 서비스의 상태를 확인하십시오.
$ sudo systemctl status postgresql ? postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) Active: active (exited) since Tue 2022-09-27 10:09:35 UTC; 4s ago Process: 4456 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 4456 (code=exited, status=0/SUCCESS) CPU: 1ms Sep 27 10:09:35 matrix systemd[1]: Starting PostgreSQL RDBMS... Sep 27 10:09:35 matrix systemd[1]: Finished PostgreSQL RDBMS.
서비스가 기본적으로 활성화되어 실행되고 있음을 알 수 있습니다.
PostgreSQL 셸에 로그인합니다.
$ sudo -su postgres psql
Graphite에 대한 데이터베이스 사용자를 생성합니다.
postgres=# CREATE USER graphite WITH PASSWORD 'your_password';
Graphite용 데이터베이스를 생성하고 Graphite 사용자에게 소유권을 부여합니다.
postgres=# CREATE DATABASE graphitedb WITH OWNER graphite;
PostgreSQL 셸을 종료합니다.
postgres=# \q
5단계 - Graphite Carbon 및 웹 구성
다음 단계는 Graphite Carbon 및 Graphite web을 구성하는 것입니다.
탄소 구성
Carbon은 세 가지 서비스로 구성됩니다.
- carbon-cache: 메트릭을 받아 디스크에 기록합니다.\n
- carbon-relay: 데이터를 복제합니다.\n
- carbon-aggregator: Carbon-cache 서비스 앞에서 실행되어 Whisper로 전달하기 전에 메트릭을 버퍼링합니다.\n
carbon-cache 설정은 필수이고 carbon-relay와 carbon-aggregator는 선택 사항입니다.
주어진 예제 파일을 사용하여
carbon.conf
파일을 생성합니다.$ sudo cp /opt/graphite/conf/carbon.conf.example /opt/graphite/conf/carbon.conf
다음으로 스토리지 스키마 구성을 생성합니다.
$ sudo cp /opt/graphite/conf/storage-schemas.conf.example /opt/graphite/conf/storage-schemas.conf
스토리지 스키마 구성 파일을 엽니다.
$ sudo nano /opt/graphite/conf/storage-schemas.conf
내부에는 다음과 같은 항목이 있습니다.
[carbon] pattern = ^carbon\. retentions = 60:90d
이는
^carbon\\.
정규식과 일치하는 패턴이 보존 정책 60:90d로 데이터를 보존해야 함을 의미합니다.- 측정항목이 기록되는 빈도: 60초\n
- 해당 값을 저장하는 기간: 90일\n
자신의 항목을 추가할 수 있습니다.
test
예를 들어 보겠습니다. 즉, 모니터링 데이터 포인트와 데이터 포인트 항목은test
문자열로 시작합니다. 이 항목은 파일 맨 아래에 언급된 기본 항목 앞에 추가해야 합니다.[test] pattern = ^test\. retentions = 10s:10m,1m:1h
이는
test
로 시작하는 모든 메트릭과 일치합니다. 수집한 데이터를 다양한 세부 정보로 두 번 저장합니다. 첫 번째 정의(1s:10m)는 10초마다 데이터 포인트를 생성합니다. 10분 동안만 데이터를 저장합니다. 두 번째 정의는 1분마다 데이터 포인트를 생성합니다. 지난 1분 동안의 모든 데이터(이전 정의가 10초마다 포인트를 생성하므로 6개 포인트)를 수집하고 집계하여 포인트를 생성합니다. 한 시간 동안 이 세부 수준으로 데이터를 저장합니다.Ctrl + X를 누르고 메시지가 표시되면 Y를 입력하여 파일을 저장합니다.
carbon-cache
서비스를 시작합니다.$ sudo /opt/graphite/bin/carbon-cache.py start
흑연 웹 구성
다음 단계는 Graphite 웹 앱을 구성하는 것입니다.
Graphite 애플리케이션의 비밀 키를 생성합니다. 나중에 사용할 수 있도록 표시된 키를 복사합니다.
$ python3 -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())' sp%71)6b$%^bc(7xpz1d!)x3(azog01&k^8l02*!y0#)72p07y
웹앱 설정 파일을 만듭니다.
$ sudo cp /opt/graphite/webapp/graphite/local_settings.py.example /opt/graphite/webapp/graphite/local_settings.py
데이터베이스 설정으로 Graphite 웹 애플리케이션을 구성해야 합니다. 편집을 위해
local_settings.py
를 엽니다.$ sudo nano /opt/graphite/webapp/graphite/local_settings.py
SECRET_KEY
변수의 주석을 제거하고 임의의 값을 입력하십시오.SECRET_KEY = 'your-secret-key'
ALLOWED_HOSTS
변수의 주석 처리를 제거하십시오.ALLOWED_HOSTS = [ '*' ]
TIME_ZONE
변수의 주석을 해제하고 적절한 값으로 설정합니다.TIME_ZONE = 'Asia/Kolkata'
USE_REMOTE_USER_AUTHENTICATION
변수의 주석 처리를 제거하고TRUE
로 설정하여 데이터베이스를 변경하기 전에 원격 사용자가 인증되도록 합니다.USE_REMOTE_USER_AUTHENTICATION = True
데이터베이스 설정을 변경합니다.
DATABASES = { 'default': { 'NAME': 'graphitedb', 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'USER': 'graphite', 'PASSWORD': 'your_password', 'HOST': '127.0.0.1', 'PORT': '' } }
Ctrl + X를 누르고 메시지가 표시되면 Y를 입력하여 파일을 저장합니다.
Pythons PostgreSQL 래퍼에 대한 몇 가지 필수 구성 요소를 설치합니다.
$ sudo pip install psycopg2-binary
다음 명령을 실행하여 데이터베이스 스키마를 가져옵니다.
$ sudo PYTHONPATH=/opt/graphite/webapp/ django-admin.py migrate --settings=graphite.settings
다음과 같은 결과가 표시됩니다.
Operations to perform: Apply all migrations: account, admin, auth, contenttypes, dashboard, events, sessions, tagging, tags, url_shortener Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying account.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying admin.0003_logentry_add_action_flag_choices... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying auth.0009_alter_user_last_name_max_length... OK Applying auth.0010_alter_group_name_max_length... OK Applying auth.0011_update_proxy_permissions... OK Applying auth.0012_alter_user_first_name_max_length... OK Applying dashboard.0001_initial... OK Applying events.0001_initial... OK Applying sessions.0001_initial... OK Applying tagging.0001_initial... OK Applying tagging.0002_on_delete... OK Applying tags.0001_initial... OK Applying url_shortener.0001_initial... OK
다음으로 정적 파일을 수집합니다.
$ sudo PYTHONPATH=/opt/graphite/webapp/ django-admin.py collectstatic --settings=graphite.settings
올바른 소유권 설정을 지정합니다.
$ sudo chown -R www-data:www-data /opt/graphite/storage/ $ sudo chown -R www-data:www-data /opt/graphite/static/ $ sudo chown -R www-data:www-data /opt/graphite/webapp/
로그인을 위한 루트 사용자를 만듭니다.
$ sudo PYTHONPATH=/opt/graphite/webapp/ django-admin.py createsuperuser --settings=graphite.settings Username (leave blank to use 'root'): navjot Email address: Password: Password (again): Superuser created successfully.
수퍼유저를 생성하라는 메시지가 표시됩니다. 이 사용자는 나중에 Graphite 애플리케이션에 연결하는 데 사용됩니다.
6단계 - Apache 구성
Graphite는 기본적으로 Apache 구성 파일과 함께 제공됩니다. 아파치 서버를 설치합니다.
$ sudo apt install apache2 libapache2-mod-wsgi-py3
mod_wsgi
파일을 생성합니다.$ sudo cp /opt/graphite/conf/graphite.wsgi.example /opt/graphite/conf/graphite.wsgi
Graphite 예제 구성 파일을 Apache 위치에 복사합니다.
$ sudo cp /opt/graphite/examples/example-graphite-vhost.conf /etc/apache2/sites-available/graphite.conf
편집을 위해 Graphite 구성 파일을 엽니다.
$ sudo nano /etc/apache2/sites-available/graphite.conf
첫 번째 줄의 포트 번호를
80
에서127.0.0.1:8080
으로 변경합니다. 앞에127.0.0.1
을 넣으면 웹을 통해 액세스할 수 없습니다.<VirtualHost 127.0.0.1:8080>
도메인 이름을 추가합니다.
ServerName graphite.example.com #Replace with your domain
Alias /static/ /opt/graphite/static/
줄 아래에 다음 줄을 추가합니다.#Add below lines <Directory /opt/graphite/static/> Require all granted </Directory>
Ctrl + X를 누르고 메시지가 표시되면 Y를 입력하여 파일을 저장합니다.
기본 가상 호스트를 비활성화하고 Graphite 가상 호스트 파일을 활성화합니다.
$ sudo a2dissite 000-default $ sudo a2ensite graphite
또한 Nginx를 프록시 서버로 사용할 것이기 때문에 Apache에게 포트 8080을 수신하고 포트 80 수신을 중지하도록 지시해야 합니다.
편집을 위해
/etc/apache2/ports.conf
파일을 엽니다.$ sudo nano /etc/apache2/ports.conf
Listen 80
줄을 찾아 다음으로 바꿉니다.Listen 127.0.0.1:8080
Ctrl + X를 누르고 메시지가 표시되면 Y를 입력하여 파일을 저장합니다.
아파치 서버를 다시 시작하십시오.
$ sudo systemctl restart apache2
Graphite가 제대로 작동하고 액세스 가능한지 확인하려면 다음 명령을 실행하십시오.
$ curl 127.0.0.1:8080
다음과 같은 결과가 표시됩니다.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> <!-- Copyright 2008 Orbitz WorldWide Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <html> <head> <title>Graphite Browser</title> </head> <frameset rows="80,*" frameborder="1" border="1"> <frame src="/browser/header" name="Header" id='header' scrolling="no" noresize="true" /> <frame src="/composer?" name="content" id="composerFrame"/> </frameset> </html>
이것은 잘 작동하고 있음을 확인합니다.
7단계 - Nginx 설치
Nginx를 Apache의 프록시 서버로 사용합니다. 이렇게 하면 Graphite에서 제공하는 기존 구성을 사용하는 동안 보안 및 모호성의 이점을 얻을 수 있습니다.
Ubuntu 22.04는 이전 버전의 Nginx와 함께 제공됩니다. 최신 버전을 설치하려면 공식 Nginx 저장소를 다운로드해야 합니다.
Nginxs 서명 키를 가져옵니다.
$ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \ | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
Nginxs 안정 버전용 리포지토리를 추가합니다.
$ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg arch=amd64] \ http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list
시스템 리포지토리를 업데이트합니다.
$ sudo apt update
Nginx를 설치합니다.
$ sudo apt install nginx
설치를 확인하십시오.
$ nginx -v nginx version: nginx/1.22.0
Nginx 서버를 시작합니다.
$ sudo systemctl start nginx
8단계 - SSL 설치
SSL 인증서를 생성하려면 Certbot을 설치해야 합니다. Ubuntus 저장소를 사용하여 Certbot을 설치하거나 Snapd 도구를 사용하여 최신 버전을 가져올 수 있습니다. 우리는 Snapd 버전을 사용할 것입니다.
Ubuntu 22.04는 기본적으로 Snapd가 설치된 상태로 제공됩니다. 다음 명령을 실행하여 Snapd 버전이 최신인지 확인하십시오.
$ sudo snap install core $ sudo snap refresh core
Certbot을 설치합니다.
$ sudo snap install --classic certbot
다음 명령을 사용하여
/usr/bin
디렉토리에 대한 심볼릭 링크를 생성하여 Certbot 명령을 실행할 수 있는지 확인하십시오.$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
다음 명령을 실행하여 SSL 인증서를 생성합니다.
$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m -d graphite.example.com
위의 명령은 서버의
/etc/letsencrypt/live/graphite.example.com
디렉토리에 인증서를 다운로드합니다.Diffie-Hellman 그룹 인증서를 생성합니다.
$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096
Certbot 갱신 스케줄러 서비스를 확인하십시오.
$ sudo systemctl list-timers
실행 예정인 서비스 중 하나로
snap.certbot.renew.service
를 찾을 수 있습니다.NEXT LEFT LAST PASSED UNIT ACTIVATES ................................................................................................................................. Wed 2022-09-28 00:00:00 UTC 7h left Tue 2022-09-27 00:00:01 UTC 16h ago logrotate.timer logrotate.service Wed 2022-09-28 02:39:09 UTC 10h left Tue 2022-09-27 09:42:42 UTC 6h ago apt-daily.timer apt-daily.service Wed 2022-09-28 06:02:00 UTC 13h left n/a n/a snap.certbot.renew.timer snap.certbot.renew.service
SSL 갱신이 제대로 작동하는지 확인하려면 프로세스를 시험 실행하십시오.
$ sudo certbot renew --dry-run
오류가 표시되지 않으면 모든 설정이 완료된 것입니다. 인증서가 자동으로 갱신됩니다.
9단계 - Nginx 구성
편집을 위해
/etc/nginx/nginx.conf
파일을 엽니다.$ sudo nano /etc/nginx/nginx.conf
include /etc/nginx/conf.d/*.conf;
줄 앞에 다음 줄을 추가합니다.server_names_hash_bucket_size 64;
Ctrl + X를 누르고 메시지가 표시되면 Y를 입력하여 파일을 저장합니다.
편집을 위해
/etc/nginx/conf.d/uvdesk.conf
파일을 만들고 엽니다.$ sudo nano /etc/nginx/conf.d/graphite.conf
다음 코드를 붙여넣습니다.
server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name graphite.example.com; access_log /var/log/nginx/graphite.access.log; error_log /var/log/nginx/graphite.error.log; # SSL ssl_certificate /etc/letsencrypt/live/graphite.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/graphite.example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/graphite.example.com/chain.pem; ssl_session_timeout 5m; ssl_session_cache shared:MozSSL:10m; ssl_session_tickets off; ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1; ssl_stapling on; ssl_stapling_verify on; ssl_dhparam /etc/ssl/certs/dhparam.pem; resolver 8.8.8.8; location / { proxy_set_header Connection "upgrade"; proxy_set_header Upgrade $http_upgrade; proxy_http_version 1.1; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:8080; proxy_redirect off; } } # enforce HTTPS server { listen 80; listen [::]:80; server_name graphite.example.com; return 301 https://$host$request_uri; }
완료되면 Ctrl + X를 누르고 프롬프트가 표시되면 Y를 입력하여 파일을 저장합니다.
Nginx 구성 파일 구문을 확인합니다.
$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Nginx 서비스를 다시 시작합니다.
$ sudo systemctl restart nginx
10단계 - Graphite 액세스 및 사용
브라우저에서 URL
https://graphite.example.com
을 방문하면 다음 화면이 나타납니다.오른쪽 상단의 로그인 링크를 클릭하여 로그인 페이지를 엽니다. 5단계에서 만든 수퍼유저 자격 증명을 입력하고 로그인 버튼을 눌러 계속 진행합니다.
Graphite에 데이터를 공급하는 방법에는 여러 가지가 있습니다. 스토리지 스키마에 패턴 매처를 추가했으며, 이에 따라 테스트로 시작하는 모든 패턴이 패턴으로 기록됩니다. 다음 명령을 사용하여 임의의 데이터를 추가해 보겠습니다.
$ echo "test.count 9 `date +%s`" | nc -q0 127.0.0.1 2003;
이렇게 하면 값이 9인 하나의 데이터 메트릭이 시스템에 추가됩니다. 값을 반복하여 데이터를 더 추가해 보겠습니다.
$ for i in 4 6 8 16 2; do echo "test.count $i `date +%s`" | nc -q0 127.0.0.1 2003; sleep 6; done
Graphite 대시보드로 돌아가 왼쪽 사이드바에서 Metrics >> test >> count를 엽니다. 다음과 같은 내용이 표시되어야 합니다.
이제 모니터링에 사용할 수 있습니다. Grafana와 결합하여 높은 수준의 사용자 정의를 얻을 수도 있습니다.
결론
Nginx를 프록시 서버로 사용하여 Ubuntu 22.04 서버에 Graphite를 설치하고 구성하는 방법에 대한 자습서를 마칩니다. 질문이 있으시면 아래 의견에 게시하십시오.