系统环境:
|
[root@repo-server ~]# hostnamectl Static hostname: repo-server.com Icon name: computer-vm Chassis: vm Machine ID: ebe83143254245e19df9020ee65b02e4 Boot ID: a84656a6b2f44296823bbb8d7be3d8d8 Virtualization: microsoft Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-327.el7.x86_64 Architecture: x86-64 IP Address: 192.168.1.254 Selinux: disabled |
1、安装nignx 及创建yum 源文件所需的包
|
[root@repo-server ~]# yum install -y nginx createrepo libxml2-python |
2、修改nginx的配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
[root@repo-server ~]# egrep -v '^$|#' /etc/nginx/nginx.conf user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf; server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /data/repo; include /etc/nginx/default.d/*.conf; location / { autoindex on; autoindex_exact_size off; autoindex_localtime on; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } } |
3、安装扩展源:
|
[root@repo-server ~]#rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm |
4、创建rpm 包存放目录:
|
[root@repo-server ~]#mkdir -p /data/repo |
5、在/usr/local/sbin 目录下新建rpm包下载脚本:
|
[root@repo-server ~]# cat /usr/local/sbin/rpm_download.sh #!/usr/bin/env bash for i in $(yum list|egrep -v "^Loaded|^Loading|^Install|^ " |awk '{print $1}');do yumdownloader $i done |
6、进入 /data/repo 目录,执行rpm 脚本,下载所有的repo 包(注意:这个时间非常长)。在执行之前,先清除本地yum 缓存并重新生成缓存:
|
[root@repo-server repo]#yum clean all && yum makecache [root@repo-server repo]#sh /usr/local/sbin/rpm_download.sh |
7、下载完成后,启动nginx 服务,并开启防火墙的80 端口:
|
[root@repo-server repo]# service nginx start Redirecting to /bin/systemctl start nginx.service [root@repo-server repo]# firewall-cmd --zone=public --add-port=80/tcp --permanent success [root@repo-server repo]# firewall-cmd --reload success |
同时,测试访问yum 源,确保是下面这样的: 8、插入centos 7 的everythin 光盘,挂载到 /mnt:
|
[root@repo-server repo]# mount /dev/cdrom /mnt mount: /dev/sr0 is write-protected, mounting read-only |
9、执行 createrepo 创建yum 缓存数据(根据服务器性能所需的时间不一):
|
[root@repo-server ~]# createrepo -g /mnt/repodata/*-comps.xml /data/repo/ Spawning worker 0 with 19136 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete |
10、删除客户端 /etc/yum.repos.d 目下的所有配置,重新新建centos-7.repo 文件,配置如下:
|
[centos-7] name=centos-7-repo baseurl=http://192.168.137.254 enable=1 gpgcheck=0 |
11、清除客户端yum 缓存,重新生成缓存数据:
|
[root@node01-11 ~ 22:51:59]#yum clean all && yum makecache Loaded plugins: fastestmirror Cleaning repos: centos-7 Cleaning up everything Loaded plugins: fastestmirror centos-7 | 3.8 kB 00:00:00 (1/4): centos-7/group_gz | 155 kB 00:00:00 (2/4): centos-7/primary_db | 10 MB 00:00:00 (3/4): centos-7/filelists_db | 14 MB 00:00:00 (4/4): centos-7/other_db | 4.7 MB 00:00:00 Determining fastest mirrors Metadata Cache Created |
|
12、在客户端尝试安装软件包试试: [root@node01-11 ~ 22:52:32]#yum install -y tree |
13、卸载挂载的iso Read more…