Linux服务管理

一、前言

“差以毫厘,谬以千里”

“长风破浪会有时,直挂云帆济沧海”

“臣心一片磁针石,不指南方不肯休”

“沉舟侧畔千帆过,病树前头万木春”

“吃一堑,长一智”

“尺有所短,寸有所长”

静心~!

二、服务管理

服务的简单介绍

Linux的服务:

  • RPM安装
    • 独立的服务:自己安装了就可以自己启动,不用依赖别的服务来支持
      • 启动:
        • /etc/rc.d/init.d/httpd start|stop
        • service httpd start| stop |
      • 自启动
        • chkconfig --level 2345 httpd on|off
        • echo "/etc/rc.d/init.d/httpd start" >> /etc/rc.local 追加到文件中
        • ntsysv 图形化修改开机自启动
    • 基于xinetd服务:需要启动xinetd服务来支持的,只有xinetd占内存-->其他人占的是它的资源
      • 启动:
        • vim /etc/xinetd.d/telnet "disabled = no";
        • service xinetd restart
      • 自启动:
        • chkconfig telnet on
        • ntsysv-->图形化启动
#以telnet服务为准-->基于xinted服务
[root@Master ~]# yum -y install telnet-server
....省略....
Installed:
  telnet-server.x86_64 1:0.17-48.el6                                            

Dependency Installed:
  xinetd.x86_64 2:2.3.14-40.el6

#查看基于xinetd的服务
[root@Master ~]# ls /etc/xinetd.d/
chargen-dgram   daytime-stream  echo-dgram   tcpmux-server  time-stream
chargen-stream  discard-dgram   echo-stream  telnet
daytime-dgram   discard-stream  rsync        time-dgram
  
#如何启动telnet?
[root@Master ~]# vim /etc/xinetd.d/telnet 
# default: on
# description: The telnet server serves telnet sessions; it uses \
#       unencrypted username/password pairs for authentication.
service telnet
{
        flags           = REUSE
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/sbin/in.telnetd
        log_on_failure  += USERID
        disable         = no            #修改这个
#然后重启xinted服务
[root@Master ~]# service xinetd restart
停止 xinetd:                                              [失败]
正在启动 xinetd:                                          [确定]
  • 源码包安装
    • 启动
      • /usr/local/nginx/sbin/nginx start| restart
    • 自启动
      • echo "/usr/local/nginx/sbin/nginx start" >> /etc/rc.local

Linux的优化原则:

  • 把不需要用到的服务都关掉
  • 服务器的安装方法不同,启动的方式也会不同
  • RPM安装和源码包安装-->很大的区别就是安装的位置不同

chkconfig命令

作用:查看开机自启动的独立服务

语法:

  • chkconfig 【选项】 默认级别 服务名
  • chkconfig --level 3 httpd on|off

常用选项

  • --list:列出rpm安装的自动服务
  • --level:指定运行级别
#查看
[root@Master ~]# chkconfig --list

#设定开机自启动
[root@Master ~]# chkconfig --level 35 httpd on
[root@Master ~]# chkconfig --list | grep httpd
httpd          	0:off	1:off	2:off	3:on	4:off	5:on	6:off

ntsysv命令

作用:图形化设置开机自启动服务

空格-->选定,打上*号代表能够开机自启动

源码服务-->service|chkconfig管理-->实验

第一步:确认没有rpm安装的nginx

[root@Master httpd-2.2.29]# rpm -qa httpd
[root@Master httpd-2.2.29]# service httpd restart 
httpd: unrecognized service
[root@Master ~]# chkconfig --list httpd
error reading information on service httpd: No such file or directory

第二步:软连接启动方式

[root@Master ~]# ln -s /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
[root@Master ~]# ll /etc/rc.d/init.d/httpd 
lrwxrwxrwx. 1 root root 31 Jan  1 23:20 /etc/rc.d/init.d/httpd -> /usr/local/apache/bin/apachectl

第三步:启动查看

[root@Master ~]# service httpd start
httpd: apr_sockaddr_info_get() failed for Master
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[root@Master ~]# ps -ef | grep httpd
root      58463      1  0 23:20 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    58464  58463  0 23:20 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    58465  58463  0 23:20 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    58466  58463  0 23:20 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    58467  58463  0 23:20 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    58468  58463  0 23:20 ?        00:00:00 /usr/local/apache/bin/httpd -k start
root      58470   2142  0 23:21 pts/1    00:00:00 grep httpd

第四步:调整chkconfig识别

手工修改httpd的启动文件

添加:

#添加一下两句话
[root@Master ~]# vim /etc/rc.d/init.d/httpd 
....省略...
#chkconfig: 35 86 76
#description: hahaha


#这里需要注意
上面两句一定要加,并且需要丼号注释,不然会报错
35:代表的是运行级别,3级别和5级别
86/76分别就是在/etc/init.d/下的启动与取消

第五步:

加入chkconfig --add

[root@Master ~]# chkconfig --add httpd
[root@Master ~]# chkconfig --list | grep httpd
httpd          	0:off	1:off	2:off	3:on	4:off	5:on	6:off


#删除:--del
[root@Master ~]# chkconfig --del httpd
[root@Master ~]# chkconfig --list | grep httpd

 

三、结束

“纵然是在自己心底一片狼藉的时候,我们还努力地保持着一片净土,保持着对周围那些纯净心灵的理解和赞赏,时刻提醒着自己:生命之中,还是有很多美好的东西值得我们去珍惜”

“或许只有在孤独中,我们才可以静静地、默默地谛听,谛听这个灯火阑珊的城市,谛听城市之外的旷野、远山,和比远山更远的一切生生不息的律动,同时也谛听自己生命的足音以及深邃的内心”

“或许在孤独中,我们才能强烈意识到生命荣枯兴衰的不朽轮回,从而坦然应对到来的一切。人生旅途中孤独是必然的,在真正的孤独中我们才能不断地成长”

“以清净心看世界,以欢喜心过生活,以平常心生情味,以柔软心除挂碍”

互勉~!

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Liang_GaRy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值