Linux 7 新命令之—lscpu和systemctl

联系:手机/微信(+86 17813235971) QQ(107644445)QQ咨询惜分飞

标题:Linux 7 新命令之—lscpu和systemctl

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

redhat 7 系列发布已经有一段时间了,最近抽时间看了下官方文档,对比了一些命令,对于其中比较关注的进行了记录,本篇主要是列出来了服务的管理改进,引进了systemctl管理和一个非常方便看cpu信息的命令lscpu
系统版本

[root@em12cdb ~]# uname -a
Linux em12cdb 3.8.13-55.1.6.el7uek.x86_64 #2 SMP Wed Feb 11 14:18:22 PST 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@em12cdb ~]# more /etc/oracle-release 
Oracle Linux Server release 7.1

查看cpu信息

[root@em12cdb ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2
On-line CPU(s) list:   0,1
Thread(s) per core:    1
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 60
Model name:            Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
Stepping:              3
CPU MHz:               3997.739
BogoMIPS:              7995.47
Hypervisor vendor:     VMware
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              8192K
NUMA node0 CPU(s):     0,1

systemctl命令管理服务和开机启动
以前主要是通过/etc/init.d/或者service命令管理服务,通过chkconfig管理是否开机启动

--查看某个服务状态
[root@em12cdb ~]# systemctl status crond.service
crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled)
   Active: active (running) since Mon 2015-07-27 11:59:16 CST; 1 months 7 days ago
 Main PID: 1245 (crond)
   CGroup: /system.slice/crond.service
           └─1245 /usr/sbin/crond -n

Jul 27 11:59:16 em12cdb systemd[1]: Started Command Scheduler.
Jul 27 11:59:16 em12cdb crond[1245]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 33% if used.)
Jul 27 11:59:17 em12cdb crond[1245]: (CRON) INFO (running with inotify support)

--停止某个服务
[root@em12cdb ~]# systemctl stop crond.service
[root@em12cdb ~]# systemctl status crond.service
crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled)
   Active: inactive (dead) since Thu 2015-09-03 00:27:55 CST; 2s ago
 Main PID: 1245 (code=exited, status=0/SUCCESS)

Jul 27 11:59:16 em12cdb systemd[1]: Started Command Scheduler.
Jul 27 11:59:16 em12cdb crond[1245]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 33% if used.)
Jul 27 11:59:17 em12cdb crond[1245]: (CRON) INFO (running with inotify support)
Sep 03 00:27:55 em12cdb systemd[1]: Stopping Command Scheduler...
Sep 03 00:27:55 em12cdb systemd[1]: Stopped Command Scheduler.

--启动某个服务
[root@em12cdb ~]# systemctl start crond.service
[root@em12cdb ~]# systemctl status crond.service
crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled)
   Active: active (running) since Thu 2015-09-03 00:28:08 CST; 1s ago
 Main PID: 7294 (crond)
   CGroup: /system.slice/crond.service
           └─7294 /usr/sbin/crond -n

Sep 03 00:28:08 em12cdb systemd[1]: Started Command Scheduler.
Sep 03 00:28:08 em12cdb crond[7294]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 56% if used.)
Sep 03 00:28:09 em12cdb crond[7294]: (CRON) INFO (running with inotify support)
Sep 03 00:28:09 em12cdb crond[7294]: (CRON) INFO (@reboot jobs will be run at computer's startup.)

--重启某个服务
[root@em12cdb ~]# systemctl restart crond.service
[root@em12cdb ~]# systemctl status crond.service
crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled)
   Active: active (running) since Thu 2015-09-03 00:28:24 CST; 2s ago
 Main PID: 7323 (crond)
   CGroup: /system.slice/crond.service
           └─7323 /usr/sbin/crond -n

Sep 03 00:28:24 em12cdb systemd[1]: Starting Command Scheduler...
Sep 03 00:28:24 em12cdb systemd[1]: Started Command Scheduler.
Sep 03 00:28:24 em12cdb crond[7323]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 61% if used.)
Sep 03 00:28:24 em12cdb crond[7323]: (CRON) INFO (running with inotify support)
Sep 03 00:28:24 em12cdb crond[7323]: (CRON) INFO (@reboot jobs will be run at computer's startup.)

--检查某个服务是否开机启动
[root@em12cdb ~]# systemctl is-enabled crond.service
enabled

--禁止某个服务开机启动
[root@em12cdb ~]# systemctl disable crond.service 
rm '/etc/systemd/system/multi-user.target.wants/crond.service'
[root@em12cdb ~]# systemctl is-enabled crond.service
disabled

--查看所有服务开机启动情况(这里使用了grep便于说明)
[root@em12cdb ~]# systemctl list-unit-files --type service|grep cron
crond.service                               disabled
[root@em12cdb ~]# systemctl enable crond.service 
ln -s '/usr/lib/systemd/system/crond.service' '/etc/systemd/system/multi-user.target.wants/crond.service'
[root@em12cdb ~]# systemctl list-unit-files --type service|grep cron
crond.service                               enabled 

systemctl chkconfig 对比


systemctl命令修改启动模式
以前版本中,直接通过vi修改/etc/inittab文件

--多用户图形界面
[root@em12cdb ~]# systemctl get-default
graphical.target

--多用户字符界面
[root@em12cdb ~]# systemctl set-default multi-user.target
rm '/etc/systemd/system/default.target'
ln -s '/usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default.target'
[root@em12cdb ~]# systemctl get-default
multi-user.target

systemd runlevel


此条目发表在 Linux 分类目录,贴了 , 标签。将固定链接加入收藏夹。

评论功能已关闭。