利用yum命令同步yum源到本地 默认centos的yum源是国外的源,我们可以把自己的源修改成阿里云,清华大学,163的源 先来备份已经有的yum源 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 下载阿里云的base源到本地 Centos6的 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo Centos7的 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo Centos8的 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo 下载阿里云的epel源到本地 备份已有的源 mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup 下载新repo 到/etc/yum.repos.d/ Centos-8的 yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm Centos-7的 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo Centos-6的 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo 选择一种就可以,可以直接选择阿里云的镜像源 如果用清华大学的镜像源不需要备份 修改地址: https://mirrors.tuna.tsinghua.edu.cn/help/centos/ 安装需要同步的软件包和创建repo数据库的命令 yum install yum-utils createrepo -y 创建同步下来存放rpm包的目录 mkdir -pv /var/ftp/pub/centos/{6..7} mkdir -pv /var/ftp/pub/epel/{6..7} 先来同步base源,同步base源以后再去同步epel源 Centos-7同步base源 reposync -r base -r updates -p /var/ftp/pub/centos/7/ Centos-7同步epel源 reposync -r epel -p /var/ftp/pub/centos/7/ 创建yum所引数据库 createrepo /var/ftp/pub/centos/7/ createrepo /var/ftp/pub/epel/7/ 以上如果报错,执行以下,不报错千万不要去执行 createrepo /var/ftp/pub/centos/7/base/ createrepo /var/ftp/pub/centos/7/updates 安装nginx,脚本运行,让yum源,以web形式展示 编译一个脚本文件 vim install_nginx.sh 写入以下内容 #!/bin/bash #nginx-install NG_DIR="/usr/local/nginx" NG_CS="--user=www --group=www --with-http_stub_status_module --with-http_ssl_module" yum install wget gcc pcre pcre-devel openssl-devel openssl gzip createrepo make cmake zlib-devel tar lrzsz -y wget -c http://nginx.org/download/nginx-1.18.0.tar.gz tar -xzf nginx-1.18.0.tar.gz cd nginx-1.18.0 useradd www -s /sbin/nologin ./configure --prefix=$NG_DIR $NG_CS make make install echo $? echo " [Unit] Description=nginx service After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target ">/lib/systemd/system/nginx.service echo " worker_processes 2; worker_rlimit_nofile 65535; worker_cpu_affinity 1000 0100; events { worker_connections 15000; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; #include /usr/local/nginx/conf.d/*.conf; server { listen 80; #server_name mirror.9527edu.com; root /var/ftp/pub/; # access_log /var/log/nginx/access.log main; location / { autoindex on; autoindex_exact_size off; autoindex_localtime on; } } }" >/usr/local/nginx/conf/nginx.conf #设置为nginx开机自启动,并设置为开机自启动 systemctl daemon-reload systemctl start nginx.service systemctl enable nginx.service ss -ntl #安装vsftpd yum install vsftpd -y systemctl enable vsftpd systemctl start vsftpd 执行脚本,等待几分钟就行了,然后用浏览器访问你的服务器的IP地址 sh install_nginx.sh