Bare Metal / Virtual Machine
-
Install JuiceFS on CubeAPM server, following the documentation at https://juicefs.com/docs/community/getting-started/installation/
-
JuiceFS needs a database for storing metadata. Since CubeAPM already uses a database (MySQL or PostgreSQL), the same can be used for JuiceFS as well.
- MySQL
- PostgreSQL
CREATE DATABASE cubeapm_logs_archive_meta CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'cubeapm_logs_archive_user'@'%' IDENTIFIED BY 'cubeapm_logs_archive_pass';
GRANT ALL PRIVILEGES ON cubeapm_logs_archive_meta.* TO 'cubeapm_logs_archive_user'@'%';
FLUSH PRIVILEGES;CREATE DATABASE cubeapm_logs_archive_meta;
CREATE USER cubeapm_logs_archive_user WITH PASSWORD 'cubeapm_logs_archive_pass';
GRANT ALL PRIVILEGES ON DATABASE cubeapm_logs_archive_meta TO cubeapm_logs_archive_user;
GRANT ALL ON SCHEMA public TO cubeapm_logs_archive_user;
\c cubeapm_logs_archive_meta
GRANT ALL ON SCHEMA public TO cubeapm_logs_archive_user; -
Create object storage bucket for storing logs archive data. Name the bucket as
cubeapm-logs-archive -
Grant read/write permissions to CubeAPM on the bucket.
- AWS
- GCP
-
Either attach appropriate role to the server instance on which CubeAPM is running, or create access keys and provide the same to JuiceFS.
-
Attach role with required permissions. If using KMS-encrypted bucket, add KMS permissions as well.
-
Create
/etc/cubeapm/logs-archive.envwith AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION. Runsudo chmod 600 /etc/cubeapm/logs-archive.envto protect the file.AWS_ACCESS_KEY_ID=AKIA...
AWS_SECRET_ACCESS_KEY=abcd...
AWS_REGION=us-east-1
The following permissions are required on the bucket.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "JuiceFSS3Access",
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:ListMultipartUploadParts",
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:AbortMultipartUpload"
],
"Resource": [
"arn:aws:s3:::cubeapm-logs-archive",
"arn:aws:s3:::cubeapm-logs-archive/*"
]
}
]
} -
-
Format the JuiceFS filesystem. This needs to be done only once per JuiceFS volume. This initializes metadata in the database.
# Skip the following command if not using logs-archive.env
source /etc/cubeapm/logs-archive.env
# Format JuiceFS
#
# database_string
# MySQL: mysql://cubeapm_logs_archive_user:cubeapm_logs_archive_pass@tcp(localhost:3306)/cubeapm_logs_archive_meta
# PostgreSQL: postgres://cubeapm_logs_archive_user:cubeapm_logs_archive_pass@localhost:5432/cubeapm_logs_archive_meta
#
# bucket_url: https://cubeapm-logs-archive.s3.us-east-1.amazonaws.com
## Block size should be 16MB to upload large files to S3 (default is 4MB)
juicefs format \
--storage s3 \
--bucket <bucket_url> \
--block-size 16384 \
<database_string> \
logsarchive -
Create mount directory using command
sudo mkdir -p /var/lib/cubeapm/logs_archivenoteThese values need to be passed in the
cubeapm-logs-archive.servicefile. Refer to the step below.Mount Options Type Description cache-sizeintThe cache-sizeflag controls a strict limit on how much local disk space (in Megabytes) JuiceFS is allowed to use on your Kubernetes worker node to store temporary data. (Default value 100MB)buffer-sizeintThe buffer-sizeflag controls how much RAM (Memory) the JuiceFS client is allowed to use as a temporary buffer for reading and writing data. When your application writes data, it hits this fast memory buffer first before moving to S3. (Default value 300MB)max-uploadsintThe max-uploadsflag controls the maximum number of concurrent connections (threads) JuiceFS will open to your S3 bucket at the exact same time when uploading data. (Default value 20)free-space-ratiofloatThe free-space-ratioflag controls a safety mechanism for your local cache disk. If your local worker node's hard drive drops below 10% free space, JuiceFS will aggressively start deleting old cached data and will temporarily disable the local cache to protect your server from running completely out of disk space. (Default value 0.1 which means 10%)put-timeoutintThe put-timeoutflag controls the maximum amount of time it will wait for the upload to finish before giving up and throwing an error/retrying when JuiceFS tries to upload (PUT) a block of data to S3. (Default value 0.1 which means 60s)writebackboolThe writebackflag controls data write behavior from "Synchronous" to "Asynchronous". This is a boolean flag (meaning you just passwritebackto turn it on). When enabled, instead of making your application wait for the data to be successfully uploaded to S3, JuiceFS quickly writes the data through its RAM buffer directly to the local node's hard drive and tells your application "Done!". It then independently uploads the data from that local disk to S3 in the background. (Default value false) -
Create systemd service. Create a file named
/etc/systemd/system/cubeapm-logs-archive.service[Unit]
Description=CubeAPM logs archive
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
# If using logs-archive.env file, point to it here:
#EnvironmentFile=/etc/cubeapm/logs-archive.env
# database_string
# MySQL: mysql://cubeapm_logs_archive_user:cubeapm_logs_archive_pass@tcp(localhost:3306)/cubeapm_logs_archive_meta
# PostgreSQL: postgres://cubeapm_logs_archive_user:cubeapm_logs_archive_pass@localhost:5432/cubeapm_logs_archive_meta
#
# bucket_url: https://cubeapm-logs-archive.s3.us-east-1.amazonaws.com
#
# cache-size is in MiB. 51200 == 50 GiB.
# cache-dir=/var/lib/cubeapm/cache/logs_archive (Path can be changed) :
# This tells the JuiceFS client **where on your local server's hard drive**
# to store temporary data (cache) and metadata.
# The actual log files and objects are stored in S3,
# but the client keeps a copy of recent data on this local path for fast reading/writing.
ExecStart=/usr/local/bin/juicefs mount <database_string> /var/lib/cubeapm/logs_archive \
--storage s3 \
--bucket <bucket_url> \
--cache-dir=/var/lib/cubeapm/cache/logs_archive \
--buffer-size=2024 \
--cache-size=51200 \
--free-space-ratio=0.2 \
--put-timeout=90 \
--max-uploads=5 \
--writeback \
--foreground
ExecStop=/usr/local/bin/juicefs umount /var/lib/cubeapm/logs_archive
Restart=on-failure
RestartSec=5
TimeoutStopSec=30
[Install]
WantedBy=multi-user.target
-
Either attach appropriate role to the server instance on which CubeAPM is running, or by create service account and provide access to it and use that service account.
-
Attach the
storage.objectAdminpermission to the GCP VM default service account. -
Create a service account and grant the
storage.objectAdminpermission to it. After granting the permission, stop the cubeapm instance and edit the instance configuration.-
Under Identity and API access setting, select the service account you have created with the
storage.objectAdminpermission. -
After settingup Identity and API access, under Access scopes, select either default or full access to all Cloud APIs and save it.
-
Start the cubeapm instance.
-
-
-
Run the below command to format the JuiceFS filesystem. This needs to be done only once per JuiceFS volume. This initializes metadata in the database.
# Format JuiceFS
#
# database_string
# MySQL: mysql://cubeapm_logs_archive_user:cubeapm_logs_archive_pass@tcp(localhost:3306)/cubeapm_logs_archive_meta
# PostgreSQL: postgres://cubeapm_logs_archive_user:cubeapm_logs_archive_pass@localhost:5432/cubeapm_logs_archive_meta
#
# bucket_url: gs://cubeapm-logs-archive
## Block size should be 16MB to upload large files to S3 (default is 4MB)
juicefs format \
--storage gs \
--bucket <bucket_url> \
--block-size 16384 \
<database_string> \
logsarchive -
Create mount directory using command
sudo mkdir -p /var/lib/cubeapm/logs_archivenoteThese values need to be passed in the
cubeapm-logs-archive.servicefile. Refer to the step below.Mount Options Type Description cache-sizeintThe cache-sizeflag controls a strict limit on how much local disk space (in Megabytes) JuiceFS is allowed to use on your Kubernetes worker node to store temporary data. (Default value 100MB)buffer-sizeintThe buffer-sizeflag controls how much RAM (Memory) the JuiceFS client is allowed to use as a temporary buffer for reading and writing data. When your application writes data, it hits this fast memory buffer first before moving to S3. (Default value 300MB)max-uploadsintThe max-uploadsflag controls the maximum number of concurrent connections (threads) JuiceFS will open to your S3 bucket at the exact same time when uploading data. (Default value 20)free-space-ratiofloatThe free-space-ratioflag controls a safety mechanism for your local cache disk. If your local worker node's hard drive drops below 10% free space, JuiceFS will aggressively start deleting old cached data and will temporarily disable the local cache to protect your server from running completely out of disk space. (Default value 0.1 which means 10%)put-timeoutintThe put-timeoutflag controls the maximum amount of time it will wait for the upload to finish before giving up and throwing an error/retrying when JuiceFS tries to upload (PUT) a block of data to S3. (Default value 0.1 which means 60s)writebackboolThe writebackflag controls data write behavior from "Synchronous" to "Asynchronous". This is a boolean flag (meaning you just passwritebackto turn it on). When enabled, instead of making your application wait for the data to be successfully uploaded to S3, JuiceFS quickly writes the data through its RAM buffer directly to the local node's hard drive and tells your application "Done!". It then independently uploads the data from that local disk to S3 in the background. (Default value false) -
Create systemd service. Create a file named
/etc/systemd/system/cubeapm-logs-archive.service[Unit]
Description=CubeAPM logs archive
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
# If using logs-archive.env file, point to it here:
#EnvironmentFile=/etc/cubeapm/logs-archive.env
# database_string
# MySQL: mysql://cubeapm_logs_archive_user:cubeapm_logs_archive_pass@tcp(localhost:3306)/cubeapm_logs_archive_meta
# PostgreSQL: postgres://cubeapm_logs_archive_user:cubeapm_logs_archive_pass@localhost:5432/cubeapm_logs_archive_meta
#
# bucket_url: gs://cubeapm-logs-archive
#
# cache-size is in MiB. 51200 == 50 GiB.
# cache-dir=/var/lib/cubeapm/cache/logs_archive (Path can be changed.):
# This tells the JuiceFS client **where on your local server's hard drive**
# to store temporary data (cache) and metadata.
# The actual log files and objects are stored in S3,
# but the client keeps a copy of recent data on this local path for fast reading/writing.
ExecStart=/usr/local/bin/juicefs mount <database_string> /var/lib/cubeapm/logs_archive \
--storage gs \
--bucket <bucket_url> \
--cache-dir=/var/lib/cubeapm/cache/logs_archive \
--buffer-size=2024 \
--cache-size=51200 \
--free-space-ratio=0.2 \
--put-timeout=90 \
--max-uploads=5 \
--writeback \
--foreground
ExecStop=/usr/local/bin/juicefs umount /var/lib/cubeapm/logs_archive
Restart=on-failure
RestartSec=5
TimeoutStopSec=30
[Install]
WantedBy=multi-user.target
infoCheck juicefs installation path (using
which juicefs). In case the path is not/usr/local/bin/juicefs, replace the installation path in above script. -
Enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable cubeapm-logs-archive.service
sudo systemctl start cubeapm-logs-archive.service
# check status
sudo systemctl status cubeapm-logs-archive.service
# check logs
journalctl -f -u cubeapm-logs-archive.service