10.23-10.27 corn, chkconfig, systemd, unit, target

八周一次课(3月26日)
10.23 linux任务计划cron
10.24 chkconfig工具
10.25 systemd管理服务
10.26 unit介绍
10.27 target介绍

扩展
1. anacron  http://blog.csdn.net/strikers1982/article/details/4787226
2. xinetd服(默认机器没有安装这个服务,需要yum install xinetd安装)   http://blog.sina.com.cn/s/blog_465bbe6b010000vi.html
3. systemd自定义启动脚本  http://www.jb51.net/article/100457.htm

10.23 linux任务计划cron

介绍

任务计划,在linux上是必不可少的。

任务计划的配置文件

[[email protected] ~]# cat /etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

# For details see man 4 crontabs

# Example of job definition:

# .---------------- minute (0 - 59)

# |  .------------- hour (0 - 23)

# |  |  .---------- day of month (1 - 31)

# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...

# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

# |  |  |  |  |

# *  *  *  *  * user-name  command to be executed

MAILTO=root 发送邮给指定root用户

SHELL=/bin/bash 使用的shell

PATH=/sbin:/bin:/usr/sbin:/usr/bin 环境变量,使用的命令路径

日期

***** 从左到右:

分钟

月(可以英文简写,jan,feb,mar,apr)

周几(0-6,0和7表示星期日,可以英文简写sun,mon,tue,wed,thu,fri,sat)

用户(不写用户名表示root)

最后一行是命令

格式演示

进入任务计划配置文件命令#crontab -e,这操作跟vim用法一样,只是换了方式来打开配置文件,但是不能直接用vi/vim来修改配置文件。

[[email protected] ~]#  crontab -e

演示示例,凌晨3点去执行任务(执行命令,在日期后面放上即可)。

任务内容为,执行脚本/bin/bash 脚本名字/usr/local/sbin123.sh

指定输出日志,正确输出到从定向文件/tmp/123.log,错误的输出定义到/tmp/123.log 如果每天都需要操作记录,利用来追加>>

以下参数:

0 3 * * *  /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log

范围用法,

分范围0-59,时范围0-23,日范围1-31,月范围1-12,周1-7

双月(能整除2的月份)的1-10号每周2周5的3点执行

0 3 1-10 */2 2,5  /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log

启动crontab服务

[[email protected] ~]# systemctl start crond

[[email protected] ~]# ps ux |grep cron

root       567  0.0  0.1 126236  1616 ?        Ss   16:29   0:00 /usr/sbin/crond -n

root      2211  0.0  0.0 123208   780 ?        Ss   17:01   0:00 /usr/sbin/anacron -s

root      2354  0.0  0.0 112676   980 pts/0    S+   17:19   0:00 grep --color=auto cron

此命令也可以查看crond服务状态

[[email protected] ~]# systemctl status crond

要保证服务是启动状态,

否则会无效。

注意

如果发现计划不生效

有可能是没有用绝对路径,

键入绝对路径(最稳),也可以在脚本里添加变量,然后后面参数敲入相应参数即可。

每写一个任务计划,都要追加日志(正确错误输出,)。

#crontab -l 列出计划任务

例如,

#crontab -e 添加以下计划任务

1 10 * 2 * /usr/bin/find /tmp/ -type f -mtime +100 |xargs rm -f

[[email protected] ~]# crontab -l

1 10 * 2 * /usr/bin/find /tmp/ -type f -mtime +100 |xargs rm -f

crontab -l可以查看计划任务。

crontab的文件路径/cron/下的文件,就是对应的用户,例如root就以root命名文件。

#cat /var/spool/cron/root

crontab

-l 列出任务计划

-e 编辑任务计划

-r 删除任务计划

-u 指定用户

10.24 chkconfig工具

Linux系统服务管理-chkconfig

chkconfig是一种服务。

chkconfig是centos7以前使用的版本。

sysv centos7以前的服务管理基制。

systmd centos7的服务管理基制。ps进程排第一,init在centos6进程排第一。

chkconfig命令

[[email protected] ~]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含

原生 systemd 服务。SysV 配置数据

可能被原生 systemd 配置覆盖。

要列出 systemd 服务,请执行 'systemctl list-unit-files'。

查看在具体 target 启用的服务请执行

