Linux system management and security management - systemctl/systemd

refer to:

Configuration parameter description:

  • symbol “@”

    • Template and Instance Unit Names
    • http://superuser.com/questions/393423/the-symbol-and-systemctl-and-vsftpd
    • Use @ to parameterize the service name. When a service has multiple instances on a machine, if you do not want to generate multiple service names, you can control it through parameters. The content after the %i proxy service name @ is used in the configuration file. Such as systemctl start mysql @3306 , %i is 3306
  • [unit]

    • Description: Service description, displayed when printing the service
    • After: Dependent service, must be started after the dependent service is started
      • syslog.target, syslog service
      • network.target, network service
  • [service]

    • User: start user
    • Group: start user group
    • type: startup method,
      • simple (default)
      • forking (a process that automatically enters the background after startup, you need to use this method)
      • Other methods are generally not used
    • ExecStart: start method
    • ExecStop: stop method
    • PIDFILE: Specify the pid file to monitor the process status. When type=forking, it must be specified
    • Restart: restart condition,
      • always reboot, even if systemctl stop is turned off
      • on-success, when exiting successfully
      • on-failure, the process exit status is abnormal, the default is 0, you can use SuccessExitStatus to specify
      • on-abnormal, process timeout, user canceled, watchdog
      • on-watchdog, when the watchdog shuts down the process
      • on-abort, user cancels
      • no, no restart, default
    • PrivateTmp: Allocate a separate temporary space for a process
  • [install]

    • WantedBy, how the current service is loaded

Applications

Precautions:

  • Use absolute path to command in ".service" file
  • When the service has a specific running user, the running environment needs to be specified: user, group, environmentfile
  • Adjust the use of parameters according to the characteristics of the service

1. Systemctl adds mysql service "@" to manage multiple instances

This script is used in an environment where multiple mysql instances are started. If you want to manage a single MySQL process, you only need to replace "%i" with specific parameters (mysql single instance management can refer to: http://blog.csdn.net /shen2308/article/details/78492460).

[Unit]
Description=MySQL Multi Server for instance %i
After=syslog.target
After=network.target

[Service]
User=mysql
Group=mysql
Type=forking
ExecStart=/usr/bin/mysqld_multi start %i
ExecStop=/usr/bin/mysqld_multi stop %i
Restart=always
PrivateTmp=true

[Install]
WantedBy=multi-user.target

#管理命令
systemctl start/stop/status/restart [email protected]

2. systemctl add tomcat service

[Unit]  
Description=Tomcat of rapapi
After=syslog.target network.target
  
[Service]
#指定用户
User=root
Group=root
Type=forking
#因为tomcat使用信号管理进程,所以需要指定pid文件
PIDFile=/usr/share/apache-tomcat-7.0.72/tomcat.pid  
ExecStart=/usr/share/apache-tomcat-7.0.72/bin/startup.sh  
ExecReload=/bin/kill -s HUP $MAINPID  
ExecStop=/bin/kill -s QUIT $MAINPID  
PrivateTmp=true  
Restart=on-failure
RestartSec=10
  
[Install]  
WantedBy=multi-user.target

Administrative command: systemctl start/stop/status/restart ProcessName.service

3. systemctl add jenkins service

[Unit]
Description=Jenkins Control With Resin
After=syslog.target
After=network.target

[Service]
User=root
Group=root
ExecStart=/bin/bash /root/resin-3.1.12/bin/httpd.sh
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target

4. systemctl add redmine service

[Unit]
Description=Redmine Control
After=syslog.target
After=network.target

[Service]
User=redmine
Group=redmine
#指定虚拟环境文件
EnvironmentFile=-/home/redmine/redmine-2.5.1/rails.env
WorkingDirectory=/home/redmine/redmine-2.5.1
ExecStart=/usr/local/rvm/src/rvm/rubies/ruby-2.0.0-p648/bin/ruby /home/redmine/redmine-2.5.1/script/rails server webrick -e production -p 4000

Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

5. systemctl add falcon service

[Unit]
Description=Open Falcon Agent Service
After=network.target

[Service]
WorkingDirectory=/home/falcon/agent
ExecStart=/home/falcon/agent/falcon-agent -c /home/falcon/agent/cfg.json >> /dev/null 2>&1
StandardOutput=null

Restart=on-failure
RestartSec=15

[Install]
WantedBy=multi-user.target

rsync configuration file

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area


uid = nobody
gid = nobody
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[m_log]
path=/data/logs/
ignore erros
read only = false
list = false
hosts allow=10.9.12.2
hosts deny=*

Note: The rsync service only opens connection permissions to the specified ip to improve the security of the service! ! !

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325636869&siteId=291194637