1、关闭不必要的服务

1.1、centos6.x服务操作命令

1.1.1、常用命令

查看服务开启或关闭状态:

[root@localhost ~]# chkconfig --list
aegis 0:off 1:off 2:on 3:on 4:on 5:on 6:off
agentwatch 0:off 1:off 2:on 3:on 4:on 5:on 6:off
atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
blk-availability 0:off 1:on 2:on 3:on 4:on 5:on 6:off
cloud-config 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cloud-final 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cloud-init 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cloud-init-local 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cloud-init-upgrade 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cloudmonitor 0:off 1:off 2:on 3:on 4:on 5:on 6:off
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ecs_mq-service 0:off 1:off 2:on 3:on 4:on 5:on 6:off
eni-service 0:off 1:off 2:on 3:on 4:on 5:on 6:off
htcacheclean 0:off 1:off 2:off 3:off 4:off 5:off 6:off
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
irqbalance 0:off 1:off 2:off 3:on 4:on 5:on 6:off
iscsi 0:off 1:off 2:off 3:on 4:on 5:on 6:off
iscsid 0:off 1:off 2:off 3:on 4:on 5:on 6:off
lvm2-monitor 0:off 1:on 2:on 3:on 4:on 5:on 6:off
mdmonitor 0:off 1:off 2:on 3:on 4:on 5:on 6:off
multipathd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
nscd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off
php-fpm 0:off 1:off 2:off 3:off 4:off 5:off 6:off
postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
rdisc 0:off 1:off 2:off 3:off 4:off 5:off 6:off
restorecond 0:off 1:off 2:off 3:off 4:off 5:off 6:off
rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off
saslauthd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
svnserve 0:off 1:off 2:off 3:off 4:off 5:off 6:off
sysstat 0:off 1:on 2:on 3:on 4:on 5:on 6:off
udev-post 0:off 1:on 2:on 3:on 4:on 5:on 6:off
xinetd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
xinetd based services:
chargen-dgram: off
chargen-stream: off
daytime-dgram: off
daytime-stream: off
discard-dgram: off
discard-stream: off
echo-dgram: off
echo-stream: off
rsync: off
tcpmux-server: off
time-dgram: off
time-stream: off
[root@localhost ~]#

单独查看某一个服务的状态:

[root@localhost ~]# chkconfig postfix --list
postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost ~]#

让某个服务开机不启动:

[root@localhost ~]# chkconfig postfix off
[root@localhost ~]# chkconfig postfix --list
postfix 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost ~]#

让某个服务在指定init级别启动:

[root@localhost ~]# chkconfig postfix --level 234 on
[root@localhost ~]# chkconfig postfix --list
postfix 0:off 1:off 2:on 3:on 4:on 5:off 6:off
[root@localhost ~]#

让某个服务在指定init级别关闭:

[root@localhost ~]# chkconfig postfix --level 234 off
[root@localhost ~]# chkconfig postfix --list
postfix 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost ~]#

让某个服务在所有级别(默认2345)都启动:

[root@localhost ~]# chkconfig postfix on
[root@localhost ~]# chkconfig postfix --list
postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost ~]#

查看系统服务的相关说明:

[root@localhost ~]# rpm -qi $(rpm -qf /etc/init.d/postfix)
Name : postfix Relocations: (not relocatable)
Version : 2.6.6 Vendor: CentOS
Release : 6.el6_7.1 Build Date: Tue 10 Nov 2015 05:59:54 PM HKT
Install Date: Wed 22 Aug 2018 11:38:05 AM HKT Build Host: c6b8.bsys.dev.centos.org
Group : System Environment/Daemons Source RPM: postfix-2.6.6-6.el6_7.1.src.rpm
Size : 10190116 License: IBM
Signature : RSA/SHA1, Tue 10 Nov 2015 08:41:47 PM HKT, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem http://bugs.centos.org
URL : http://www.postfix.org
Summary : Postfix Mail Transport Agent
Description :
Postfix is a Mail Transport Agent (MTA), supporting LDAP, SMTP AUTH (SASL),
TLS
[root@localhost ~]#

