龙空技术网

CentOS 7搭建本地yum源和局域网yum源

运维小弟 1579

前言:

此时看官们对“centos怎么新建文件”大概比较着重,咱们都想要分析一些“centos怎么新建文件”的相关文章。那么小编也在网摘上搜集了一些对于“centos怎么新建文件””的相关知识,希望同学们能喜欢,你们一起来学习一下吧!

看到这个都是情非得已的,话不多说,直接卷

搭建本地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 -hFilesystem               Size  Used Avail Use% Mounted on/dev/mapper/centos-root   50G  1.9G   49G   4% /devtmpfs                  63G     0   63G   0% /devtmpfs                     63G     0   63G   0% /dev/shmtmpfs                     63G   11M   63G   1% /runtmpfs                     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% /hometmpfs                     13G     0   13G   0% /run/user/0/dev/loop0               4.5G  4.5G     0 100% /local-yum# 修改yum配置文件,把原先的配置先备份了cd /etc/yum.repos.dmkdir bakmv *.repo ./bak#新建local.repovim /etc/yum.repos.d/local.repo[base]name=CentOSbaseurl=清除下yum 原有的信息,载入新的缓存yum clean allyum makecache这样,一个崭新的本地yum源就可以使用了。
搭建局域网yum源

除了可以搭建本地yum源外,我们还可以基于HTTP方式配置yum源,这样我们就可以配置一个局域网内都可以使用的yum源。

一般都是通过apache 来搭建HTTP的yum源,本次我们使用Nginx搭建

#官网下载nginx1.18.0wget 安装依赖包,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.confworker_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 -tnginx: the configuration file /home/application/nginx/conf/nginx.conf syntax is oknginx: 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_BuildTagdrwxr-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 GPLdrwxr-xr-x. 3 root root         57 Apr 21  2020 imagesdrwxr-xr-x. 2 root root        198 Apr 21  2020 isolinuxdrwxr-xr-x. 2 root root         43 Apr 21  2020 LiveOSdrwxr-xr-x. 2 root root     225280 Apr 22  2020 Packagesdrwxrwxr-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-yumbaseurl=

#清除下yum 原有的信息,载入新的缓存

yum clean allyum makecache

这样,局域网yum源就可以使用了

#安装一个软件试下效果

[root@localhost ~]# yum install bash*Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfilePackage bash-4.2.46-34.el7.x86_64 already installed and latest versionResolving 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 ResolutionDependencies Resolved=================================================================================================================================================================================================================================================================== Package                                                            Arch                                                      Version                                                           Repository                                                    Size===================================================================================================================================================================================================================================================================Updating: bash-completion                                                    noarch                                                    1:2.1-8.el7                                                       Nginx-yum                                                     87 kTransaction Summary===================================================================================================================================================================================================================================================================Upgrade  1 PackageTotal download size: 87 kIs this ok [y/d/N]: yDownloading packages:No Presto metadata available for Nginx-yumbash-completion-2.1-8.el7.noarch.rpm                                                                                                                                                                                                        |  87 kB  00:00:00     Running transaction checkRunning transaction testTransaction test succeededRunning 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!

标签: #centos怎么新建文件