티스토리 뷰
우분투에서는 systemctl 명령으로 프로세스를 서비스로 등록할 수 있습니다. 기본적으로 서비스명.service 파일을 만들고 systemd 데몬을 리로드 한 후 실행명령을 사용하면 실행할 수 있습니다.
기본 명령어
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 서비스 파일 생성 위치 | |
/etc/systemd/system/zookeeper.service | |
# 주키퍼 서비스를 등록(*.service 파일을 읽어서 등록 함) | |
systemctl daemon-reload | |
# 시스템이 시작될 때 자동으로 시작되도록 등록 | |
systemctl enable zookeeper | |
# 시작 | |
systemctl stop zookeeper | |
# 정지 | |
systemctl stop zookeeper | |
# 상태 확인 | |
systemctl status zookeeper | |
# active 상태 확인 | |
systemctl is-active zookeeper |
예제
서비스 파일의 예제는 다음과 같습니다. mysql 의 서비스 등록 예제와 zookeeper 를 서비스로 등록하는 예제입니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deploy@hadoop-etc:~$ cat /etc/systemd/system/mysqld.service | |
# | |
# /etc/systemd/system/mariadb.service | |
# | |
# This file is free software; you can redistribute it and/or modify it | |
# under the terms of the GNU Lesser General Public License as published by | |
# the Free Software Foundation; either version 2.1 of the License, or | |
# (at your option) any later version. | |
# | |
# Thanks to: | |
# Daniel Black | |
# Erkan Yanar | |
# David Strauss | |
# and probably others | |
[Unit] | |
Description=MariaDB 10.1.48 database server | |
Documentation=man:mysqld(8) | |
Documentation=https://mariadb.com/kb/en/library/systemd/ | |
After=network.target | |
[Install] | |
WantedBy=multi-user.target | |
Alias=mysql.service | |
Alias=mysqld.service | |
[Service] | |
############################################################################## | |
## Core requirements | |
## | |
Type=notify | |
# Setting this to true can break replication and the Type=notify settings | |
# See also bind-address mysqld option. | |
PrivateNetwork=false | |
############################################################################## | |
## Package maintainers | |
## | |
User=mysql | |
Group=mysql | |
# To allow memlock to be used as non-root user if set in configuration | |
CapabilityBoundingSet=CAP_IPC_LOCK | |
# Prevent writes to /usr, /boot, and /etc | |
ProtectSystem=full | |
# Doesn't yet work properly with SELinux enabled | |
# NoNewPrivileges=true | |
PrivateDevices=true | |
# Prevent accessing /home, /root and /run/user | |
ProtectHome=true | |
# Execute pre and post scripts as root, otherwise it does it as User= | |
PermissionsStartOnly=true | |
ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld | |
# Perform automatic wsrep recovery. When server is started without wsrep, | |
# galera_recovery simply returns an empty string. In any case, however, | |
# the script is not expected to return with a non-zero status. | |
# It is always safe to unset _WSREP_START_POSITION environment variable. | |
# Do not panic if galera_recovery script is not available. (MDEV-10538) | |
ExecStartPre=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION" | |
ExecStartPre=/bin/sh -c "[ ! -e /usr/bin/galera_recovery ] && VAR= || \ | |
VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] \ | |
&& systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1" | |
# Needed to create system tables etc. | |
# ExecStartPre=/usr/bin/mysql_install_db -u mysql | |
# Start main service | |
# MYSQLD_OPTS here is for users to set in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf | |
# Use the [Service] section and Environment="MYSQLD_OPTS=...". | |
# This isn't a replacement for my.cnf. | |
# _WSREP_NEW_CLUSTER is for the exclusive use of the script galera_new_cluster | |
ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION | |
ExecStartPost=/etc/mysql/debian-start | |
# Unset _WSREP_START_POSITION environment variable. | |
ExecStartPost=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION" | |
KillSignal=SIGTERM | |
# Don't want to see an automated SIGKILL ever | |
SendSIGKILL=no | |
# Restart crashed server only, on-failure would also restart, for example, when | |
# my.cnf contains unknown option | |
Restart=on-abort | |
RestartSec=5s | |
UMask=007 | |
############################################################################## | |
## USERs can override | |
## | |
## | |
## by creating a file in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf | |
## and adding/setting the following under [Service] will override this file's | |
## settings. | |
# Useful options not previously available in [mysqld_safe] | |
# Kernels like killing mysqld when out of memory because its big. | |
# Lets temper that preference a little. | |
# OOMScoreAdjust=-600 | |
# Explicitly start with high IO priority | |
# BlockIOWeight=1000 | |
# If you don't use the /tmp directory for SELECT ... OUTFILE and | |
# LOAD DATA INFILE you can enable PrivateTmp=true for a little more security. | |
PrivateTmp=false | |
# Set an explicit Start and Stop timeout of 900 seconds (15 minutes!) | |
# this is the same value as used in SysV init scripts in the past | |
# Galera might need a longer timeout, check the KB if you want to change this: | |
# https://mariadb.com/kb/en/library/systemd/#configuring-the-systemd-service-timeout | |
TimeoutStartSec=900 | |
TimeoutStopSec=900 | |
## | |
## Options previously available to be set via [mysqld_safe] | |
## that now needs to be set by systemd config files as mysqld_safe | |
## isn't executed. | |
## | |
# Number of files limit. previously [mysqld_safe] open-files-limit | |
LimitNOFILE=16384 | |
# Maximium core size. previously [mysqld_safe] core-file-size | |
# LimitCore= | |
# Nice priority. previously [mysqld_safe] nice | |
# Nice=-5 | |
# Timezone. previously [mysqld_safe] timezone | |
# Environment="TZ=UTC" | |
# Library substitutions. previously [mysqld_safe] malloc-lib with explicit paths | |
# (in LD_LIBRARY_PATH) and library name (in LD_PRELOAD). | |
# Environment="LD_LIBRARY_PATH=/path1 /path2" "LD_PRELOAD= | |
# Flush caches. previously [mysqld_safe] flush-caches=1 | |
# ExecStartPre=sync | |
# ExecStartPre=sysctl -q -w vm.drop_caches=3 | |
# numa-interleave=1 equalivant | |
# Change ExecStart=numactl --interleave=all /usr/sbin/mysqld...... | |
# crash-script equalivent | |
# FailureAction= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Zookeeper | |
[Service] | |
Type=forking | |
User=zookeeper | |
ExecStart=/opt/zookeeper/bin/zkServer.sh start | |
[Install] | |
WantedBy=multi-user.target |
반응형
'리눅스' 카테고리의 다른 글
[vi] VI의 기본 인코딩을 utf-8로 설정 (0) | 2021.12.21 |
---|---|
[ubuntu] 크론탭 설정 중 crontab rename: Operation not permitted (0) | 2021.07.27 |
[bash] ssh로 원격 서버에 명령어 실행시 환경 변수를 읽지 않는 문제 해결 (0) | 2021.03.29 |
[ubuntu] apt-get 프록시(proxy) 설정 (0) | 2021.03.28 |
[CentOS] root 계정의 암호 변경 (0) | 2020.12.29 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- nodejs
- ubuntu
- 오류
- HDFS
- bash
- Linux
- java
- S3
- emr
- error
- HIVE
- 파이썬
- 하둡
- SQL
- yarn
- Hadoop
- airflow
- hbase
- AWS
- Python
- 정올
- SPARK
- 알고리즘
- build
- 다이나믹
- 하이브
- mysql
- oozie
- 백준
- Tez
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함