因单位工作环境无法连接外网,自行架设一台离线yum源
1.准备一台可连接外网CentOS7主机,安装nginx,createrepo
sudo yum install nginx
sudo yum install createrepo
安装中可能报 :已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 没有可用软件包 nginx。 错误:无须任何处理
解决办法:
添加nginx源:
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
然后再执行安装
配置nginx:
查看nginx安装目录:
whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz /usr/share/man/man3/nginx.3pm.gz
进入配置目录添加配置:
添加autoindex on;autoindex_exact_size on;autoindex_localtime on开启文件大小以及修改时间的显示
cd /etc/nginx
vim nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
error_page 404 /404.html;
location = /40x.html {
}
页面添加目录超链接:
cd /usr/share/nginx/html
vim index.html
添加一行
CentOS-YUM
启动nginx并设置开机启动:
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
2.关闭防火墙
查看防火墙状态:
systemctl status firewalld.service
关闭防火墙:
systemctl stop firewalld.service
关闭开机启动防火墙:
systemctl disable firewalld.service
修改SELINUX设置:
vim /etc/sysconfig/selinux
并修改SELINUX=enforce为SELINUX=disabled
3.在html包下建立存放路径
mkdir -p /usr/share/nginx/html/CentOS-YUM/version_7.2/64bit/
给目录添加读写可执行权限
chmod -R +x /usr/share/nginx/html/
4.同步阿里云源(base,updates,extras,epel)
清除/etc/yum.repos.d/下的repo
获取阿里云源repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/CentOS-epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
同步下载包
reposync -p /usr/share/nginx/html/CentOS-YUM/version_7.2/64bit/
5.建仓(供client端检索使用)
createrepo -p /usr/share/nginx/html/CentOS-YUM/version_7.2/64bit/base/Packages
createrepo -p /usr/share/nginx/html/CentOS-YUM/version_7.2/64bit/extras/Packages
createrepo -p /usr/share/nginx/html/CentOS-YUM/version_7.2/64bit/updates/Packages
createrepo -p /usr/share/nginx/html/CentOS-YUM/version_7.2/64bit/epel
6.client端yum配置
备份原有repo文件
mkdir /back
mv ./* /back
新建new.repo文件
vim new.repo
[new_base]
name=source_from_loaclserver
baseurl=http://192.168.110.132/CentOS-YUM/version_7.2/64bit/base/Packeages
gpgcheck=0
enable=1
priority=1
[new_extras]
name=source_from_loaclserver
baseurl=http://192.168.110.132/CentOS-YUM/version_7.2/64bit/extras/Packeages
gpgcheck=0
enable=1
priority=2
[new_updates]
name=source_from_loaclserver
baseurl=http://192.168.110.132/CentOS-YUM/version_7.2/64bit/updates/Packeages
gpgcheck=0
enable=1
priority=3
[new_epel]
name=source_from_loaclserver
baseurl=http://192.168.110.132/CentOS-YUM/version_7.2/64bit/epel/Packeages
gpgcheck=0
enable=1
priority=4
[new_base]#这个是本源的名字,不能和其他的重复(随便,不重复)
name=source_from_loaclserver #名字(随便)
baseurl=http://192.168.110.132/CentOS-YUM/version_7.2/64bit/extras/Packeages #上方步骤一挂载镜像地址
gpgcheck=0 #安全检测 1-开启 0-不开启
enabled=1 #yum源是否启用 1-启用 0-不启用
priority=1#检索优先级
清理本地YUM缓存和重建
yum clean all
yum makecache
7.测试安装
yum install gcc