以上命令只适用于系统自带的服务,或者用yum和rpm安装的一些服务,如果是自己源码安装的,可能没这么详细。

自己安装了一些服务之后,可以手动将它们加进系统服务管理中:

如何增加一个服务:

1、服务脚本必须存放在/etc/ini.d/目录下;

2、chkconfig --add servicename

在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了;

3.chkconfig --level35 mysqld on

修改服务的默认启动等级。

1.1.2、关闭不需要的服务

这里,postfix服务是提供邮件服务的,这里我们并没有用到,所以我们选择把它关闭

[root@localhost ~]# chkconfig postfix off

[root@localhost ~]# chkconfig postfix --list

postfix         0:off 1:off 2:off 3:off 4:off 5:off 6:off

[root@localhost ~]#

服务可能在运行,我们让服务现在就关闭:

[root@localhost ~]# service postfix stop
Shutting down postfix: [ OK ]
[root@localhost ~]# service postfix status
master is stopped
[root@localhost ~]#

其它服务也一样操作,下面我们会列出一个可以关闭的服务列表。

1.2、Centos7.x服务操作命令

1.2.1、常用命令

查看服务开启或关闭状态:

CentOS7已不再使用chkconfig 管理启动项,使用systemctl工具来管理服务程序,包括了service和chkconfig

启动一个服务: systemctl start firewalld.service

关闭一个服务: systemctl stop firewalld.service

重启一个服务: systemctl restart firewalld.service

显示一个服务的状态: systemctl status firewalld.service

在开机时启用一个服务: systemctl enable firewalld.service

在开机时禁用一个服务: systemctl disable firewalld.service

查看服务是否开机启动: systemctl is-enabled firewalld.service;echo $?

查看已启动的服务列表: systemctl list-unit-files|grep enabled

使用 systemctl list-unit-files 可以查看各个服务的状态,这个信息有点多,

所以我们过滤一下打开的:

[root@localhost ~]# systemctl list-unit-files | grep enable
auditd.service enabled
autovt@.service enabled
crond.service enabled
dbus-org.fedoraproject.FirewallD1.service enabled
firewalld.service enabled
getty@.service enabled
irqbalance.service enabled
kdump.service enabled
lvm2-monitor.service enabled
microcode.service enabled
NetworkManager-wait-online.service enabled
postfix.service enabled
rsyslog.service enabled
sshd.service enabled
systemd-readahead-collect.service enabled
systemd-readahead-drop.service enabled
systemd-readahead-replay.service enabled
tuned.service enabled
vmtoolsd.service enabled
xinetd.service enabled
dm-event.socket enabled
lvm2-lvmetad.socket enabled
lvm2-lvmpolld.socket enabled
default.target enabled
multi-user.target enabled
remote-fs.target enabled
runlevel2.target enabled
runlevel3.target enabled
runlevel4.target enabled
[root@localhost ~]#

1.2.2、关闭不需要的服务

同上面一样,接下来我们关闭postfix服务。

[root@localhost ~]# systemctl disable postfix.service
Removed symlink /etc/systemd/system/multi-user.target.wants/postfix.service.
[root@localhost ~]#
[root@localhost ~]# systemctl list-unit-files | grep postfix
postfix.service disabled

关闭正在运行的postfix

[root@localhost ~]# systemctl stop postfix.service

1.3、系统启动项列表

参考:https://blog.csdn.net/alexdream/article/details/10955797

https://www.cnblogs.com/jonsea/p/5571267.html

https://www.getlinux.cn/centos7-x-chang-yong-fu-wu-jian-jie.html

服务名称

功能

默认

建议

备注

aegis

阿里云安骑士

on

on

agentwatch

阿里云Ecs监控

on

on

atd

计划任务,/etc/at.allow,/etc/at.deny

on

off

可用crond代替

auditd

配合selinux审核

on