'systemctl list-dependencies [target]'。

netconsole     0:关 1:关 2:关 3:关 4:关 5:关 6:关

network         0:关 1:关 2:开 3:开 4:开 5:开 6:关

chkconfig在centos7下面只剩下这2个服务。

chkconfig服务脚本的目录,MySQL以后也会用到此脚本

[[email protected] ~]# ls /etc/init.d/

functions  netconsole  network  README

更改network服务状态,例如off它们

[[email protected] ~]# chkconfig network off

[[email protected] ~]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含

原生 systemd 服务。SysV 配置数据

可能被原生 systemd 配置覆盖。

要列出 systemd 服务,请执行 'systemctl list-unit-files'。

查看在具体 target 启用的服务请执行

'systemctl list-dependencies [target]'。

netconsole     0:关 1:关 2:关 3:关 4:关 5:关 6:关

network         0:关 1:关 2:关 3:关 4:关 5:关 6:关

再次开启利用on

[[email protected] ~]# chkconfig network on

[[email protected] ~]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含

原生 systemd 服务。SysV 配置数据

可能被原生 systemd 配置覆盖。

要列出 systemd 服务,请执行 'systemctl list-unit-files'。

查看在具体 target 启用的服务请执行

'systemctl list-dependencies [target]'。

netconsole     0:关 1:关 2:关 3:关 4:关 5:关 6:关

network         0:关 1:关 2:开 3:开 4:开 5:开 6:关

此处数字0-6 是一个运行级别 一共7个级别

0表示关机

1单用户 centos6 及之前的系统版本实用,如果定位至1级别,开机就会自动进入单用户模式。

2多用户模式,不带图形 2比3少了一个nfs服务

3多用户模式,不带图形

4保留级别

5多用户,带图形

6重启 如果定位6级别,启动就会重启。

更改inittab文件,可以更改运行级别。

#vi /etc/inittab

指定某个级别关闭或开启,

[[email protected] ~]# chkconfig --level 3 network off

[[email protected] ~]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含

原生 systemd 服务。SysV 配置数据

可能被原生 systemd 配置覆盖。

要列出 systemd 服务,请执行 'systemctl list-unit-files'。

查看在具体 target 启用的服务请执行

'systemctl list-dependencies [target]'。

netconsole     0:关 1:关 2:关 3:关 4:关 5:关 6:关

network         0:关 1:关 2:开 3:关 4:开 5:开 6:关

如果需要几个级别一起开启或者关闭,可以同一条命令连着级别来写,例如格式:

# chkconfig --level 345 network on 此处345 on 表示运行级别的345都开启

[[email protected] ~]# chkconfig --level 345 network on

[[email protected] ~]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含

原生 systemd 服务。SysV 配置数据

可能被原生 systemd 配置覆盖。

要列出 systemd 服务,请执行 'systemctl list-unit-files'。

查看在具体 target 启用的服务请执行

'systemctl list-dependencies [target]'。

netconsole     0:关 1:关 2:关 3:关 4:关 5:关 6:关

network         0:关 1:关 2:开 3:开 4:开 5:开 6:关

把脚本加入到服务列表

chkconfig --add 服务

示例:

[[email protected]701 ~]# cd /etc/init.d/

[[email protected] init.d]# ls

functions  netconsole  network  README

[[email protected] init.d]# cp network 123

[[email protected] init.d]# ls

123  functions  netconsole  network  README

[[email protected] init.d]# chkconfig --add 123

[[email protected] init.d]# chkconfig --list

123             0:关 1:关 2:开 3:开 4:开 5:开 6:关

netconsole     0:关 1:关 2:关 3:关 4:关 5:关 6:关

network         0:关 1:关 2:开 3:开 4:开 5:开 6:关

文件名无条件要求,但是文件内容有要求,具体参考# vi network

shell脚本,

2345启动顺序,

运行级别启动顺序第十位10位启动

第90位关闭

描述

删除123服务

chkconfig --del 123

10.25 systemd管理服务

systemd是centos7服务管理机制

列出所有service,以及描述

#systemctl list-units --all --type=service

几个常用的服务相关的命令

让服务开机启动 (.service可以不用加)

#systemctl enable crond.service

生成软链接文件

不让开机启动

#systemctl disable crond

查看状态

#systemctl status crond

停止服务

