웹사이트 검색

CentOS 8에 Matomo(Piwik) 웹 분석을 설치하는 방법


이 페이지에서

  1. 전제 조건
  2. LAMP 서버 설치
  3. Piwik용 데이터베이스 생성
  4. Piwik 설치
  5. SELinux 및 방화벽 구성\n
  6. Piwik용 Apache 구성
  7. Piwik 웹 인터페이스 액세스
  8. Lets Encrypt SSL로 Matomo 보호\n

이전에 Piwik으로 알려진 Matomo는 Linux 운영 체제용 오픈 소스 분석 애플리케이션입니다. 사용자 방문 위치를 추적하고 표시하는 데 도움이 되는 Google Analytics와 매우 유사합니다. PHP/MySQL 웹 서버에서 실행되는 국제 개발자 팀이 개발했습니다. 많은 기능을 제공하며 그 중 일부는 다음과 같습니다.

  • 유연성, 신뢰성 및 보안
  • 자체 호스팅, 단순하고 사용하기 쉬움\n
  • 100% 데이터 소유권
  • GDPR 준수
  • 웹 및 모바일 분석

이 튜토리얼에서는 CentOS 8 서버에 Piwik 분석 애플리케이션을 설치하고 설정하는 방법을 보여줍니다.

전제 조건

  • CentOS 8을 실행하는 서버.\n
  • 서버 IP를 가리키는 유효한 도메인 이름입니다.\n
  • 서버에 루트 암호가 구성되어 있습니다.\n

램프 서버 설치

Piwik은 LAMP 서버에서 실행되므로 시스템에 Apache, MariaDB, PHP 및 기타 PHP 확장을 설치해야 합니다. 다음 명령으로 모두 설치할 수 있습니다.

dnf install httpd mariadb-server php php-mysqlnd php-fpm unzip wget php-json php-dom php-gd php-mbstring -y

모든 패키지가 설치되면 php.ini 파일을 편집하고 원하는 값을 설정합니다.

nano /etc/php.ini

다음 값을 변경합니다.

upload_max_filesize = 10M
post_max_size = 10M
max_execution_time = 300
max_input_time = 300
memory_limit = 256M

파일을 저장하고 닫은 다음 Apache 및 MariaDB 서비스를 시작하고 시스템 재부팅 시 시작할 수 있도록 활성화합니다.

systemctl start mariadb
systemctl start httpd
systemctl enable mariadb
systemctl enable httpd

Piwik용 데이터베이스 생성

다음으로 Piwik용 데이터베이스와 사용자를 생성해야 합니다. 먼저 다음 명령을 사용하여 MariaDB에 로그인합니다.

mysql

로그인 후 다음 명령을 사용하여 데이터베이스와 사용자를 생성합니다.

mysql> CREATE DATABASE matomo;
mysql> CREATE USER `matomo`@`localhost` IDENTIFIED BY 'password';

다음으로 다음 명령을 사용하여 데이터베이스에 대한 모든 권한을 부여합니다.

mysql> GRANT ALL ON matomo.* TO `matomo`@`localhost`;

다음으로 다음 명령을 사용하여 권한을 플러시하고 MariaDB를 종료합니다.

mysql> FLUSH PRIVILEGES;
mysql> EXIT;

Piwik 설치

다음으로 공식 웹사이트에서 최신 버전의 Piwik을 다운로드해야 합니다. 먼저 다음 명령을 사용하여 디렉터리를 Apache 웹 루트로 변경합니다.

cd /var/www/html

다음으로 다음 명령을 사용하여 Piwik을 다운로드합니다.

wget https://builds.matomo.org/matomo-latest.zip

다운로드가 완료되면 다음 명령을 사용하여 다운로드한 파일의 압축을 풉니다.

unzip matomo-latest.zip

그런 다음 다음 명령을 사용하여 웹 루트에 적절한 권한과 소유권을 설정합니다.

chown -R apache:apache /var/www/html/matomo
chmod -R 775 /var/www/html/matomo

완료되면 다음 단계로 진행할 수 있습니다.

SELinux 및 방화벽 구성

다음으로 방화벽을 통해 포트 80 및 443을 허용해야 합니다. 다음 명령으로 허용할 수 있습니다.

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https

다음으로 방화벽을 다시 로드하여 변경 사항을 적용합니다.

firewall-cmd --reload

다음으로 Piwik용 SELinux도 설정해야 합니다. 다음 명령으로 설정할 수 있습니다.

chcon -R -t httpd_sys_rw_content_t /var/www/html/matomo/
setsebool httpd_can_network_connect on -P

완료되면 다음 단계로 진행할 수 있습니다.

Piwik용 Apache 구성

다음으로 Piwik 웹사이트를 호스팅하도록 Apache 웹 서버를 구성해야 합니다. 새 Apache 가상 호스트 구성 파일을 생성하여 이를 수행할 수 있습니다.

