linux菜鸟入门之服务管理与软件包的安装

Systemctl是一个systemd工具,主要负责控制systemd系统和服务管理器。

Systemd是一个系统管理守护进程、工具和库的集合,用于取代System V初始进程。Systemd的功能是用于集中管理和配置类UNIX系统。

在Centos7以前,1号进程还是init,在Centos7的时候1号进程变成了systemd




 systemctl start服务名称###开启服务
 stop 。。。。###关闭服务
restart。。。。###重启服务
reload。。。。###重新加在服务配置
status。。。。###查看服务状态
enable。。。。###设定服务开机启动
disable。。。。###禁止服务开机启动
list-dependencies###查看服务依赖关系
list-units###查看当前运行的所有服务
list-unit-files###查看服务的开机启动情况
set-default multi-user.target###开机不启动图形
set-default graphical.target###开机启动图形


loaded   #系统服务已经初始化完成,加载配置
active(running) #服务正在被系统利用
active(exited) #服务已经加载配置,等待被系统调用
active(waiting) #服务等待被系统处理
inactive #服务关闭
enbaled #服务开机启动
disenbaled #服务开机不启动
static #服务开机启动项不可被管理
failed #系统配置错误


以http为例。




软件包分为二进制包和RPM包:

软件包管理的核心功能:

1.制作软件包

2.安装,卸载,升级,查询,校验


Redhat,Suse,Debian,Ubuntu等操作系统

Redhat,Suse    用rpm

Debian,Ubuntu 用det

但用rpm命令安装软件时会有令人深恶痛绝的依赖性问题,树形依赖和环形依赖还好说,只有有耐心,就可以装成功,但库文件依赖就令人无语了,早期没有网站去查库文件依赖性,库文件依赖只能靠猜。猜对了就可以安装,猜错了就继续猜。所以为了规避依赖性问题,就有了yum安装

依赖关系:1.树形依赖

2.环形依赖

3.库文件依赖


yum(yellowdog update modifier):可以自行解决依赖问题。Centos默认是已经安装了yum源的。但yum源分为网络yum源和本地yum源。

1.配置本地yum源的方法。

# mount /dev/cdrom /mnt/cdrom/

# cd /etc/yum.repos.d

在这个文件中会看到repo文件

