0分享至
用扫码二维码
分享至好友和朋友圈
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 SizeUsed Avail Use% Mounted on /dev/mapper/centos-root 50G1.9G 49G 4% / devtmpfs63G 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 1014M138M877M14% /boot /dev/sda1200M 12M189M 6% /boot/efi /dev/mapper/centos-home392G9.0G383G 3% /home tmpfs 13G 0 13G 0% /run/user/0 /dev/loop0 4.5G4.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是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 ~]# cdnginx-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_processes1; events { worker_connections1024; } http { include mime.types; default_typeapplication/octet-stream; sendfileon; keepalive_timeout65; server { listen 8899; server_namelocalhost; location / { autoindexon; 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-rw-r--r--. 1 root rootAug 17 18:36 CentOS-7-x86_64-DVD-2003.iso -rw-rw-r--. 1 root root 14 Apr 212020 CentOS_BuildTag drr-xr-x. 3 root root 35 Apr 212020 EFI -rw-rw-r--. 1 root root227 Aug 302017 EULA -rw-rw-r--. 1 root root18009 Dec 102015 GPL drr-xr-x. 3 root root 57 Apr 212020 images drr-xr-x. 2 root root198 Apr 212020 isolinux drr-xr-x. 2 root root 43 Apr 212020 LiveOS drr-xr-x. 2 root rootApr 222020 Packages drrr-x. 2 root root 4096 Apr 222020 repodata -rw-rw-r--. 1 root root 1690 Dec 102015 RPM-GPG-KEY-CentOS-7 -rw-rw-r--. 1 root root 1690 Dec 102015 RPM-GPG-KEY-CentOS-Testing-7 -r--r--r--. 1 root root 2883 Apr 222020 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 tcp00 0.0.0.0:220.0.0.0:* LISTEN16129/sshd tcp00 0.0.0.0:88990.0.0.0:* LISTEN41103/nginx: master tcp6 00 :::22 :::*LISTEN16129/sshd
登陆浏览器访问查看yum仓库
最后,我们开始配置yum的配置文件
在/etc/yum.repos.d新建一个名为nginx-yum.repo 的配置文件,内容如下:
vim /etc/yum.repos.d/nginx-yum.repo [Nginx-yum] name=nginx-yum baseurl=: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 ===================================================================================================================================================================================================================================================================PackageArchVersion RepositorySize =================================================================================================================================================================================================================================================================== Updating:bash-completionnoarch1:2.1-8.el7 Nginx-yum 87 k Transaction Summary =================================================================================================================================================================================================================================================================== Upgrade1 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 kB00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : 1:bash-completion-2.1-8.el7.noarch1/2 Cleanup: 1:bash-completion-2.1-6.el7.noarch2/2 Verifying: 1:bash-completion-2.1-8.el7.noarch1/2 Verifying: 1:bash-completion-2.1-6.el7.noarch2/2 Updated: bash-completion.noarch 1:2.1-8.el7 Complete!
原文来自:本文地址:编辑:roc_guo,审核员:逄增宝Linux命令大全:特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.
/阅读下一篇/ 返回网易首页 下载网易新闻客户端