#systemctl stop crond

启动服务

#systemctl start crond

重启服务

#systemctl restart crond

检查服务是否开机启动

#systemctl is-enabled crond

10.26 unit介绍

Linux系统服务管理-systemd

ls /usr/lib/systemd/system //系统所有unit,分为以下类型

service 系统服务

target 多个unit组成的组

单用户,emygrcym model,centos6 7个运行级别。centos7有类似的级别

[[email protected] system]# cd /usr/lib/systemd/system

[[email protected] system]# ls -l runlevel*

lrwxrwxrwx. 1 root root 15 3月   8 05:05 runlevel0.target -> poweroff.target

lrwxrwxrwx. 1 root root 13 3月   8 05:05 runlevel1.target -> rescue.target

lrwxrwxrwx. 1 root root 17 3月   8 05:05 runlevel2.target -> multi-user.target

lrwxrwxrwx. 1 root root 17 3月   8 05:05 runlevel3.target -> multi-user.target

lrwxrwxrwx. 1 root root 17 3月   8 05:05 runlevel4.target -> multi-user.target

lrwxrwxrwx. 1 root root 16 3月   8 05:05 runlevel5.target -> graphical.target

lrwxrwxrwx. 1 root root 13 3月   8 05:05 runlevel6.target -> reboot.target

上面  runlevel0.target -> poweroff.target中的runlevel10.target是软链接,真正的文件是poweroff.targt

target是由多个unit组成的一个组,而unit又由多个services组成的组。

不用深究以下几点

device 硬件设备

mount 文件系统挂载点

automount 自动挂载点

path 文件或路径

scope 不是由systemd启动的外部进程

slice 进程组

snapshot systemd快照

socket 进程间通信套接字

swap  swap文件

timer 定时器

system的服务

#ls /usr/lib/systemd/system

unit相关的命令

systemctl list-units 列出正在运行的unit

systemctl list-units --all 列出所有,包括失败的或者inactive的

systemctl list-units --all --state=inactive //列出inactive的unit

systemctl list-units --type=service 列出状态为active的service

不加--all的话active列会显示全部active和failed(个别)

systemctl is-active crond.service 查看某个服务是否为active

[[email protected]entos701 system]#  systemctl is-active crond.service

active

10.27 target介绍

介绍

系统为了方便管理用target来管理unit

显示系统所有的target

#systemctl list-unit-files --type=target

查看指定target下面有哪些unit

#systemctl list-dependencies multi-user.target

大部分都是.service

查看系统默认的target

#systemctl get-default

[[email protected] system]# systemctl get-default

multi-user.target

设定默认运行级别。

设定开机运行级别,相当于修改chkconfing的默认开机运行级别。

#systemctl set-default multi-user.target

