一、ntsysv服务配置工具linux
用来配置哪些服务开启或关闭,图形界面,使用键盘来操做。vim
安装ntsysv服务的命令:yum install -y ntsysvbash
直接运行命令ntsysv 弹出配置界面;
网络
按键盘的上下方向键进行移动,按空格键选择,中括号内显示有 * 表示开启,不然不开启。经过这个工具能够看到目前系统中的全部服务。建议除“crond,iptables,network,sshd,syslog,irqbalance,sedmail,microcode_ctl”外其余服务所有停掉。按tab键切换到OK,保存,重启机器才能生效;session
二、chkconfig服务管理工具ssh
linux系统全部的预设服务能够查看/etc/init.d/目录获得;ide
系统预设的服务能够经过命令:service 服务名 start|stop|restart|status 进行服务的中止或启动及查看状态;工具
这里的服务名就是/etc/init.d/目录下的系统预设服务,因此也可使用/etc/init.d/服务名 start|stop|restart 启动或中止服务;post
可使用chkconfig 或 chkconfig --list 列出全部的服务以及每一个级别是否开启:ui
这里的级别(0-6)就是/etc/inittab 对应的级别,0,1,6运行级别被系统保留,0为shutdown关机,1为重启到单用户模式,6为重启;在通常的linux系统实现中,都是用2,3,4,5几个级别;2级别为不带NFS的多用户模式;3为彻底多用户模式(最经常使用),4保留给用户自定义,5为图形界面登陆。
chkconfig --level 指定级别 服务名 on或者off 更改哪一个级别下的服务是否开启;
--level 能够省略,默认针对2,3,4,5级别操做;
示例:关闭crond服务;开启3级别下的crond服务;开启345级别的crond服务;
[root@yong ~]# chkconfig --list |grep crond crond 0:off1:off2:on3:on4:on5:on6:off [root@yong ~]# chkconfig crond off [root@yong ~]# chkconfig --list |grep crond crond 0:off1:off2:off3:off4:off5:off6:off [root@yong ~]# chkconfig --level 3 crond on [root@yong ~]# chkconfig --list |grep crond crond 0:off1:off2:off3:on4:off5:off6:off [root@yong ~]# chkconfig --level 345 crond on [root@yong ~]# chkconfig --list |grep crond crond 0:off1:off2:off3:on4:on5:on6:off
chkconfig还有一个功能能够把某个服务加入到系统服务,自定义的服务若是想要加到系统服务里面,拷贝可执行的服务到/etc/init.d/目录里面;加入系统服务以后可使用:service 服务名 start 操做,而且也能够在chkconfig --list列表中查找到,固然也能够删除掉;
chkconfig --del 服务名 删除服务
chkconfig --add 服务名 添加服务 这个功能经常使用在把自定义的启动脚本加入到系统服务中。
[root@yong ~]# chkconfig --del crond [root@yong ~]# chkconfig --list |grep crond [root@yong ~]# chkconfig --add crond [root@yong ~]# chkconfig --list |grep crond crond 0:off1:off2:on3:on4:on5:on6:off
三、linux系统日志
日志主要的功能有:审计和检测,还能够实时的监测系统状态,监测和追踪侵入者等等;
经常使用日志文件有/var/log/message 核心系统日志文件,包含了系统启动时的引导消息,以及系统运行时的其余状态消息。IO错误、网络错误和系统系统错误都会记录到这个文件中。另外其余信息,好比某我的的身份切换为root以及用户定义安装的软件日志也会在这里列出。
[root@yong ~]# ls /var/log/messages messages messages-20150407 messages-20150420 messages-20150330 messages-20150413
连同messages一共有5个日志文件,系统有一个日志轮询机制,每星期切换一个日志,按照日期格式生成。
系统轮询是经过logrotate工具的控制来实现的,配置文件为/etc/logrotate.conf 没有特殊需求请不要修改。
/var/log/messages 是由rsyslogd这个守护进程产生的,若是停掉这个服务则系统不会产生/var/log/messages,因此这个服务不要停。
rsyslogd服务的配置文件为/etc/rsyslogd.conf 定义了日志的级别;若是没有特殊需求也不要修改此配置文件。
dmesg 显示系统的启动信息,若是某个硬件有问题,也能够用这个命令查看。
last 用来查看登陆linux的历史信息
last命令输出信息其实是读取/var/log/wtmp 二进制文件,不用用cat vim head tail查看;
从左到右依次为:帐户名称、登陆终端、登陆客户端ip、登陆日期及时长。
lastb 查看无效的登陆历史,有人恶意登陆会记录; 其实是读取/var/log/btmp文件
/var/log/maillog 一样有5个maillog日志文件;
[root@yong ~]# head /var/log/maillog Apr 20 13:55:41 yong postfix/postfix-script[1980]: stopping the Postfix mail system Apr 20 13:55:41 yong postfix/master[1143]: terminating on signal 15
/var/log/secure 系统登陆的信息日志文件,记录验证和受权等方面的信息,好比ssh登陆系统成功或失败。
[root@yong ~]# tail /var/log/secure Apr 20 18:29:05 yong login: pam_unix(login:session): session closed for user root Apr 20 18:29:06 yong sshd[954]: Received signal 15; terminating. Apr 20 18:29:06 yong sshd[1863]: Exiting on signal 15 Apr 20 18:29:06 yong sshd[1863]: pam_unix(sshd:session): session closed for user root Apr 20 18:29:06 yong sshd[2040]: pam_unix(sshd:session): session closed for user user1 Apr 20 18:29:06 yong sshd[1863]: syslogin_perform_logout: logout() returned an error Apr 21 10:33:50 yong sshd[951]: Server listening on 0.0.0.0 port 22. Apr 21 10:33:50 yong sshd[951]: Server listening on :: port 22. Apr 21 10:39:11 yong sshd[986]: Accepted password for root from 192.168.20.1 port 61567 ssh2 Apr 21 10:39:11 yong sshd[986]: pam_unix(sshd:session): session opened for user root by (uid=0)