# 官方提供@yunTaoScripts 系统服务 🔥🔥
通过service 启动脚本来控制守护进程(Daemon)的启动与关闭
[root@localhost yum.repos.d]# yum install -y vsftpd
[root@localhost yum.repos.d]# systemctl status vsftpd.service
● vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@localhost yum.repos.d]# cat /usr/lib/systemd/system/vsftpd.service
[Unit]
Description=Vsftpd ftp daemon
After=network-online.target
[Service]
Type=forking
ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
[Install]
WantedBy=multi-user.target
# 自定义服务
- 清理缓存
[root@rhel-100 ~]# free -h
total used free shared buff/cache available
Mem: 3.6Gi 1.1Gi 1.5Gi 19Mi 1.1Gi 2.3Gi
Swap: 2.0Gi 0B 2.0Gi
[root@rhel-100 ~]# echo 3 > /proc/sys/vm/drop_caches
[root@rhel-100 ~]# free -h
total used free shared buff/cache available
Mem: 3.6Gi 1.0Gi 2.3Gi 19Mi 300Mi 2.4Gi
Swap: 2.0Gi 0B 2.0Gi
- 配置服务
[root@rhel-100 system]# systemctl list-unit-files | grep memload
memload.service disabled
[root@rhel-100 system]# cat memload.service
[Unit]
Description=memload daemon
After=network-online.target
[Service]
Type=memtest
ExecStart=/usr/local/bin/memload 1000
[Install]
WantedBy=multi-user.target
[root@rhel-100 system]# pwd
/usr/lib/systemd/system
[root@rhel-100 system]# vim memload.service ###修改了配置文件需要daemon-relaod
[root@rhel-100 system]# cat memload.service
[Unit]
Description=memload daemon
After=network-online.target
[Service]
Type=memtest
ExecStart=/usr/local/bin/memload 2000
[Install]
WantedBy=multi-user.target
[root@rhel-100 system]# systemctl restart memload.service
Warning: The unit file, source configuration file or drop-ins of memload.service changed on disk. Run 'systemctl daemon-reload' to reload units.
ansible service 模块和 systemd 模块区别
- 如果启动文件被修改,此时需要daemond reload,但是service 模块不支持daemon reload,此时就需要systemd 模块。
# 通过ansible 配置网络
[root@rhel8-100 home]# cat network.yaml
---
- hosts: rhel8-102
vars:
network_connections:
- name: ens224
interface_name: ens224
type: ethernet
ip:
dhcp4: no
gateway4: 192.168.26.2
dns:
- 192.168.26.2
address:
- 198.168.26.102/24
roles:
- rhel-system-roles.network
[root@rhel8-100 home]# ansible-playbook network.yaml
← 快速链接