前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >10.27 target介绍

10.27 target介绍

作者头像
运维小白
发布2018-02-06 12:04:04
8350
发布2018-02-06 12:04:04
举报
文章被收录于专栏:运维小白运维小白

target介绍

  • 系统为了方便管理target来管理unit
  • systemctl list-unit-files --type=target //列出系统中所有的target
  • systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit
  • systemctl get-default //查看系统默认的target
  • systemctl set-default multi-user.target
  • 一个service属于一种类型的unit
  • 多个unit组成了一个target
  • 一个target里面包含了多个service
  • cat /usr/lib/systemd/system/sshd.service 看[install]部分

target相关命令

  • systemctl list-unit-files --type=target //列出系统中所有的target
代码语言:javascript
复制
[root@hf-01 system]# systemctl list-unit-files --type=target    //列出系统中所有的target
UNIT FILE                 STATE   
basic.target              static  
bluetooth.target          static  
cryptsetup-pre.target     static  
cryptsetup.target         static  
ctrl-alt-del.target       disabled
default.target            enabled 
emergency.target          static  
等等等,只截取了一部分
  • systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit
  • systemctl get-default //查看系统默认的target
  • systemctl set-default multi-user.target //设置默认的target
代码语言:javascript
复制
[root@hf-01 system]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
[root@hf-01 system]# ls /etc/systemd/system/default.target
/etc/systemd/system/default.target
[root@hf-01 system]# ls -l !$
ls -l /etc/systemd/system/default.target
lrwxrwxrwx 1 root root 41 12月  5 07:49 /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.target
[root@hf-01 system]# 
  • 一个service属于一种类型的unit
  • 多个unit组成了一个target
  • 一个target里面包含了多个service
  • cat /usr/lib/systemd/system/sshd.service 看[install]部分
代码语言:javascript
复制
[root@hf-01 system]# cat /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
After=syslog.target network.target auditd.service

[Service]
EnvironmentFile=/etc/sysconfig/sshd
ExecStartPre=/usr/sbin/sshd-keygen
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
[root@hf-01 system]# 
  • 只有multi-user.target 里面的service可以设置开机启动。其他的target设置成默认启动无法正常启动。
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • target介绍
    • target相关命令
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档