Инструменты пользователя

Инструменты сайта


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

Управление сервисами в Linux

Конфигурация сервиса

# cat /etc/ssh/sshd_config

# cat /etc/rsyslog.conf

# ls /etc/rsyslog.d/

# cat /etc/apache2/apache2.conf

# ls /etc/apache2/sites-available/

# ls -l /etc/apache2/sites-enabled/

Запуск/остановка сервиса

Из shell

# /usr/sbin/sshd

Система загрузки rc.local

# cat /etc/rc.local
#!/bin/sh

/usr/bin/ssh -N -R 200X:localhost:22 userX@gate.isp.un &

exit 0
chmod +x /etc/rc.local

Система загрузки SysV

Скрипты запуска/остановки

# cat /etc/default/proftpd

# cat /etc/init.d/proftpd

# /etc/init.d/proftpd start

# /etc/init.d/proftpd stop

# cat /etc/init.d/sshvpn
#!/bin/sh

######### CentOS ##########
# sshvpn          Start/Stop the sshvpn daemon.
#
# chkconfig: 2345 90 60

######### Debian ##########
### BEGIN INIT INFO
# Provides:             sshvpn
# Required-Start:    $remote_fs $syslog $local_fs $network
# Required-Stop:     $remote_fs $syslog $local_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6

# Short-Description:    sshvpn Secure Shell server
### END INIT INFO



if [ "$1" = start ]
then
        echo Starting sshvpn...
        /usr/bin/ssh -N -R 200X:localhost:22 userX@gate.isp.un &
        echo $! > /var/run/sshvpn.pid
elif [ "$1" = stop ]
then
        echo Stopping sshvpn...
        kill -TERM `cat /var/run/sshvpn.pid`
        rm /var/run/sshvpn.pid
else
        echo Usage:
        echo '/etc/init.d/sshvpn start|stop'
fi

Управление запуском/остановкой

# runlevel

# cd /etc/init.d
# ln -s ../init.d/sshvpn /etc/rc5.d/S20sshvpn

# ln -s ../init.d/sshvpn /etc/rc0.d/K20sshvpn
# ln -s ../init.d/sshvpn /etc/rc6.d/K20sshvpn

Debian/Ubuntu

# ls -l /etc/rc?.d/* | grep ftp

# update-rc.d -f proftpd remove

# update-rc.d proftpd defaults

RHEL/CentOS

http://www.cyberciti.biz/faq/rhel5-update-rcd-command/

# chkconfig --list

# chkconfig --add sshvpn

# chkconfig --list sshvpn

# chkconfig --del sshvpn

# chkconfig sshvpn on

# chkconfig sshvpn off

Система загрузки Systemd

$ systemctl -a
$ systemctl list-units

centos# find /usr/lib/systemd/system/
debian# find /lib/systemd/system/

$ systemctl status ssh

# systemctl stop ssh
# systemctl start ssh
# systemctl reload ssh

# systemctl disable ssh
# systemctl enable ssh

# cat /etc/systemd/system/sshvpn.service
[Unit]
Description=ssh client vpn daemon
After=network.target

[Service]
ExecStart=/usr/bin/ssh -N -R 200X:localhost:22 userX@gate.isp.un
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
# systemctl status sshvpn

# systemctl enable sshvpn

# systemctl start sshvpn

Система загрузки OpenRC

# ls /etc/init.d/
# /etc/init.d/sshd status|start|stop

# rc-service sshd status|start|stop

# rc-update add|del sshd default
# openrc

Система загрузки Upstart

Скрипты запуска/остановки

# initctl show-config | grep ssh

# initctl show-config ssh

# less /etc/default/ssh

# less /etc/init/ssh.conf

# start ssh

# stop ssh

# initctl list

Пример файла конфигурации для запуска/остановки сервиса

server# cat /etc/init/sshvpn.conf
description     "OpenSSH tunnel"

start on filesystem or runlevel [2345]
stop on runlevel [!2345]

respawn
respawn limit 10 5
umask 022

exec /usr/bin/ssh ssh -N -R 192.168.X.10:3389:192.168.100+X.101:3389 student@server.corpX.un
mail# cat /etc/init/communigate.conf
description     "Communigate"

start on filesystem or runlevel [2345]
stop on runlevel [!2345]

respawn
respawn limit 10 5
umask 022

exec /root/CGateProSoftware/CommuniGate/CGServer-static --Base /var/CommuniGate

Управление запуском/остановкой

server# echo manual > /etc/init/sshvpn.override

Универсальный скрипт service

debian# service --status-all

# service ssh start

# service ssh stop
управление_сервисами_в_linux.txt · Последние изменения: 2018/08/28 12:10 — val