nano /etc/httpd/conf.d/piwik.conf

다음 줄을 추가합니다.

<VirtualHost *:80>
ServerAdmin 
DocumentRoot "/var/www/html/matomo"
ServerName piwik.example.com
<Directory "/var/www/html/matomo/">
Options MultiViews FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
TransferLog /var/log/httpd/matomo_access.log
ErrorLog /var/log/httpd/matomo_error.log

</VirtualHost>

완료되면 파일을 저장하고 닫습니다. 그런 다음 Apache 웹 서버를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart httpd

이제 다음 명령을 사용하여 Apache의 상태를 확인할 수 있습니다.

systemctl status httpd

다음 출력이 표시되어야 합니다.

? httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/httpd.service.d
           ??php-fpm.conf
   Active: active (running) since Sun 2020-12-27 05:38:29 EST; 5s ago
     Docs: man:httpd.service(8)
 Main PID: 4228 (httpd)
   Status: "Started, listening on: port 80"
    Tasks: 213 (limit: 12523)
   Memory: 36.8M
   CGroup: /system.slice/httpd.service
           ??4228 /usr/sbin/httpd -DFOREGROUND
           ??4229 /usr/sbin/httpd -DFOREGROUND
           ??4230 /usr/sbin/httpd -DFOREGROUND
           ??4231 /usr/sbin/httpd -DFOREGROUND
           ??4232 /usr/sbin/httpd -DFOREGROUND

Dec 27 05:38:28 centos8 systemd[1]: Stopped The Apache HTTP Server.
Dec 27 05:38:28 centos8 systemd[1]: Starting The Apache HTTP Server...

완료되면 다음 단계로 진행할 수 있습니다.

Piwik 웹 인터페이스에 액세스

이제 웹 브라우저를 열고 URL http://piwik.example.com을 사용하여 Piwik 웹 인터페이스에 액세스합니다. 다음 페이지로 리디렉션됩니다.

다음을 클릭하면 시스템 확인 페이지가 표시됩니다.

NEXT를 클릭하면 데이터베이스 설정 페이지가 표시됩니다.

데이터베이스 사용자 이름, 데이터베이스 이름, 암호를 제공하고 다음을 클릭하면 다음 페이지가 표시됩니다.

다음을 클릭하면 관리 사용자 생성 페이지가 표시됩니다.

관리자 사용자 이름, 비밀번호, 이메일을 제공하고 다음을 클릭하십시오. 웹사이트 설정 페이지가 표시됩니다.

웹사이트 세부 정보를 제공하고 다음을 클릭합니다. 다음 페이지에 추적 코드가 표시되어야 합니다.

다음을 클릭합니다. 일단 설치가 완료되었습니다. 다음 페이지가 표시됩니다.

CONTINUE TO MATOMO를 클릭합니다. MATOMO 로그인 페이지가 표시됩니다.

관리자 사용자 이름, 암호를 제공하고 로그인을 클릭합니다. 다음 페이지에서 MATOMO 대시보드를 볼 수 있습니다.

Lets Encrypt SSL로 Matomo 보호

다음으로 시스템에 Certbot 유틸리티를 설치하여 Piwik 웹사이트용 Lets Encrypt SSL을 다운로드하고 설치해야 합니다.

다음 명령을 사용하여 Certbot 클라이언트를 설치할 수 있습니다.

wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 0755 /usr/local/bin/certbot-auto

다음으로 다음 명령을 사용하여 Mantis 웹 사이트에 대한 SSL 인증서를 가져와 설치합니다.

certbot-auto --apache -d piwik.example.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y 


Obtaining a new certificate
Performing the following challenges:
http-01 challenge for piwik.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/httpd/conf.d/piwik.conf

다음으로 아래와 같이 HTTP 트래픽을 HTTPS로 리디렉션할지 여부를 선택해야 합니다.

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

2를 입력하고 Enter를 눌러 계속하십시오. 설치가 완료되면 다음 출력이 표시됩니다.

Redirecting all traffic on port 80 to ssl in /etc/httpd/conf.d/piwik.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://piwik.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=piwik.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/piwik.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/piwik.example.com/privkey.pem
   Your cert will expire on 2020-03-23. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot-auto renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

이 시점에서 귀하의 웹사이트는 Lets Encrypt SSL로 보호됩니다.

결론 축하합니다! CentOS 8에서 Apache와 Lets Encrypt SSL을 사용하여 Piwik을 성공적으로 설치 및 설정했습니다. 이제 웹사이트에 추적 코드를 추가하고 Piwik 대시보드에서 웹사이트 방문자 모니터링을 시작할 수 있습니다. 궁금한 점이 있으면 언제든지 문의해 주세요.