off

autovt

登录相关

on

on

blk-availability

lvm2相关

on

on

有lvm就开

cloud-config

Ecs云配置,配合cloud-init

on

on

cloud-final

配合cloud-init

on

on

cloud-init

云初始化服务

on

on

cloud-init-local

配合cloud-init

on

on

cloud-init-upgrade

配合cloud-init

on

on

cloudmonitor

云监控

on

on

crond

计划任务

on

on

dbus-org.fedoraproject.FirewallD1

桌面网卡管理

on

off

default.target

默认启动项

on

on

multi-user.target

同default.target

on

on

ecs_mq-service

Ecs相关

on

on

eni-service

Ecs网卡相关

on

on

firewalld

Centos7的默认防火墙

on

off

getty

tty控制台相关 保留

on

on

htcacheclean

Apache清除磁盘缓存

off

off

httpd

http服务器

off

off

看需要,可用Nginx代替

ip6tables

ipv6防火墙

on

off

不用ipv6就关闭

iptables

ipv4防火墙

on

on

看需要,阿里云安全组可代替

irqbalance

cpu负载均衡

on

on

多核cpu需要

iscsi

网络存储相关,san

on

off

看需要

iscsid

网络存储相关,san

on

off

kdump

内核崩溃信息捕获

on

on

看需要

lvm2-monitor

Lvm监控

on

on

有lvm就开

mdmonitor

软raid监控

on

on

建议开

microcode

处理器稳定性增强 保留

on

on

multipathd

off

off

NetworkManager-wait-online

网卡守护进程 关闭

on

off

netconsole

网络驱动程序调试用

off

off

netfs

网络文件系统

on

off

有用nfs可以开

network

启动是激活网络接口

on

on

必须开

nscd

name cache,应该与DNS相关

off

off

ntpd

自动对时服务

on

on

ntpdate

自动对时服务

off

off

php-fpm

Php解释器

off

off

用到开

postfix

替代sendmail的邮件服务器

on

off

rdisc

自动检测路由器

off

off

restorecond

selinux相关

off

off

用selinux就开

rsyslog

系统的日志服务

on

on

必须开

saslauthd

sasl认证服务相关

off

off

sshd

ssh服务端

on

on

必须开

svnserve

Svn服务端

off

off

服务端开,客户端关闭

sysstat

系统状态监测命令提供 iostat 和 sar

on

on

systemd-readahead-collect

内核调用--预读取 保留

on

on

systemd-readahead-drop

--

systemd-readahead-replay

--

dm-event

设备映射用

on

on

udev-post

设备管理系统

on

on

xinetd

超级守护进程

on

off

用到可以开

remote-fs.target

远程挂载文件系统

on

off

用到再开

runlevel2.target

运行级别 用于兼容6的SysV

on

on

runlevel3.target

--

on

on

runlevel4.target

--

on

on