[[email protected] 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.

一个service属于一种类型的unit

多个unit组成了一个target

一个target里面包含了多个service

cat /usr/lib/systemd/system/sshd.service //看[install]部分

总结:

系统由多种units组成的,unit是由target去管理,也就是说target由很多unit组成的。

原文地址:http://blog.51cto.com/13578154/2091451

时间: 2024-07-31 01:35:53

10.23-10.27 corn, chkconfig, systemd, unit, target的相关文章

Linux20180511八周一次课cron chkconf systemd unit target

八周一次课(5月11日) 10.23 linux任务计划cron10.24 chkconfig工具10.25 systemd管理服务10.26 unit介绍10.27 target介绍扩展1. anacron http://blog.csdn.net/strikers1982/article/details/47872262. xinetd服(默认机器没有安装这个服务,需要yum install xinetd安装)http://blog.sina.com.cn/s/blog_465bbe6b01

10.23 linux任务计划cron10.24chkconfig工具10.25 systemd管理服务10.26 unit介绍 10.27 target介绍

- 10.23 linux任务计划cron - 10.24 chkconfig工具 - 10.25 systemd管理服务 - 10.26 unit介绍 - 10.27 target介绍 - 扩展 1. anacron http://blog.csdn.net/strikers1982/article/details/4787226  2. xinetd服(默认机器没有安装这个服务,需要yum install xinetd安装) http://blog.sina.com.cn/s/blog_46

10.23 linux任务计划cron 10.24 chkconfig工具 10.25 system

八周一次课 10.23 linux任务计划cron 10.24 chkconfig工具 10.25 systemd管理服务 10.26 unit介绍 10.27 target介绍 10.23 linux任务计划cron 10.24 chkconfig工具 显示chkconfig服务 系统启动服务在inittab 10.25 systemd管理服务 10.26 unit介绍 10.27 target介绍 原文地址:http://blog.51cto.com/wbyyy/2066113

2016.10.23大型在职研究生招生说明会

气温骤降,金秋已值,一年一度的十月攻坚战开始了.伴随着在职研究生新政的颁布,北京地区各大院校在职研究生的新简章轮番更新,给很多准备报考在职研究生的学员带来了各种混乱以及忐忑. 正巧,2016年秋季大型在职研究生招生说明会即将在北京国家图书馆召开.不管你对在职研究生有多少疑问,这次会议都会给你一个完美的解释. 10月23日北京地区大型在职研究生招生说明会有必要去吗?去了以后真的能解决所有疑惑吗? 其实啊,我们在9月17日已经成功举办了一次北京大型在职研究生说明会,通过9.17说明会的完美收官总结一

同侪隐修录 (2016-12-25 23:10:21)转载▼

同侪隐修录 (2016-12-25 23:10:21)转载▼ 标签: 武术史 武学 孙氏拳前辈多隐修者,不仅孙存周先生1949年后基本处于隐修状态,鲜与武术界往来,同辈中武艺高明者如裘徳元.齐公博等先生亦如是.这种隐修的气质在孙门内颇为普遍,及至我辈,同侪中之武艺高明者几乎皆如此,如董岳山.陈垣.牟八爷.驼五爷.肖德昌等,不一而足.即使是以票友自称的侪辈高手,如圆觉和尚.胡六爷.何回子.支一峰.刘子明等先生也是隐修自娱,鲜为人知.其他人如张兆麒.李梦庚.章仲华.关秉之.张烈等先生其为人大体也是此

2014.10.23安卓全球开发者大会经历

2014.10.23安卓全球开发者大会经历 by 伍雪颖 2014.10.23 2014安卓全球开发者大会 作为一个程序员,怀着激动的心情,大老远的从深圳南山赶到福田香格里拉酒店,听了一天后其实是很失望地回来的: 1.中国分几个区同时进行,就深圳区是免费入场的,所以深圳区的活动质量是最差的 2.全场在做广告的偏多 3.挂着"安卓全球开发者"的羊头,卖着扯皮的狗肉 4.雷军说好要来的,最后大概意思是深圳都是做广告的,来了没意思 5.说实在的,干货不多 上午赶过去因为半路塞车了,11点多才

10.23 考试总结

10.23 考试总结 救火行动 不得不说还是想问候一下出题人的,那个白色的字是什么鬼.....不过看到了不要喧哗倒是很有意思 所以就是一个大模拟题.....因为比较麻烦,只不过数据很小,纯模拟循环都可以过的说. 考试的时候没有注意到一个点就是可以直接灭火的时候当前这一轮是不算这层着火的,也就是说第五层的火势应该只涨i-1 稍微注意一下这个就可以了,然后就还好,其余的还是都有好好注意到的 打篮球 这个题目我是考试的时候一下没有相同怎么建图....实际上暴力枚举各种参数就可以了. 然后就是纯最短最长

2017.10.23 大盘观后感

今天大盘好无聊,上上下下就几个点,持有的股票全天几乎没有涨,最近行情很无聊. 操作大专栏  2017.10.23 大盘观后感ng>:无 策略:继续保持低仓位的持股不动 持仓:继续战略持有中南和格力,保持定力,趁着股市清单看看书也挺好. 预计:预计到年底前都不会有上涨行情,反而下跌的概率比较大,预计能跌到3100点左右(不过现在属于国家队坐庄模式,已经不能用点数来决定个股的涨跌了) 原文地址:https://www.cnblogs.com/wangziqiang123/p/11696388.htm

背水一战 Windows 10 (23) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令

[源码下载] 作者:webabcd 介绍背水一战 Windows 10 之 MVVM(Model-View-ViewModel) 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令 示例1.ModelMVVM/Model/Product.cs /* * Model 层的实体类,如果需要通知则需要实现 INotifyPropertyChanged 接口 */ using System.ComponentModel; namespace Wind