Linux软件服务管理
学习该课程之前先学习linux的软件安装管理
1、linux的运行级别有下面几种类型
在后面的服务启动管理之中会被使用到
[root@weiyuan httpd-2.4.20]# runlevel
N 5
如果使用 init 0 就会让电脑关机,但是不一定可靠,最好使用shutdown -r now命令
linux的服务管理分为下面的两种形式
基于rpm默认安装的的服务管理
基于源代码安装的服务管理
[weiyuan@weiyuan 下载]$ chkconfig --list 是不能查看源码包的安装的服务的
[weiyuan@weiyuan 下载]$ netstat -tlunp
(No info could be read for "-p": geteuid()=500 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:36763 0.0.0.0:* LISTEN -
tcp 0 0 :::111 :::* LISTEN -
tcp 0 0 :::59892 :::* LISTEN -
tcp 0 0 :::22 :::* LISTEN -
tcp 0 0 ::1:631 :::* LISTEN -
tcp 0 0 ::1:25 :::* LISTEN -
udp 0 0 0.0.0.0:10000 0.0.0.0:* -
udp 0 0 0.0.0.0:685 0.0.0.0:* -
udp 0 0 0.0.0.0:958 0.0.0.0:* -
udp 0 0 0.0.0.0:68 0.0.0.0:* -
udp 0 0 0.0.0.0:34886 0.0.0.0:* -
udp 0 0 0.0.0.0:111 0.0.0.0:* -
udp 0 0 0.0.0.0:631 0.0.0.0:* -
udp 0 0 :::50442 :::* -
udp 0 0 :::958 :::* -
udp 0 0 :::111 :::* -
[weiyuan@weiyuan 下载]$
接下来重点讲解下rpm包安装的服务如何启动和重启电脑之后自启动
rpm安装的软件服务可以使用下面的命令来进行启动
[weiyuan@weiyuan 下载]$ cd /etc/rc.d/init.d/
[weiyuan@weiyuan init.d]$ ls
abrt-ccpp dnsmasq lvm2-monitor postfix single
abrtd firstboot mdmonitor psacct smartd
abrt-oops functions messagebus quota_nld snmpd
acpid haldaemon netconsole rdisc snmptrapd
atd halt netfs restorecond spice-vdagentd
auditd htcacheclean network rngd sshd
autofs httpd NetworkManager rpcbind sssd
blk-availability ip6tables nfs rpcgssd sysstat
bluetooth iptables nfslock rpcidmapd udev-post
certmonger irqbalance ntpd rpcsvcgssd wdaemon
cpuspeed kdump ntpdate rsyslog winbind
crond killall oddjobd sandbox wpa_supplicant
cups lvm2-lvmetad portreserve saslauthd ypbind
[weiyuan@weiyuan init.d]$
[weiyuan@weiyuan init.d]$ cd /etc/init.d/
[weiyuan@weiyuan init.d]$ ls
abrt-ccpp dnsmasq lvm2-monitor postfix single
abrtd firstboot mdmonitor psacct smartd
abrt-oops functions messagebus quota_nld snmpd
acpid haldaemon netconsole rdisc snmptrapd
atd halt netfs restorecond spice-vdagentd
auditd htcacheclean network rngd sshd
autofs httpd NetworkManager rpcbind sssd
blk-availability ip6tables nfs rpcgssd sysstat
bluetooth iptables nfslock rpcidmapd udev-post
certmonger irqbalance ntpd rpcsvcgssd wdaemon
cpuspeed kdump ntpdate rsyslog winbind
crond killall oddjobd sandbox wpa_supplicant
cups lvm2-lvmetad portreserve saslauthd ypbind
[weiyuan@weiyuan init.d]$
我们可以看到
/etc/rc.d/init.d/ 和/etc/init.d/ 内容都是一样,使用了软连接的方式我们启动httpd apache服务
使用命令
[root@weiyuan init.d]# /etc/rc.d/init.d/httpd start
正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using 183.221.250.11 for ServerName
[确定]
[root@weiyuan init.d]# /etc/init.d/httpd start
正在启动 httpd:
两种方式启动httpd是一样的
第三种方式也可以使用,但是主要service不是linxu的常用命令,只有redhat相关的操作系统采可以使用service启动服务,需要注意,所以最好情况下使用上面的绝对路径来启动服务,使用serive命令启动服务的时候
实际上执行的也是 /etc/rc.d/init.d/路径下的文件,源码包的默认情况下都是安装在/usr/local/下的,所以service是无法启动源码包安装的,如果要让service启动源码包的,例如httpd源码包安装在
/usr/local/apache2/bin/apactrl1 start启动,如果将/usr/local/apache2/bin/apactrl1复制到/etc/rc.d/init.d/路径下,也可以使用service管理源码包
[root@weiyuan init.d]# service httpd start
正在启动 httpd: 查看服务运行的状态
[root@weiyuan init.d]# service httpd status
httpd (pid 2361) 正在运行...
[root@weiyuan init.d]#
接下来我们讲解rpm包如何实现重启电脑之后服务能够自动启动
有下面的三种方式
[root@weiyuan weiyuan]# chkconfig --level 2345 httpd on
[root@weiyuan weiyuan]# chkconfig --list | grep httpd
httpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@weiyuan weiyuan]#
chkconfig --level 2345 httpd on这个命令重启电脑之后就能够保证httpd能够自启动
chkconfig 默认只对rpm安装的服务有效果,对二进制安装包没有效果
第二种方式:电脑重启之后每次都会读取/etc/rc.d/rc.local里面的任何命令,所以我们可以把启动httpd的命令放在该文件下面
[root@weiyuan rc.d]# vim rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff. touch /var/lock/subsys/local
/etc/init.d/httpd start
注意第一种方法和第二种方法只能二选一,否则httpd要被自启动两次,最好选择第二种方法,第二种方法对源代码安装的服务自启动是有效的 第三种:
[root@weiyuan rc.d]# vim ntsysv 会弹出图形化窗口开启rpm对应的服务,这种方式只有redhat的rpm有效,其他操作系统无效一定要注意
上面讲解了rpm包的服务管理,下面我们重点分析下源码包的服务管理的方法
上面这几个命令默认情况是不能管理源代码的安装服务的,默认管理的是rpm包的,因为rpm包默认安装在/etc/init.d目录下,而源码包不是安装在/etc/init.d目录下
[root@weiyuan rc.d]# /usr/local/apache2/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 183.221.250.11. Set the 'ServerName' directive globally to suppress this message 上面这个命令就是源码包启动服务的命令
如何让源码包服务自启动了
接下来我们如何让service命令能够启动源码包的服务了,因为我们知道service 启动服务的时候,是去查找/etc/init.d下面的文件进行启动,我们可以把/usr/local/apache2/bin/
apachectl 复制到/etc/init.d目录下,也可以使用下面的软连接
[root@weiyuan rc.d]# ln -s /usr/local/apache2/bin/apachectl /etc/init.d/apache
[root@weiyuan rc.d]# service apache start
Linux软件服务管理的更多相关文章
- linux的服务管理(centos6和Centos7)和网络管理(网卡配置),计划服务cron
服务和网络 管理 init ifcfg ens33 1.服务: Linux系统中提供的功能,统称为服务,如:at服务.cron服务.web服务.FTP服务.sshd服务等. 服务是由已经在运行的进程 ...
- Linux软件安装管理之——dpkg与apt-*详解 apt命令(dpkg和apt代替rpm)
apt list *python* Nosee123关注赞赏支持 Linux软件安装管理之--dpkg与apt-*详解 [Linux软件安装管理系列]- - 传送门: - -<Linux软件 ...
- Linux软件安装管理之——dpkg与apt-*详解
Linux软件安装管理之--dpkg与apt-*详解 [Linux软件安装管理系列]- - 传送门: - -<Linux软件安装管理之--源码安装详解> - -<Linux软件安装管 ...
- Linux软件安装管理
1.软件包管理简介 1.软件包分类 源码包 脚本安装包 二进制包(RPM包.系统默认包) 2.源码包 源码包的优点是: 开源,如果有足够的能力,可以修改源代码 可以自由选择所需要的功能 软件设计编译安 ...
- Linux软件安装管理 - CentOS (三)
1. 软件包管理简介 2. rpm命令管理(Redhat Package Manager) 3. yum在线安装 4. 源码包管理 4.1 源码包和RPM包的区别 4.1.1 区别 安装前:概念上的区 ...
- Linux系列教程(二十三)——Linux的服务管理
前面我们讲解Linux软件包管理之源码包.脚本安装包时,我们介绍了rpm包和源码包由于安装位置的不同,会对服务的启动造成影响,具体是什么,本篇博客我们来详细介绍. 1.Linux服务管理总览 我们可以 ...
- Linux之服务管理
一.计划任务 1) Crontab简介 1.Crontab是一个用于设置周期性被执行任务的工具: 2.被周期性执行的任务我们称为Cron Job: 3.周期性执行的任务列表我们称为Cron Table ...
- Linux软件安装管理 - CentOS (二)
1. 软件包管理简介 2. rpm命令管理(Redhat Package Manager) 3. yum在线安装 3.1 yum源文件 vi /etc/yum.repos.d/CentOS-Base. ...
- Linux学习 -- 服务管理
1 服务分类 服务管理内容 启动 自启动 查询已安装的服务 RPM包安装的服务 自启动的 chkconfig --list 2345中如果是启用,代表下次开机会自启动 正在运行的服务 p ...
随机推荐
- SpringBoot 2.x 版本以put方式提交表单不生效的问题详解
在使用SpringBoot 2.x版本时,原有springboot 1.x 版本的通过在表单中添加 input框隐藏域指定_method = put 的方式失效. 虽然浏览器传参的确是带上了这个参数, ...
- Rocket - debug - Example: Triggers
https://mp.weixin.qq.com/s/zPNyrBOhsytkRrZTDTEvpw 介绍riscv-debug的使用实例:配置Triggers功能. 1. Trigger Trigge ...
- “造轮运动”之 ORM框架系列(二)~ 说说我心目中的ORM框架
ORM概念解析 首先梳理一下ORM的概念,ORM的全拼是Object Relation Mapping (对象关系映射),其中Object就是面向对象语言中的对象,本文使用的是c#语言,所以就是.ne ...
- Java中lang包的常用方法介绍
JAVA API(图片来源:实验楼) 包装类 Integer包装类 方法 返回值 功能描述 byteValue() byte 以 byte 类型返回该 Integer 的值 intValue() in ...
- MyBatis整合双数据源
有时候在项目中会遇到需要连接两个数据库的情况.本文就结合Spring和Mybatis来讲下怎么使用双数据源(或者是多数据源). 背景知识介绍 本文中实现多数据源的关键是Spring提供的Abstrac ...
- Spring IoC 容器的扩展
前言 本篇文章主要介绍 Spring 中 BeanFactory 的扩展 ApplicationContext,我们平时日常开发中也基本上是使用它,不会去直接使用 BeanFactory. 那么在 S ...
- JVM中堆的介绍
一.堆的概述 一个JVM实例只有一个堆内存,堆也是Java内存管理的核心区域,堆在JVM启动的时候创建,其空间大小也被创建,是JVM中最大的一块内存空间,所有线程共享Java堆,物理上不连续的逻辑上连 ...
- css3中的skew(skewX,skewY)用法
这是html代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...
- [windows][技巧]百度网盘提示您的电脑已安装百度网盘,是否覆盖,解决方法
目录 故障描述 解决方法 故障描述 解决方法 win+r,输入regedit,进入注册表 依次打开HKEY_CURRENT_USER->Software->Baidu->BaiDuY ...
- Java 技术网站总结(不停更新)
Spring Spring 中文手册 Spring 教程 Spring For All Spring 学习笔记 Spring Boot Break易站 Spring Cloud 中文文档 Spring ...