[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo

CentOS-Base.repo 是yum 网络源的配置文件

CentOS-Media.repo 是yum 本地源的配置文件

可以看到CentOS-Base.repo文件中(网络yum源)


#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

  这里分为3部分,其中每部分都差不多一样。

mirrorlist这里设置了在哪个网站去找资源库,这里就默认了Centos官方的,如果不想访问外网也可以改成中国的,清华大学好像搭建了一个yum源

设置gpgcheck=1会让yum检查每个下载的RPM的GnuPG签名。这么做是因为你需要适当的GnuPG key注册到您的RPM数据库。可以防止被欺骗,如:非法入侵发行版网站,木马导入软件包,使不知情用户下载。

enable是启用


想要配置本地yum源。因为系统是识别.repo后缀名的。可以将CentOS-Base.repo 改名成 CentOS-Base.repo.bak。然后将CentOS-Media.repo中的enabled改成1。

将baseurl改成,镜像挂载的地方。如刚才讲镜像挂载在/mnt/cdrom下。然后将另外两个注释掉

1 # CentOS-Media.repo
  2 #
  3 #  This repo can be used with mounted DVD media, verify the mount point for
  4 #  CentOS-7.  You can use this repo and yum to install items directly off the
  5 #  DVD ISO that we release.
  6 #
  7 # To use this repo, put in your DVD and use it with the other repos too:
  8 #  yum --enablerepo=c7-media [command]
  9 #  
 10 # or for ONLY the media repo, do this:
 11 #
 12 #  yum --disablerepo=\* --enablerepo=c7-media [command]
 13 
 14 [c7-media]
 15 name=CentOS-$releasever - Media
 16 baseurl=file:///mnt/cdrom
 17 #        file:///media/cdrom/
 18 #        file:///media/cdrecorder/
 19 gpgcheck=1
 20 enabled=1
 21 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

这样就会加载本地yum源了


如果只有本地.iso镜像文件的话,也可以当做yum源使用,还是要挂载起来。这里我还是将镜像文件挂载在/mnt/cdrom下。   用mount -o loop 本地镜像文件所在位置 /mnt/cdrom


yum命令还可以加上其他参数,如升级之类的。下面简单的介绍一下,yum的参数其实很多,但不一定都常用。


yum -y update httpd        #升级软件(最好别用)

如果后面不跟 httpd等服务的话   那么是默认是升级linux中所有软件包,包括linux的内核。这是很危险的。这个升级非常浪费时间。如果服务器放在远程,那么对内核的操作就不能及时进行。这会导致系统直接崩溃。(CentOS6.3以前)。升级所有的服务完全没有必要的.


yum -y remove 包名       #卸载软件 (尽量少用)

服务器最好最小安装,用什么装什么,尽量别卸载。安装有依赖性。卸载也需要依赖性。卸掉了很重要的包的话,会导致系统崩溃


yum search httpd    #搜索服务器上和关键字相关的包

[root@localhost ~]# yum search httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.btte.net
================================================================= N/S matched: httpd =================================================================
libmicrohttpd-devel.i686 : Development files for libmicrohttpd
libmicrohttpd-devel.x86_64 : Development files for libmicrohttpd
libmicrohttpd-doc.noarch : Documentation for libmicrohttpd
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server

  名称和简介匹配 only,使用“search all”试试。

yum grouplist # 列出所有可用的软件组列表

[root@localhost ~]# yum grouplist
已加载插件:fastestmirror, langpacks
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.tuna.tsinghua.edu.cn
可用的环境分组:
   最小安装
   基础设施服务器
   计算节点
   文件及打印服务器
   基本网页服务器
   虚拟化主机
   带 GUI 的服务器
   GNOME 桌面
   KDE Plasma Workspaces
   开发及生成工作站
可用组:
   传统 UNIX 兼容性
   兼容性程序库
   图形管理工具
   安全性工具
   开发工具
   控制台互联网工具
   智能卡支持
   科学记数法支持
   系统管理
   系统管理工具
完成


yum groupinstall     软件组名      #安装指定的软件组。组名是由grouplist查询而来(安装必须是英文)

yum groupremove   软件组名      #卸载指定的软件组


yum info 软件包    ##显示安装包信息软件包


[root@localhost ~]# yum info httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.btte.net
已安装的软件包
名称    :httpd
架构    :x86_64
版本    :2.4.6
发布    :40.el7.centos
大小    :9.4 M
源    :installed
来自源:c7-media
简介    : Apache HTTP Server
网址    :http://httpd.apache.org/
协议    : ASL 2.0
描述    : The Apache HTTP Server is a powerful, efficient, and extensible
         : web server.

可安装的软件包
名称    :httpd
架构    :x86_64
版本    :2.4.6
发布    :40.el7.centos.4
大小    :2.7 M
源    :updates/7/x86_64
简介    : Apache HTTP Server
网址    :http://httpd.apache.org/
协议    : ASL 2.0
描述    : The Apache HTTP Server is a powerful, efficient, and extensible
         : web server.


还有个问题,yum命令虽然可以方便的下载,升级,卸载软件包,但他不能更好的查询。

想要查询还需要使用rpm命令。

rpm -q   RPM_PACKET             ##查询一个包是否被安装

[root@localhost yum.repos.d]# rpm -q httpd
httpd-2.4.6-40.el7.centos.x86_64

rpm -qi  RPM_PACKET  ##得到被安装包的信息

[root@localhost yum.repos.d]# rpm -qi httpd
Name        : httpd
Version     : 2.4.6
Release     : 40.el7.centos
Architecture: x86_64
Install Date: Wed 28 Sep 2016 12:17:29 AM CST
Group       : System Environment/Daemons
Size        : 9806197
License     : ASL 2.0
Source RPM  : httpd-2.4.6-40.el7.centos.src.rpm
Build Date  : Fri 20 Nov 2015 05:45:11 AM CST
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

rpm -ql  RPM_PACKET  ##列出该包中有什么文件


rpm -qf  FILE   ##列出服务器上的一个文件属于哪一个RPM包









  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值