Understanding Production Server Environment Variables

Asked 1 years ago, Updated 1 years ago, 117 views

Sorry for the rudimentary question.

I want to permanently set the environment variable on the production server, but I can only set it temporarily with export.Please let me know how to set the permanent environment variable.It's like writing DB and other information into an environment variable for reference.

I would appreciate it if you could write it specifically like this in the command or xxx file.

Thank you for your cooperation.

server-management

2022-09-29 22:12

1 Answers

Prerequisites

Based on past question trends, I will answer about setting environment variables in a Linux configuration with SELinux disabled.
The range of expectations will be wider, so it will be easier to answer if you give me a little more information.
SE I don't recommend disabling SELinux, but it's an answer that doesn't take into account SELinux.
この In this case, it is necessary to determine based on the type of operating system and to include the version of Windows, Linux, RedHat, Debian, etc. in the answer.In addition, DB settings such as rails are recognized as database.yml, so this answer is not reliable.

Environment variable settings for all users

Please include the environment variables you would like to set in the file below, where hoge is an optional name and should be given a name that tells you what to set.
/etc/profiles.d/hoge.sh

Valid only if the user is logged in.

Set environment variables for specific users

Please include the environment variables you would like to set in the file below.
/home/username/.bash_profile

NOTE: When changing environment variables, please note that settings may be added to the following files:
/home/username/.bashrc

Valid only if the user is logged in.

How to load environment variables with services using systemd

Please include the environment variables you would like to set in the file below.(Anywhere)
/etc/systemconfig/hoge.env

Configure EnvironmentFile settings for the following services:(The following is a fictional service, so it does not exist)
/etc/systemd/system/hoge.service

 Service
EnvironmentFile=/etc/systemconfig/hoge.env
ExecStart =....

Once configured, do systemctl daemon-reload to restart the service.


2022-09-29 22:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.