前期准备
-
虚拟机 VMware 和 CentOS 的安装和学习环境搭建,安装用的网络是桥接模式,该模式好处在于:局域网中可互访,也可访问外网。
下载址址:https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/isos/x86_64/
-
设置ip,dns
-
远程连接软件SecureCRT,免安装,解压即可用,可以预先添加所需要连接的主机,打包上传到网盘或其它自已能下载的地方,再次使用时,下载解压直接可用,省不少时间呢。
-
临时和永久关闭 Selinux
//安全增强型 Linux(Security-Enhanced Linux)简称 SELinux,它是一个 Linux 内核模块,也是 Linux 的一个安全子系统。
//现在初学先关掉,不然很多服务都需要配置才能跑起来。
//SELinux 有三个状态:
//enforcing:强制模式,代表 SELinux 运作中,且已经正确的开始限制;
//permissive:宽容模式:代表 SELinux 运作中,不过仅会有警告讯息并不会实际限制
//disabled:关闭,SELinux 并没有实际运作。
# getenforce //查看状态
//临时关闭
# setenforce 0
//永久关闭
# vi /etc/selinux/config //把 7 行 SELINUX=enforcing 改:SELINUX=disabled
//这个服务是linux 内核的一部分,要生效必须重启# reboot
配置本地 YUM 源
- Yum(全称为 Yellowdog Updater Modified)是一个在 RedHat 以及 CentOS 中的 Shell 前端软件包管理器。直白一点它是帮我们安装、卸载软件的工具,暂时先简单地这样理解。
- yum 的命令形式一般是如下: yum –选项 命令包
其中选项是可选的,选项包括
-h(帮助),
-y(当安装过程提示选择全部为"yes"),
-q(不显示安装的过程)等等
yum 的一切信息都存储在一个叫 yum.reops.d 目录下的配置文件中,通常位于 /etc/yum.repos.d 目录下。在这个目录下面有很多文件,都是.repo 结尾的,repo 文件是 yum 源(也就是软件仓库)的配置文件,通常一个 repo 文件定义了一个或者多个软件仓库的细节内容,例如我们将从哪里下载需要安装或者升级的软件包,repo 文件中的设置内容将被 yum 读取和应用!默认情况下,yum 的软件仓库是在网络上的,所以每次安装的时候,前提需要联网,在网络上的软件仓库中下载软件,然后安装,所以呢,在没有网络的时候 yum 就用不了,为了解决这个问题,我们可以包软件仓库的设置修改为本地的光盘镜像上,我们下载的 CentOS-7-x86_64-Everything-1810.iso 文件中就包含了完整的一套软件,所以我们可以用它来做软件仓库!
1—设置系统光盘开机自动挂载
vi /etc/fstab #在文档最后,添加内容:
/dev/cdrom /mnt iso9660 defaults 0 0
:wq #esc键 :wq 保存退出
mount -a #命令用于加载文件系统到指定的加载点,-a:加载文件“/etc/fstab”中描述的所有文件系统。
#显示:mount: /dev/sr0 写保护,将以只读方式挂载
ls /mnt/ #可以查看到此目录下有内容,说明挂载成功
2—进入/etc/yum.repo.d 目录下,创建xxx.repo配置文件
删除原有的文件
rm -rf /etc/yum.repos.d/*.repo
为什么要删除里面所有的文件呢,因为里面配置文件的软件源在国外,有的软件下载超慢,所以我们要重新配置本地源或国内镜镜像源
例:cat /etc/yumpos.d/CentOS-Base.repo
创建一个新的 yum 源配置文件,yum 源配置文件的结尾必须是.repo
cd /etc/yum.repos.d/
# vi CentOS7.repo #写入以下红色内容
[CentOS7]
name=CentOS-server
baseurl=file:///mnt
enabled=1
gpgcheck=0
#若是我们设置了gpgcheck=1,则要在下面加上一行,数字证书验证,这个数字证不用修改,系统安装后生成了
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
参数说明:
[CentOS7] —>yum的ID,必须唯一
name=CentOS-server ----->描述信息
baseurl=file:///mnt -------> /mnt表示的是光盘的挂载点 . file:后面有3个///这是规定
enabled=1 ------>启用
gpgcheck=0 ---->取消验证,自己的yum源一般不用校验它
验证yum源生效没:yum install httpd
yum配置阿里腾讯等镜像源
rpm 包在线安装( yum 安装)
------yum 源配置文件保存在/etc/yum.repos.d/目录中,文件的扩展名一定是“.repo”。也就是说,yum 源配置文件只要扩展名是“.repo”就会生效。
# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
--------这个目录中有 7 个 yum 源配置文件,默认情况下 CentOS-Base.repo 文件生效,这个文件中又有多个具体的yum源。
------在 CentOS-Base.repo 文件中有 4 个 yum 源,这里只列出了 base,其他和 base类似。我们解释一下 base 这个源。
[base]:源的名称,一定要放在[]中,在一个配置文件中,这个名字不能重复。
name:源说明,可以自己随便写。
mirrorlist: yum 源服务器的镜像站点地址。
baseurl: yum 源服务器的地址。
-----mirrorlist和baseurl两个配置,只能使用一个,用那个都可以,默认的地址都在国外,这里可以使用国内的镜像163,aliyun都行
enabled:此容器是否生效,如果不写或写成 enabled=1 则表示此容器生效,写成 enabled=0则表示此容器不生效。
gpgcheck:如果为 1 则表示 RPM 的数字证书生效;如果为 0 则表示 RPM 的数字证书不生效。
gpgkey:数字证书的公钥文件保存位置。不用修改。gpgcheck为1才有用,gpgcheck为0就可以不需要。
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
腾讯云镜像站
备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.cloud.tencent.com/repo/centos7_base.repo
yum clean all
yum makecache
阿里云镜像站
1)、备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2)、下载新的CentOS-Base.repo 到/etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
3)、之后运行生成缓存
yum makecache
清华大学镜像站
首先备份CentOS-Base.repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
之后启用 TUNA 软件仓库, 将以下内容写入vi /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
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
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
更新软件包缓存 yum makecache
EPEL镜像源
yum -y install epel-release
# set [priority=5]
sed -i -e “s/]$/]\npriority=5/g” /etc/yum.repos.d/epel.repo
for another way, change to [enabled=0] and use it only when needed
[root@localhost ~]#
sed -i -e “s/enabled=1/enabled=0/g” /etc/yum.repos.d/epel.repo
# if [enabled=0], input a command to use the repository
[root@localhost ~]# yum --enablerepo=epel install [Package]