The previous series of articles, we vi editor and 46 basic commands are introduced, this article will demonstrate the use of RPM and YUM to install and manage the software in centos7.
A, RPM Package Manager
1.1 RPM Background
RPM (RedHat Package Manager), similar to the control panel under the windows, and install the RPM package similar to the setup.exe file. RPM will establish a unified database file records detailed information and can automatically analyze software dependencies, it was originally a Red Hat Linux distributions designed to manage the Linux program suite, because it is easy to follow and powerful GPL rules gradually by other issuers version uses, been limited to the use of the Red Hat system , such as CentOS, fedora, suse.
Different distributions of linux package format is not the same, such as ubuntu, debian package using the suffix deb format; and redhat, centos, fedora, suse rpm format such as the use of the package.
The two are not universal. SecureCRT Remote Tools such as previously mentioned, the official would provide packages for different linux distributions. Application package ubuntu18 is: scrt-8.5.4-1942.ubuntu18-64.x86_64.deb, applicable redhat (centos) packet is: scrt-8.5.4-1942.rhel7-64.x86_64.rpm.
Check the official website: https://www.vandyke.com/cgi-bin/releases.php?product=securecrt&dl=1
RPM before publication, in order to install the software on a Linux system can only take the form of source package installed. Early in the linux installer is a very difficult thing, operation and maintenance personnel need to compile the code and solve many dependencies, but also consider other programs to upgrade and uninstall the service program, dependencies between libraries, very difficult.
Therefore, in order to solve these problems, RPM mechanism makes the birth of Linux is easy to install and upgrade.
1.2 rpm packet format
SecureCRT or more sides of the package as an example.
scrt-8.5.4-1942.rhel7-64.x86_64.rpm
scrt: Software Name
8.5.4-1942: software version number, turn-based version and a minor version number
rhel7: operating system, Red Hat Enterprise 7 is here. Some packages are not part of this
x86_64: software that runs the hardware platform
rpm: Package extension
1.3 Common Commands
1.3.1 Query has been installed package
Syntax: rmp -q package names
Case:
[root@heimatengyun ~]# rpm -q firefox
firefox-24.5.0-1.el7.centos.x86_64
Since our first article installed by default gui installed firefox, so check out here is already installed.
Installing the software 1.3.2
Syntax: RPM -ivh full package name
Options:
-i: install installation
-v: verbose Show Details
-h: hash progress bar
--nodeps: do not rely on detection
Description:
System image contains many rpm package, the disc can be mounted directly be installed when required. If the disc is not included, you can go online to download the appropriate rpm package and change to the directory where the rpm package, the installation command.
1.3.3 uninstall software
Syntax: RPM package -e
ps: is generally not recommended to uninstall the software by this method, easily lead to many problems.
Two, YUM warehouse
Introduction 2.1 YUM
Although RPM dependencies query software can help, but still need to install their own operation and maintenance personnel to solve dependency problems, large-scale software relies very much, it is very troublesome to install. To further reduce software installation difficulty and complexity of the design YUM repositories.
YUM (Yellow dog Updater, Modified) is a front end shell package manager RedHat, Centos and in Fedora. YUM warehouse management can be considered for RPM packages, warehouses package may be the official release of Red Hat, can also write your own. YUM repositories can be divided into many desired package and associated dependencies based on user demand, and automatically download and install software packages from the server to the system.
Therefore daily work, software is usually installed using yum manner.
2.2 YUM related commands
command | Functional Description |
---|---|
yum install package name | Installation services, you can add the -y option to avoid Always ask |
yum list | Lists all available package and package group |
yum clean all | Clear all cached data |
yum makecache | Cache generation |
yum deplist package name | A list of all package dependencies |
yum remove package name | Delete Service |
yum repolist | Yum list available source |
Case:
- Yum install apache service by way of
[root@heimatengyun ~]# yum install httpd -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.aliyun.com
* updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
...省略中间部分内容
Installed:
httpd.x86_64 0:2.4.6-90.el7.centos
Dependency Installed:
apr.x86_64 0:1.4.8-5.el7
apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-90.el7.centos
mailcap.noarch 0:2.1.41-2.el7
Complete!
[root@heimatengyun ~]# systemctl start httpd
Tip a successful installation, the default is not started, manually start the httpd service, this time directly through the virtual machine to log into the system, access to 127.0.0.1 through a browser, we found to have been successfully installed appache service.
However, on a physical host can not access the virtual machine ip,. Big reason may be because a firewall, you can turn off the firewall directly early learning, learning to avoid interference.
If you encounter a situation can not be accessed, please turn to the investigation in the following order:
Check whether the process started to see the process start port, view the status of the firewall, if the firewall is turned off. The operation is complete in theory, it can be accessed in the host.
[root@heimatengyun ~]# ps -ef |grep httpd
root 44948 1 0 15:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 44949 44948 0 15:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 44950 44948 0 15:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 44951 44948 0 15:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 44952 44948 0 15:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 44953 44948 0 15:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 44963 42126 0 15:07 pts/0 00:00:00 grep --color=auto httpd
[root@heimatengyun ~]# netstat -lntup |grep httpd
tcp6 0 0 :::80 :::* LISTEN 44948/httpd
[root@heimatengyun ~]# firewall-cmd --state
running
[root@heimatengyun ~]# systemctl stop firewalld.service
[root@heimatengyun ~]# firewall-cmd --state
not running
Now enter the virtual machine ip address in the physical machine browser and found that the service can access apache.
The following command can also check whether the service is running httpd
[root@heimatengyun ~]# systemctl status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
Active: active (running) since Wed 2019-11-27 15:06:56 CST; 30min ago
...省略部分内容
Note: Using yum source installation, httpd version is generally not up to date, the latest version of Apache can only go to the official website to download source packages installed
- Uninstall apache service
[root@heimatengyun ~]# yum remove httpd
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-90.el7.centos will be erased
--> Finished Dependency Resolution
...省略部分内容
Is this ok [y/N]: y
...省略部分内容
Removed:
httpd.x86_64 0:2.4.6-90.el7.centos
Complete!
At this time, go see the state has been able to find a service
[root@heimatengyun ~]# systemctl status httpd.service
httpd.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
...省略部分内容
2.3 Network YUM
2.3.1 Why the need to replace YUM
CentOS yum default source is not necessarily mirror the country, leading yum-line installation and update speed is not very satisfactory. This time needs to be set for the domestic source yum mirror sites, major domestic open source open source mirror sites Netease and Ali cloud and so on.
2.3.2 to replace the default YUM Ali cloud sources
Prerequisites: centos to be able to connect to external networks.
主要思路就是在阿里云镜像站点下载阿里云的YUM配置文件,然后覆盖系统默认的YUM配置文件即可。配置文件可以本地下载上传覆盖,也可以直接在centos上下载。在覆盖时记得先备份一个默认YUM,以防不测。
按以下命令一条条执行即可
[root@heimatengyun yum.repos.d]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@heimatengyun yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2019-11-27 16:13:24-- http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 118.112.15.1, 182.140.218.238, 182.140.218.243, ...
...省略部分内容
[root@heimatengyun yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Vault.repo
CentOS-Base.repo.backup CentOS-Sources.repo
[root@heimatengyun yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@heimatengyun yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, langpacks
...省略部分内容
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Metadata Cache Created
执行以上命令后替换成功,如果再次安装apache服务的话,可以看到yum已经替换为阿里云的源了。
[root@heimatengyun yum.repos.d]# yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
...省略部分内容
此处只是为了验证以下源是否替换成功,按Ctrl+C中断安装
2.4 本地YUM
2.4.1 为何需要制作本地YUM源
YUM源可以简化软件在Linux上的安装过程,但是因为有些特殊的情况下生产环境是无法上外网,不能连接外网的YUM源,因此就无法直接使用YUM命令安装软件。为了在内网中也可以使用YUM安装软件,就需要配置本地YUM源。
YUM源本质是一个保存了多个RPM包的web服务器,可以通过http的方式来检索、下载并安装相关的RPM包。
2.4.2 制作本地YUM源
(1)准备另外一台虚拟机
按系列文章1重新再装一台centos虚拟机或克隆虚拟机,用于yum源服务器。
ps:系统初次安装完后做一个快照,以后克隆虚拟机就用这个快照,避免重复安装费时间
克隆的虚拟机给原系统一模一样,因此无法同时启动,需要修改ip地址和主机名称。
修改ip地址:登录界面,按前面文章的方法修改ip地址为192.168.78.101
修改主机名称:终端执行hostnamectl set-hostname yum-local-server命令即可
(2)将iso镜像挂载到目录
依次执行下列命令,创建目录并挂载,挂载之后通过df命令查看是否挂载成功
[root@yum-local-server /]# mkdir /mnt/cdrom
[root@yum-local-server /]# mount /dev/cdrom /mnt/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
[root@yum-local-server /]# df -HT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 19G 4.8G 15G 26% /
devtmpfs devtmpfs 949M 0 949M 0% /dev
tmpfs tmpfs 958M 87k 958M 1% /dev/shm
tmpfs tmpfs 958M 9.4M 949M 1% /run
tmpfs tmpfs 958M 0 958M 0% /sys/fs/cgroup
/dev/sda1 xfs 521M 125M 397M 24% /boot
/dev/sr0 iso9660 4.2G 4.2G 0 100% /mnt/cdrom
(3)修改本机YUM源配置文件
备份原来YUM源配置文件,将源指向自己。
[root@yum-local-server /]# cd /etc/yum.repos.d/
[root@yum-local-server yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Sources.repo CentOS-Vault.repo
[root@yum-local-server yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@yum-local-server yum.repos.d]# ls
CentOS-Base.repo.bak CentOS-Sources.repo
CentOS-Debuginfo.repo CentOS-Vault.repo
[root@yum-local-server yum.repos.d]# vi CentOS-Base.repo
[base]
name=CentOS-Local
baseurl=file:///mnt/cdrom/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
保存并退出
ps:写法是固定格式,name是自定义仓库名称,baseurl是基础地址指向的是挂在的镜像目录,gpgcheck是一个秘钥功能(可以不启用,如果不启用就不指定gpgkey),enabled是启动的意思如果数值为1的话代表开启如果是0的话代表关闭
(4)清除缓存
[root@yum-local-server yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base
Cleaning up everything
Cleaning up list of fastest mirrors
(5)列出可用源
[root@yum-local-server yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00
(1/2): base/group_gz | 157 kB 00:00
(2/2): base/primary_db | 2.7 MB 00:00
Determining fastest mirrors
repo id repo name status
base CentOS-Local 3,538
repolist: 3,538
(6)安装apache服务
Step: Install apache, open httpd service (default is off), turn off the firewall
The method is consistent with the front, where the code is no longer attached.
(7) to the httpd source configuration YUM
Yum httpd source will be copied to the web directory, so other servers within the network can access the yum source of the network.
[root@yum-local-server yum.repos.d]# cp -r /mnt/cdrom/ /var/www/html/CentOS
(8) browser to access test
In the host through direct access http://192.168.78.101/CentOS/
Description yum can access the server configuration successfully
2.4.3 Using local sources YUM
Each centos server can be made into a local source, no need to connect to other yum, but if more than one server, you can make a separate source server yum, yum then modify each server configuration file, it will address all point to that is can. Below we newly prepared a virtual machine 192.168.78.102 (if the original 100 that machine does not perform yum remove httpd operation, can be directly used) to demonstrate the use of local yum.
Important note: The reason the Department is strongly recommended that new equipment is a virtual machine, if you follow the steps I followed the top, it may have been performed to uninstall the service httpd 2.2. As the unloading operation has been performed, again with that virtual machine to run the following command to change the local yum install httpd again, would have been installed unsuccessful, most likely related to the uninstall is dependent on residual lead to a conflict for installation. I encountered this problem very confused, and finally successfully installed on a new virtual machine.
- Configure the server to use a local source YUM
[root@heimatengyun yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@heimatengyun yum.repos.d]# vi CentOS-Base.repo
[base]
name=CentOS-101
baseurl=http://192.168.78.101/CentOS/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Save and exit, clear the cache, a list of available yum source
[root@heimatengyun yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base
Cleaning up everything
Cleaning up list of fastest mirrors
[root@heimatengyun yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id repo name status
base CentOS-101 3,538
repolist: 3,538
- Use local sources to install software yun
[root@heimatengyun yum.repos.d]# yum install httpd
Loaded plugins: fastestmirror, langpacks
...省略部分内容
Installed:
httpd.x86_64 0:2.4.6-17.el7.centos.1
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7
apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-17.el7.centos.1
mailcap.noarch 0:2.1.41-2.el7
Complete!
Successful installation.
This article finished lower centos7 install and uninstall the software, then configure yum source of knowledge began to explain in the next section pipe symbol, redirection, environment variables, etc., to prepare for the back shell programming.