共计 7921 个字符,预计需要花费 20 分钟才能阅读完成。
导读 | CentOS(Community Enterprise Operating System,中文意思是社区企业操作系统) 是 Linux 发行版之一,它是来自于 Red Hat Enterprise Linux 依照开放源代码规定释出的源代码所编译而成。 |
搭建本地 yum 源
本地 yum 源,就意味着只有搭建该 yum 源的这台服务器能使用,其它的服务器都不能使用该 yum 源。搭建本地 yum 源的所有步骤如下:
# 准备好一个 centos 的镜像,我这里是 CentOS-7-x86_64-DVD-1810.iso
# 在 /local-yum 目录创建挂载镜像的文件夹
# 将 iso 镜像挂载到 /mnt/iso 目录
mount -o loop CentOS-7-x86_64-DVD-1810.iso /local-yum
# 挂载成功后可以使用 df - h 命令查看
[root@localhost application]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 50G 1.9G 49G 4% /
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 63G 11M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/sda2 1014M 138M 877M 14% /boot
/dev/sda1 200M 12M 189M 6% /boot/efi
/dev/mapper/centos-home 392G 9.0G 383G 3% /home
tmpfs 13G 0 13G 0% /run/user/0
/dev/loop0 4.5G 4.5G 0 100% /local-yum
# 修改 yum 配置文件,把原先的配置先备份了
cd /etc/yum.repos.d
mkdir bak
mv *.repo ./bak
#新建 local.repo
vim /etc/yum.repos.d/local.repo
[base]
name=CentOS
baseurl=file:///local-yum
enabled=1
gpgcheck=0
#清除下 yum 原有的信息,载入新的缓存
yum clean all
yum makecache
这样,一个崭新的本地 yum 源就可以使用了。
搭建局域网 yum 源
除了可以搭建本地 yum 源外,我们还可以基于 HTTP 方式配置 yum 源,这样我们就可以配置一个局域网内都可以使用的 yum 源。
一般都是通过 apache 来搭建 HTTP 的 yum 源,本次我们使用 Nginx 搭建
# 官网下载 nginx1.18.0
wget http://nginx.org/download/nginx-1.18.0.tar.gz
#安装依赖包,NGINX 是 C 语言写的,pcre-devel 支持正则表达式,openssl 开启加密
[root@proxy ~]# yum -y install gcc pcre-devel openssl-devel
#创建 NGINX 用户,为了安全起见,不允许登录系统
[root@proxy ~]# useradd -s /sbin/nologin nginx
#解压,安装,这里把 nginx 部署在 /home/application/nginx 目录下
[root@proxy ~]# mkdir /home/application/nginx
[root@proxy ~]# tar -xf nginx-1.18.0.tar.gz
[root@proxy ~]# cd nginx-1.18.0
[root@proxy nginx-1.18.0]# ./configure --prefix=/home/application/nginx --user=nginx --group=nginx --with-http_ssl_module
#编译安装
[root@proxy nginx-1.10.3]# make && make install
#创建 yum 仓库文件路径 /home/application/nginx-yum
[root@proxy ~]#mkdir -p /home/application/nginx-yum
#编辑 nginx 配置文件, 定义端口为 8899
[root@proxy ~]# vim /home/application/nginx/conf/nginx.conf
worker_processes 1;
events {worker_connections 1024;}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8899;
server_name localhost;
location / {
autoindex on;
root /home/application/nginx-yum/;
}
}
}
#检查 nginx 配置文件是否正确
[root@proxy ~]# /home/application/nginx/sbin/nginx -t
nginx: the configuration file /home/application/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /home/application/nginx/conf/nginx.conf test is successful
#将 iso 镜像文件挂载到临时目录下,再拷贝到 yum 仓库路径下 /home/application/nginx-yum
[root@proxy ~]# mkdir local-yum
[root@proxy ~]# mount -o loop CentOS-7-x86_64-DVD-1810.iso /local-yum
[root@proxy ~]# cd local-yum
[root@proxy ~]# cp -rp * /home/application/nginx-yum/
[root@proxy ~]# ls -l /home/application/nginx-yum/
total 4669768
-rw-r--r--. 1 root root 4781506560 Aug 17 18:36 CentOS-7-x86_64-DVD-2003.iso
-rw-rw-r--. 1 root root 14 Apr 21 2020 CentOS_BuildTag
drwxr-xr-x. 3 root root 35 Apr 21 2020 EFI
-rw-rw-r--. 1 root root 227 Aug 30 2017 EULA
-rw-rw-r--. 1 root root 18009 Dec 10 2015 GPL
drwxr-xr-x. 3 root root 57 Apr 21 2020 images
drwxr-xr-x. 2 root root 198 Apr 21 2020 isolinux
drwxr-xr-x. 2 root root 43 Apr 21 2020 LiveOS
drwxr-xr-x. 2 root root 225280 Apr 22 2020 Packages
drwxrwxr-x. 2 root root 4096 Apr 22 2020 repodata
-rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 Apr 22 2020 TRANS.TBL
#确认配置没有问题后,启动 nginx
[root@proxy ~]# /home/application/nginx/sbin/nginx
#查看端口
[root@localhost conf]# netstat -ntlup
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:22 0.0.0.0:* LISTEN 16129/sshd
tcp 0 0 0.0.0.0:8899 0.0.0.0:* LISTEN 41103/nginx: master
tcp6 0 0 :::22 :::* LISTEN 16129/sshd
登陆浏览器访问查看 yum 仓库
最后,我们开始配置 yum 的配置文件
在 /etc/yum.repos.d 新建一个名为 nginx-yum.repo 的配置文件,内容如下:
vim /etc/yum.repos.d/nginx-yum.repo
[Nginx-yum]
name=nginx-yum
baseurl=http://10.114.0.15:8899
enabled=1
gpgcheck=0
清除下 yum 原有的信息,载入新的缓存
yum clean all
yum makecache
这样,局域网 yum 源就可以使用了
安装一个软件试下效果
[root@localhost ~]# yum install bash*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package bash-4.2.46-34.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package bash-completion.noarch 1:2.1-6.el7 will be updated
---> Package bash-completion.noarch 1:2.1-8.el7 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
===================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================================================================================================================================================
Updating:
bash-completion noarch 1:2.1-8.el7 Nginx-yum 87 k
Transaction Summary
===================================================================================================================================================================================================================================================================
Upgrade 1 Package
Total download size: 87 k
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for Nginx-yum
bash-completion-2.1-8.el7.noarch.rpm | 87 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : 1:bash-completion-2.1-8.el7.noarch 1/2
Cleanup : 1:bash-completion-2.1-6.el7.noarch 2/2
Verifying : 1:bash-completion-2.1-8.el7.noarch 1/2
Verifying : 1:bash-completion-2.1-6.el7.noarch 2/2
Updated:
bash-completion.noarch 1:2.1-8.el7
Complete!
正文完
星哥说事-微信公众号
![post-qrcode](https://www.xgss.net/wp-content/uploads/2023/07/二维码-微信公众号256x256.jpg)