如何在CentOS 8上安裝Matomo(Piwik)Web Analytics
如何在CentOS 8上安裝Matomo(Piwik)Web Analytics
Matomo(以前稱為Piwik)是用於Linux操作系統的開源分析應用程序。這與Google Analytics(分析)非常相似,可幫助您跟蹤和查看訪問。它是由一組在PHP / MySQL Web服務器上運行的國際開發人員開發的。它提供了許多功能,下面列出了其中的一些功能:
- 靈活性,可靠性,安全性
- 自託管,簡單易用
- 100%的數據所有權
- 符合GDPR
- 網絡和移動分析
本教程向您展示如何在CentOS 8服務器上安裝和設置Piwik分析應用程序。
先決條件
- 運行CentOS的服務器8。
- 指向服務器IP的有效域名。
- 根密碼由服務器組成。
安裝LAMP服務器
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 mariadbsystemctl start httpdsystemctl enable mariadbsystemctl 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 Web根目錄:
cd /var/www/html
然後使用以下命令下載Piwik:
wget https://builds.matomo.org/matomo-latest.zip
下載完成後,使用以下命令解壓縮下載的文件。
unzip matomo-latest.zip
然後使用以下命令為Web根目錄設置適當的權限和所有權。
chown -R apache:apache /var/www/html/matomochmod -R 775 /var/www/html/matomo
完成後,您可以繼續下一步。
配置SELinux和防火牆
接下來,您需要允許端口80和443通過防火牆。您可以使用以下命令允許它們:
firewall-cmd --permanent --zone=public --add-service=httpfirewall-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
接下來,您需要配置Apache Web服務器來託管Piwik網站。您可以通過創建一個新的Apache虛擬主機配置文件來做到這一點:
nano /etc/httpd/conf.d/piwik.conf
添加以下行。
<VirtualHost *:80> ServerAdmin [email protected] 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 Web服務器以應用更改。
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 Web界面
然後打開Web瀏覽器,並使用URL訪問Piwik Web界面。 http://piwik.example.com..您將被重定向到下一頁。
請點擊 下一個,顯示系統檢查頁面。
請點擊 下一個,顯示數據庫設置頁面。
輸入您的數據庫用戶名,數據庫名和密碼,然後單擊。 下一個,顯示下一頁。
請點擊 下一個,顯示管理員用戶創建頁面。
輸入管理員的用戶名,密碼和電子郵件地址, 下一個.. 顯示網站設置頁面。
請提供您的網站的詳細信息,然後單擊 下一個..跟蹤代碼將顯示在下一頁。
請點擊 下一個..安裝完成後。顯示下一頁。
請點擊 繼MATOMO.. 顯示MATOMO登錄頁面。
輸入管理員用戶名和密碼, 登入.. MATOMO儀錶板顯示在下一頁上。
讓我們用SSL加密保護Matomo
接下來,您需要在系統上安裝Certbot實用程序,以下載和安裝Piwik網站的Let’s Encrypt SSL。
您可以使用以下命令安裝Certbot客戶端:
wget https://dl.eff.org/certbot-automv certbot-auto /usr/local/bin/certbot-autochown root /usr/local/bin/certbot-autochmod 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): [email protected]om - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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
目前,該網站已由“讓我們加密SSL”保護。
恭喜您得出結論!您已經使用Apache和Let’s Encrypt SSL在CentOS 8上成功安裝並設置了Piwik。您現在可以將跟蹤代碼添加到您的網站,並開始從Piwik儀錶板監視網站訪問者。如有任何疑問,請隨時與我們聯繫。