Configure Aerospike to run as non-root
This page describes how to configure Aerospike to run as a non-root user.
On an Aerospike system running with the default root privileges, a non-root user on the same system cannot
access the logs collected by collectlogs
.
Configure an Aerospike node
Use the following steps to configure a new installation of Aerospike to run as a non-root user.
-
If necessary, install Aerospike as described in the install documentation.
-
If upgrading an existing installation:
-
Stop the Aerospike
asd
process. See Aerospike daemon management. -
Check the ownership of the shared memory segments. Segments with the prefix
0xae
are Aerospike primary index, segments with the prefix0xa2
are Aerospike secondary index, and segments with the prefix0xad
store data for an in-memory namespace.Terminal window ipcs -m------ Shared Memory Segments --------key shmid owner perms bytes nattch status0xae001100 0 root 666 1073741824 10xae002100 1 root 666 1073741824 10xad001000 2 root 666 536870912 10xad001001 3 root 666 536870912 1 -
Remove the existing shared memory blocks owned by Aerospike (if not storage engine memory), then restart Aerospike. This forces a cold start with shared memory blocks created by the non-root user and group.
Terminal window ipcs | grep -oE "^0xa[2de][0-9a-f]*" | sudo xargs -i ipcrm -M {}To avoid a cold restart, use a special script to change ownership of shared memory. For more information, see Fast restart.
-
-
Configure
User
andGroup
to root in/lib/systemd/system/aerospike.service
.Terminal window [Service]User=AEROSPIKE-USERGroup=AEROSPIKE-GROUP -
Ensure that the server is configured to use console logging.
Terminal window logging {console {context any info}} -
Configure file resources used by namespaces.
If your namespace data is configured for persistence to a file, AEROSPIKE-USER must have write permissions creation permission for the directory with the specified file. Example:
Terminal window namespace bar {...storage-engine device {file /opt/aerospike/data/bar.data...}} -
If you are using SSDs as raw devices, you must give ownership of the devices to the AEROSPIKE-USER. To give ownership you can either add AEROSPIKE-USER to the disk group, or add a udev rule to the AEROSPIKE-USER.
-
Add user to disk group.
Terminal window sudo usermod -a -G nameOfDiskGroup AEROSPIKE-USEROr,
-
Add a udev rule, similar to the following, to the file
/etc/udev/rules.d/99-aerospike.rules
. This rule sets AEROSPIKE-USER as the owner of the devices/dev/sdb
and/dev/sdc
.Terminal window KERNEL=="sd[bc]", OWNER="AEROSPIKE-USER"Save this file, then reload and trigger the udev rules.
Terminal window udevadm control --reload-rulesudevadm triggerSSDs used as filesystems, such as a flash index, need the same directory ownership and permissions detailed in Step 2.
-
-
Change ownership of additional directories.
Terminal window # Give read-write access to system metadatachown -R AEROSPIKE-USER:AEROSPIKE-GROUP /opt/aerospike/smd# Give read-write access for persisting User-Defined Functions (UDFs)chown -R AEROSPIKE-USER:AEROSPIKE-GROUP /opt/aerospike/usr# If you are using file storagechown -R AEROSPIKE-USER:AEROSPIKE-GROUP /opt/aerospike/data/ -
Tune the Linux kernel to the following required parameters. In an all-flash deployment, the following Linux kernel parameters are required for the node to start. Prepare these values before running the Aerospike server. Enable
enforce-best-practices
inaerospike.conf
to prevent the server from starting when any best practice isn’t being followed.Terminal window /proc/sys/vm/dirty_bytes = 16777216/proc/sys/vm/dirty_background_bytes = 1/proc/sys/vm/dirty_expire_centisecs = 1/proc/sys/vm/dirty_writeback_centisecs = 10 -
If you are using SSDs as raw devices or for the index as flash index: You must give ownership of the devices to the AEROSPIKE-USER. To give ownership you can either add AEROSPIKE-USER to the disk group or add a udev rule to the AEROSPIKE-USER.
Add user to disk group.
Terminal window sudo usermod -a -G nameOfDiskGroup AEROSPIKE-USEROr,
Add a udev rule similar to the following to the file
/etc/udev/rules.d/99-aerospike.rules
. This rule sets AEROSPIKE-USER as the owner of the devices/dev/sdb
and/dev/sdc
.Terminal window KERNEL=="sd[bc]", OWNER="AEROSPIKE-USER"Save this file, then reload and trigger the udev rules.
Terminal window udevadm control --reload-rulesudevadm trigger -
Check for success After you make these changes, start the node.
The Aerospike server can be started only by a root user or by a user with sudo permissions. The running process, however, is owned by the non-root user.
For options on starting the server, see Aerospike Daemon Management.
Verify with
ipcs -m
that the Aerospike shared memory segments are correctly owned.If there are errors, the Aerospike Daemon (asd) process does not start. Examine the logs for messages about which resources require attention.