Linux服务管理

                                    查询已安装的服务
RPM包安装的服务
chkconfig --list
#查看服务自启动状态,可以看到所有RPM包安装的服务。

源码包安装的服务
#查看服务安装位置,一般是/usr/local/下

                                     服务与端口
端口是什么?
如果把IP地址比做一间房子,端口就是出入这间房子的门。真正的房子只有几个门,但是一个IP地址的端口可以有65536个

 DNS同时有TCP53端口和UDP53端口。
                                     查询系统中开启的服务
· netstat -tlunp
  • -t列出tcp数据
  • -u列出udp数据
  • -l列出正在监听的网络服务(不包含已经连接的网络服务)
  • -n用端口号来显示服务,而不是用服务名
  • -p列出该服务的进程ID(PID)

·会列出系统中所有的已经启动的服务
                                      独立服务的启动
/etc/init.d/独立服务名
· star|stop|stutas|restart|

service 独立服务名
· start|stop|restart||status

centos 7以后就用systemctl start httpd 了 ,systemctl代替service和chkconfig了,跟课程不太一样.

netstat -tlun
-t或--tcp:显示TCP传输协议的连线状况;
-l或--listening:显示监控中的服务器的Socket;
-u或--udp:显示UDP传输协议的连线状况;
-n或--numeric:直接使用ip地址,而不通过域名服务器;

                             CentOS7下服务启动:
启动服务:
systemctl start httpd

停止服务:
systemctl stop httpd

重启服务(先停止,后启动):
systemctl restart httpd

重新加载(使用新的配置文件):
systemctl reload httpd

显示服务状态:
systemctl status httpd
                                 独立服务的自启动
自动运行某服务的指令
systemctl enable httpd
systemctl disable httpd
检查服务状态
systemctl is-enabled httpd
列举出所有服务的指令
systemctl list-unit-files --type=service

systemctl 和chkconfig 指令用法比较的表格
任务旧指令新指令
使某服务自动启动chkconfig –level 3 httpd onsystemctl enable httpd.service
使某服务不自动启动chkconfig –level 3 httpd offsystemctl disable httpd.service
检查服务状态service httpd statussystemctl status httpd.service
显示所有已启动的服务chkconfig –listsystemctl list-units –type=service
启动某服务service httpd startsystemctl start httpd.service
停止某服务service httpd stopsystemctl stop httpd.service
重启某服务service httpd restartsystemctl restart httpd.service
                             源码包服务的自启动
[root@localhost ~]# vi /etc/rc.d/rc.local
在最下面一行加入
/usr/local/apache2/bin/apachectl start

让源码包服务被服务管理命令识别:
ln -s /usr/local/apache2/bin/apachectl  /etc/rc.d/init.d/
就能直接service apachectl start启动源码包服务了


[root@localhost ~]# chkconfig --add apachectl
#把源码包apache加入chkconfig命令
键入ntsysv可见里面已经有了该服务

                                                      总结
   
以下是建议开启的服务:
                                      

posted @ 2018-05-06 19:47  whomhim  阅读(207)  评论(0编辑  收藏  举报