导读 | 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 //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=//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!
原文来自:
本文地址://lrxjmw.cn/centos-yum.html编辑:roc_guo,审核员:逄增宝
Linux大全:
Linux系统大全: