User Tools

Site Tools


управление_сервисами_в_linux

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
управление_сервисами_в_linux [2025/04/18 11:18]
val [Управление юнитами Systemd]
управление_сервисами_в_linux [2026/04/06 16:16] (current)
val [Система загрузки rc.local]
Line 31: Line 31:
  
 ===== Система загрузки rc.local ===== ===== Система загрузки rc.local =====
 +
 +  * [[Сервис SSH#​Аутентификация с использованием ключей ssh]]
 +  * [[Сервис SSH#SSH вместо VPN (привязка к порту сервера)]]
 +  * [[Управление ядром и модулями в Linux#​Переменные ядра]] net.ipv4.ip_local_port_range
 <​code>​ <​code>​
 # cat /​etc/​rc.local # cat /​etc/​rc.local
Line 59: Line 63:
 # /​etc/​init.d/​proftpd stop # /​etc/​init.d/​proftpd stop
  
-# cat /​etc/​init.d/​sshvpn+# cat /​etc/​init.d/​mysshvpn
 </​code><​code>​ </​code><​code>​
 #!/bin/sh #!/bin/sh
  
 ######### CentOS ########## ######### CentOS ##########
-sshvpn ​         ​Start/​Stop the sshvpn ​daemon.+mysshvpn ​         ​Start/​Stop the mysshvpn ​daemon.
 # #
 # chkconfig: 2345 90 60 # chkconfig: 2345 90 60
Line 70: Line 74:
 ######### Debian ########## ######### Debian ##########
 ### BEGIN INIT INFO ### BEGIN INIT INFO
-# Provides: ​            sshvpn+# Provides: ​            mysshvpn
 # Required-Start: ​   $remote_fs $syslog $local_fs $network # Required-Start: ​   $remote_fs $syslog $local_fs $network
 # Required-Stop: ​    ​$remote_fs $syslog $local_fs $network # Required-Stop: ​    ​$remote_fs $syslog $local_fs $network
Line 76: Line 80:
 # Default-Stop: ​     0 1 6 # Default-Stop: ​     0 1 6
  
-# Short-Description: ​   ​sshvpn ​Secure Shell server+# Short-Description: ​   ​mysshvpn ​Secure Shell server
 ### END INIT INFO ### END INIT INFO
  
Line 83: Line 87:
 if [ "​$1"​ = start ] if [ "​$1"​ = start ]
 then then
-        echo Starting ​sshvpn...+        echo Starting ​mysshvpn...
         /​usr/​bin/​ssh -N -R 61000+X:​localhost:​22 -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes userX@gate.isp.un &         /​usr/​bin/​ssh -N -R 61000+X:​localhost:​22 -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes userX@gate.isp.un &
-        echo $! > /var/run/sshvpn.pid+        echo $! > /var/run/mysshvpn.pid
 elif [ "​$1"​ = stop ] elif [ "​$1"​ = stop ]
 then then
-        echo Stopping ​sshvpn... +        echo Stopping ​mysshvpn... 
-        kill -TERM `cat /var/run/sshvpn.pid` +        kill -TERM `cat /var/run/mysshvpn.pid` 
-        rm /var/run/sshvpn.pid+        rm /var/run/mysshvpn.pid
 else else
         echo Usage:         echo Usage:
-        echo '/​etc/​init.d/​sshvpn ​start|stop'​+        echo '/​etc/​init.d/​mysshvpn ​start|stop'​
 fi fi
 </​code>​ </​code>​
Line 103: Line 107:
  
 # cd /etc/init.d # cd /etc/init.d
-# ln -s ../init.d/sshvpn ​/etc/rc5.d/S20sshvpn+# ln -s ../init.d/mysshvpn ​/etc/rc5.d/S20mysshvpn
  
-# ln -s ../init.d/sshvpn ​/etc/rc0.d/K20sshvpn +# ln -s ../init.d/mysshvpn ​/etc/rc0.d/K20mysshvpn 
-# ln -s ../init.d/sshvpn ​/etc/rc6.d/K20sshvpn+# ln -s ../init.d/mysshvpn ​/etc/rc6.d/K20mysshvpn
 </​code>​ </​code>​
  
Line 128: Line 132:
 # chkconfig --list # chkconfig --list
  
-# chkconfig --add sshvpn+# chkconfig --add mysshvpn
  
-# chkconfig --list ​sshvpn+# chkconfig --list ​mysshvpn
  
-# chkconfig ​sshvpn ​on+# chkconfig ​mysshvpn ​on
  
-# #​chkconfig ​sshvpn ​off+# #​chkconfig ​mysshvpn ​off
  
-# #chkconfig --del sshvpn+# #chkconfig --del mysshvpn
 </​code>​ </​code>​
 ==== Управление ресурсами ==== ==== Управление ресурсами ====
Line 153: Line 157:
   * [[https://​wiki.archlinux.org/​index.php/​systemd|systemd]]   * [[https://​wiki.archlinux.org/​index.php/​systemd|systemd]]
  
-==== Управление юнитами Systemd ​=====+==== Управление юнитами Systemd ====
  
   * [[https://​docs.gitea.io/​en-us/​linux-service/​|Run Gitea as Linux service]]   * [[https://​docs.gitea.io/​en-us/​linux-service/​|Run Gitea as Linux service]]
Line 162: Line 166:
 $ systemctl list-units $ systemctl list-units
 $ systemctl --failed $ systemctl --failed
 +$ systemctl reset-failed
  
 centos# find /​usr/​lib/​systemd/​system/​ centos# find /​usr/​lib/​systemd/​system/​
Line 177: Line 182:
 # systemctl enable ssh # systemctl enable ssh
  
-# cat /​etc/​systemd/​system/​sshvpn.service+# cat /​etc/​systemd/​system/​mysshvpn.service
 </​code><​code>​ </​code><​code>​
 [Unit] [Unit]
Line 196: Line 201:
 WantedBy=multi-user.target WantedBy=multi-user.target
 </​code><​code>​ </​code><​code>​
-# systemctl status ​sshvpn+# systemctl status ​mysshvpn
  
-# systemctl enable ​sshvpn ​--now+# systemctl enable ​mysshvpn #--now
  
-# ###systemctl start sshvpn+# systemctl start mysshvpn
 </​code>​ </​code>​
  
-==== Настройка параметров запуска в Systemd ​=====+==== Настройка параметров запуска в Systemd ====
  
 <​code>​ <​code>​
Line 210: Line 215:
 [Service] [Service]
 LimitNOFILE=65536 ​     # nginx, squid LimitNOFILE=65536 ​     # nginx, squid
 +LimitCORE=infinity
 TimeoutStartSec=180 ​   # elasticsearch TimeoutStartSec=180 ​   # elasticsearch
 </​code><​code>​ </​code><​code>​
Line 222: Line 228:
 # cat /​proc/​NNNNN/​limits # cat /​proc/​NNNNN/​limits
 </​code>​ </​code>​
 +
 +==== Systemd Sockets ====
 +
 +  * [[https://​gist.github.com/​drmalex07/​28de61c95b8ba7e5017c|README-setup-socket-activated-systemd-service.md]]
 +
 +<​code>​
 +# cat /​etc/​systemd/​system/​webd.socket
 +</​code><​code>​
 +[Unit]
 +Description=Web Socket
 +
 +[Socket]
 +ListenStream=127.0.0.1:​9999
 +#​ListenStream=0.0.0.0:​80
 +Accept=yes
 +
 +[Install]
 +WantedBy=sockets.target
 +</​code><​code>​
 +# cat /​etc/​systemd/​system/​webd@.service
 +</​code><​code>​
 +[Unit]
 +Description=WebD Service
 +Requires=webd.socket
 +
 +[Service]
 +Type=simple
 +ExecStart=/​usr/​local/​sbin/​webd %i
 +StandardInput=socket
 +StandardError=journal
 +TimeoutStopSec=5
 +#​RuntimeMaxSec=10
 +
 +[Install]
 +WantedBy=multi-user.target
 +</​code><​code>​
 +# systemctl start webd.socket
 +
 +# curl 127.0.0.1:​9999
 +
 +# journalctl -u '​webd@*'​ -n 20 --no-pager
 +</​code>​
 +
 +==== Systemd Timers ====
 +
 +  * [[Планирование выполнения заданий в Linux#​Systemd timers]]
 ===== Система загрузки OpenRC ===== ===== Система загрузки OpenRC =====
  
Line 260: Line 312:
 === Пример файла конфигурации для запуска/​остановки сервиса === === Пример файла конфигурации для запуска/​остановки сервиса ===
 <​code>​ <​code>​
-server# cat /etc/init/sshvpn.conf+server# cat /etc/init/mysshvpn.conf
 </​code><​code>​ </​code><​code>​
 description ​    "​OpenSSH tunnel"​ description ​    "​OpenSSH tunnel"​
Line 289: Line 341:
 === Управление запуском/​остановкой === === Управление запуском/​остановкой ===
 <​code>​ <​code>​
-server# echo manual > /etc/init/sshvpn.override+server# echo manual > /etc/init/mysshvpn.override
 </​code>​ </​code>​
  
управление_сервисами_в_linux.1744964320.txt.gz · Last modified: 2025/04/18 11:18 by val