一、建立yum源
1.1 在线yum源
- 阿里云yum源。
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
yum install epel-release -y
yum clean all
yum makecache
- 华为云x86云服务器镜像源。
mkdir -p /etc/yum.repos.d/repo_bak/
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo_bak/
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.myhuaweicloud.com/repo/CentOS-Base-7.repo
yum clean all
yum makecache
1.2 离线本地yum源
- 上传Centos7 iso镜像到本机的bck目录,要求与安装本机使用的镜像是同一版本的DVD/Everything镜像。
- 创建挂载目录,并挂载。
mkdir -p /opt/yum_Centos7
- 挂载镜像。
mount /opt/bck/CentOS-7-x86_64-DVD-1804.iso /opt/yum_Centos7 -o loop
4.设置yum源
cat > /etc/yum.repos.d/Centos7_bck.repo <<EOF
[local]
name=local
baseurl=file:///opt/yum_Centos7
enabled=1
gpgcheck=0
EOF
- 建立yum缓存,安装服务测试效果。
yum clean all
yum makecache
1.3 离线挂载异地yum源
- 在第一台机器(192.168.150.129)上安装nginx服务,修改配置文件。
##可以使用任何方式安装nginx,修改nginx配置文件参数一模一样,我这里采用yum安装。
cat /etc/nginx/nginx.conf
user nginx;
worker_processes 1; ##修改,启动一个worker进程。
error_log /var/log/nginx/error.log warn; ##修改,调整错误日志级别。
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
##################################################################
cat /etc/nginx/conf.d/default.conf
server {
listen 80;
listen [::]:80; ##添加该参数,监听ipv6所有地址。
server_name localhost;
location / {
root /usr/share/nginx/html;
autoindex on;
autoindex_exact_size on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
-
将要挂载出来的文件放入到html目录下。
-
启动nginx服务,网页ip:port访问。
-
在第二台(192.168.150.128)机器上配置yum源,重建yum缓存。
cat > /etc/yum.repos.d/Centos7_bck.repo <<EOF
[local]
name=local
baseurl=http://192.168.150.129:80
enabled=1
gpgcheck=0
EOF
5.重建yum缓存,安装服务测试。
yum clean all
yum makecache
二、制作离线rpm包
1.在测试环境建立在线yum源。
cd /etc/yum.repos.d/
mkdir bck
mv CentOS-* bck/
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
yum install epel-release -y
yum clean all
yum makecache
2.设置yum安装服务后不删除本地安装包。
sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf
- 安装基本服务。
yum install autoconf bash-completion bind-utils cifs-utils createrepo dstat expect ftp gcc gcc-c++ glibc iotop lrzsz lsof make net-tools nfs-utils openssl openssl-devel openvpn pam-devel pcre-devel python2-pip rsync screen sysstat tcpdump telnet tree unzip vim wget yum-utils zip haveged
- 过滤出以上服务的安装包和依赖包。
mkdir -p /opt/bck
find /var/cache/yum/x86_64/7/ -name "*.rpm" |xargs -I {} mv {} /opt/bck/
- 建立yum仓库和元数据
cd /opt/bck/
createrepo .
- 将该目录打包发送给现场人员。
cd ../
tar zcf bck_yum.tar.gz bck
- 现场人员拿到压缩包后的操作。
##解压包。
tar zxmf bck_yum.tar.gz
##备份原有yum源。
mkdir -p /etc/yum.repos.d/bck
mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/bck/
##创建新本地yum源。
cat > /etc/yum.repos.d/bck_yum.repo <<EOF
[local]
name=local
baseurl=file:///root/bck
enabled=1
gpgcheck=0
EOF
##重建yum缓存。
yum clean all
yum makecache
##开始安装服务。
yum install autoconf bash-completion bind-utils cifs-utils createrepo dstat expect ftp gcc gcc-c++ glibc iotop lrzsz lsof make net-tools nfs-utils openssl openssl-devel openvpn pam-devel pcre-devel python2-pip rsync screen sysstat tcpdump telnet tree unzip vim wget yum-utils zip haveged --skip-broken