CentOS7 - rc.local 활성화 하기

rc.local 이란?

부팅시 자동실행 명령어 스크립트 수행하며 일반적으로 서버 부팅시마다 매번 자동 실행되길 원하는 명령어를 넣어주는 곳.

CentOS7 에서는 /etc/rc.local 에 명령어를 입력해도 재부팅시 실행이 안됩니다.default 상태가 disable 상태로 되어있습니다./etc/rc.local 파일을 보면 아래와 같이 /etc/rc.d/rc.local에 실행권한을 부여해줘야 한다고 합니다.

# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensurethat this script will be executed during boot.

1. 파일의 실행 권한 부여

위에서 확인한대로 /etc/rc.d/rc.local 파일에 실행권한을 부여해 줍니다.

$ chmod +x /etc/rc.d/rc.local

2. 현재 상태 확인

아래 명령어로 확인해보면 rc-local 의 서비스 상태가Active: inactive (dead) 로 확인이 되는걸 보실 수 있습니다.

$ systemctl status rc-local.service

3. 활성화

아래 명령어로 Active 상태로 활성화 해줍니다.현재 상태에서 활성화 해주는 것이기 때문에 재부팅해도 유지하려면 4번의 설정을 추가해주면 됩니다.

$ systemctl start rc-local.service

4. reboot시 사용가능하게 enable 설정

재부팅하게되면 다시 disable 상태로 변경되기 때문에 재부팅 후에도 enable 상태를 유지하기 위해/usr/lib/systemd/system/rc-local.service 파일을 수정 후 아래의 명령어를 입력해 줍니다.

$ vi /usr/lib/systemd/system/rc-local.service

하단에 아래 내용을 추가해 줍니다.

[Install] WantedBy=multi-user.target

부팅시 서비스를 자동실행하게 enable 해줍니다.

$ systemctl enable rc-local.service Created symlink from /etc/systemd/system/multi-user.target.wants/rc-local.service to /usr/lib/systemd/system/rc-local.service.

5. 서비스 상태 확인

서비스가 enable 상태인지 확인합니다.

$ systemctl list-unit-files |grep rc.local rc-local.service enabled

춣처 : https://blessu1201.github.io/2020/09/19/rclocal.html


© 2024. Chiptune93 All rights reserved.