Basic Environment#
System Environment:
Operating System: CentOS Stream 9
Software Environment:
Docker, Docker Compose
Install Docker#
(1) Install the yum-utils package (provides the yum-config-manager utility) and set up the repository.
# Install yum-utils package
yum install -y yum-utils
# Set up docker-ce repository
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
(2) Install the latest version of Docker and Docker Compose.
yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
(3) Change Docker's data directory to "/data/dockerData" and restart the Docker service to apply the configuration.
# Create Docker daemon configuration file
# Edit the configuration file /etc/docker/daemon.json to configure the Docker data directory
vi /etc/docker/daemon.json
**************************daemon.json**************************
{
"data-root": "/data/dockerData"
}
**************************daemon.json**************************
# Restart the Docker service to apply the configuration
[root@Book-ELK-VM-113 data]# systemctl restart docker
(4) Start the Docker service and set it to start on boot.
# Start Docker service
systemctl start docker
# Set Docker to start on boot
systemctl enable docker
# Check Docker service status
systemctl status docker
Deploy and Configure Matomo#
Deploy Matomo#
(1) Create a script directory to store the yml file and orchestrate the deployment of Matomo.
mkdir /data/script
vi /data/script/matomo.yml
**************************matomo.yml**************************
services:
matomo-sql:
# Use MySQL database image
image: mysql:latest
# Container name
container_name: matomo-sql
# Container restart policy: always restart if the container stops
restart: always
# Configure environment variables
environment:
# Set database name
- MYSQL_DATABASE=matomo
# Set database username
- MYSQL_USER=matomo
# Set database user password
- MYSQL_PASSWORD=matomo
# Set database root user password
- MYSQL_ROOT_PASSWORD=matomo
# Set timezone
- TZ=Asia/Shanghai
# Exposed port mapping, mapping MySQL's 3306 port to the host
ports:
- "3306:3306"
# Mount the host directory to the container's MySQL data directory
volumes:
- /data/database/matomo-sql:/var/lib/mysql
# Run the container with root user privileges
user: "0"
# Network configuration
networks:
# Use custom network 'net'
net:
# Assign a fixed IPv4 address to the container
ipv4_address: 172.18.0.10
matomo-app:
# Use Matomo application image
image: matomo:latest
# Container name
container_name: matomo-app
# Container restart policy: always restart if the container stops
restart: always
# Link to MySQL database service
links:
- matomo-sql
# Mount the host directory to the Matomo application directory
volumes:
- /data/matomo:/var/www/html
# Set environment variables
environment:
# Set timezone
- TZ=Asia/Shanghai
# Specify database hostname as 'matomo-sql'
- MATOMO_DATABASE_HOST=matomo-sql
# Set PHP memory limit
- PHP_MEMORY_LIMIT=2048M
# Specify database adapter as MySQL
- MATOMO_DATABASE_ADAPTER=mysql
# Set database table prefix
- MATOMO_DATABASE_TABLES_PREFIX=matomo_
# Specify database username
- MATOMO_DATABASE_USERNAME=matomo
# Specify database user password
- MATOMO_DATABASE_PASSWORD=matomo
# Specify database name
- MATOMO_DATABASE_DBNAME=matomo
# Run the container with root user privileges
user: "0"
# Container port mapping, mapping Matomo's 80 port to the host
ports:
- "80:80"
# Network configuration
networks:
# Use custom network 'net'
net:
# Assign a fixed IPv4 address to the container
ipv4_address: 172.18.0.11
# Custom network configuration
networks:
# Define custom network 'net'
net:
# Use bridge network driver
driver: bridge
# IP address management configuration
ipam:
config:
# Set subnet for custom network
- subnet: 172.18.0.0/24
**************************matomo.yml**************************
(2) Execute Docker Compose to create the containers and check the currently running Docker containers.
docker compose -f /data/script/matomo.yml up -d
docker ps
Configure Matomo#
(1) Access http://local_ip
in a browser and follow the prompts to install.
(2) In the wizard's "3. Database Setup" interface, view and modify the database configuration information; the "Database Server" name here is the name of the database container.
(3) In the wizard's "5. Super User" interface, create a username, password, and email for the super user.
(4) In the wizard's "6. Set Up Website" interface, please set a site you want Matomo to track and analyze.
(5) In the wizard's "7. JavaScript Tracking Code" interface, copy the code snippet and add it to every page of the website to track website traffic.
(6) After installation, log in to Matomo, and in the "Dashboard" interface, select [INSTALL WITH JAVASCRIPT CODE] to view the tracking code.
(7) Select [TEST INSTALLATION] to test if it can monitor website traffic. When the green text "The tracking code is installed successfully! This screen will disappear as soon as some data is tracked for your website." appears, website traffic can be tracked normally.
(8) Select "All Websites" in the menu bar to view reports and total visits, visitors, page views, activities, revenue, and other elements for all monitored websites.
Optional Configuration#
(1) Select the "Settings" icon, choose "Personal" in "Settings," and change the default report loading date to "Today."
(2) Select the "Settings" icon, choose "Privacy Settings" in "Settings," and uncheck "Hide visitor IP addresses."
(3) Select the "Settings" icon, choose "Website" in "Settings," and set the default timezone for new websites to "China - Shanghai" and the default currency to "Renminbi (¥)."
(4) Select the "Settings" icon, choose "System" in "Settings," and change the location information provider to "DBIP / GeoIP 2 (Php)."
(5) Select the "Settings" icon, choose "Platform" in "Settings," and install the IP2Location, LogViewer, MarketingCampaignsReporting, and Profile Gravatar plugins. After installing the LogViewer plugin, you need to modify the [log] module in global.ini.php in the local mapped directory /data/matomo/config/. After modification, restart the app container.
[log]
log_writers[] = file
log_level = INFO
# Restart app container
docker restart matomo-app
(6) Enable the TagManager and DBStats plugins.