Linux安全加固--精简启动项的更多相关文章

  1. windows和linux双系统修改启动项

    在windows系统的基础上再装linux系统的时候,电脑启动就会出现linux的启动引导项,默认的是进入linux.要使电脑默认进入windows只需要修改linux系统的启动引导文件(grub.c ...

  2. Linux下修改efi启动项

    Linux下有一个efibootmgr工具可以编辑efi启动项,十分方便,简单介绍如下 直接运行efibootmgr会显示出当前所有efi启动项,每个启动项前都有相应编号, 可以使用efibootmg ...

  3. 「linux」win+linux 双系统 默认启动项 的修改

    修改/etc/default/grub文件,其中的GRUB_DEFAULT表示默认启动项: sudo gedit /etc/default/grub 注意:启动项是从0开始计数. 要使修改生效需要运行 ...

  4. Linux残留的EFI启动项删除后又恢复的问题

    电脑Windows + Fedora双系统,UEFI启动,共用同一个EFI分区.现在删除了Fedora系统,那么应该将EFI分区中的Fedora启动项也删除之. 按照网上的办法,在Windows上,尝 ...

  5. Linux设置开机启动项

    第一种方式:ln -s 建立启动软连接 在Linux中有7种运行级别(可在/etc/inittab文件设置),每种运行级别分别对应着/etc/rc.d/rc[0~6].d这7个目录 Tips:/etc ...

  6. Linux minilogd占用内存过高及开机启动项修改

    minilogd: 今天发现一台服务起的内存正常占用应该在70左右,但是内存占用却到了90%以上,用top查看发现minilogd占用了30%左右的内存,是不符合预期的,查看开机启动项并无minilo ...

  7. linux 设置开机启动项两种方式

    原文链接:http://blog.csdn.net/karchar/article/details/52489572 有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务. 在解问题之前 ...

  8. Linux 添加开机启动项的三种方法

    linux 添加开机启动项的三种方法. (1)编辑文件 /etc/rc.local 输入命令:vim /etc/rc.local 将出现类似如下的文本片段: #!/bin/sh## This scri ...

  9. Linux 系统开机启动项清理

    一般情况下,常规用途的 Linux 发行版在开机启动时拉起各种相关服务进程,包括许多你可能无需使用的服务,例如蓝牙bluetooth.Avahi. 调制解调管理器ModemManager.ppp-dn ...

随机推荐

  1. hadoop 常用端口 及模块介绍

    50070                 namenode http port 50075                 datanode   http  port 50090          ...

  2. mysql show status 参数解析

    状态名 作用域 详细解释 Aborted_clients Global 由于客户端没有正确关闭连接导致客户端终止而中断的连接数 Aborted_connects Global 试图连接到MySQL服务 ...

  3. 【277】◀▶ Python 列表/元组/字典说明

    目录: 前言 一.访问列表中的值 二.更新列表 三.删除列表元素 四.Python 列表脚本操作符 五.Python 列表函数 & 方法 参考:Python 列表(List)使用说明 列表截取 ...

  4. oracle中函数和存储过程的区别和联系

    oracle中函数和存储过程的区别和联系 在oracle中,函数和存储过程是经常使用到的,他们的语法中有很多相似的地方,但也有自己的特点.刚学完函数和存储过程,下面来和大家分享一下自己总结的关于函数和 ...

  5. Ajax入门(一)从0开始到一次成功的GET请求

    什么是服务器 网页浏览过程分析 一个完整的HTTP请求过程,通常有下面7个步骤 建立TCP连接 Web浏览器向Web服务器发送请求命令 Web浏览器发送请求头信息 Web服务器- 应答 Web服务器- ...

  6. 面试题: 1天的java面试题 已看1

    1,自我介绍下,我直接说的项目经历,(哪年在哪个公司呆过) 2,问是否有带过团队的经历,我说去年带过一次. 3,Struts是单例模式还是多例模式?我先说单例模式,后说多例模式. Struts1是单例 ...

  7. STM32 C++编程 005 I2c(Soft)类

    使用 C++ 语言给 STM32 编写一个 I2c(Soft)类 我使用的STM32芯片:STM32F103ZET6 我们使用的STM32库版本:V3.5.0 注意: 想学习本套 STM32 C++编 ...

  8. Luogu 4139 上帝与集合的正确用法

    扩展欧拉定理:$a^{b} \equiv a^{b Mod \varphi  (p) + \varphi  (p)}  (Mod  p)  $ $(b \geq \varphi (p))$ . 这道题 ...

  9. AJAX的dataType问题

    dataType是预期服务器返回的数据类型.如果不指定,jQuery 将自动根据 HTTP 包 MIME 信息来智能判断,比如 XML MIME 类型就被识别为 XML.在 1.4 中,JSON 就会 ...

  10. Android中常见的内存泄漏

    为什么会产生内存泄漏? 当一个对象已经不需要再使用了,本该被回收时,而有另外一个正在使用的对象持有它的引用从而导致它不能被回收,这导致本该被回收的对象不能被回收而停留在堆内存中,这就产生了内存泄漏. ...