一键安装nginx,并同步清华大学centos,yum源到本地

#!/bin/bash
#rsync 一键脚本 可以直接用vim 创建一个123.sh文件然后把这里面的全部复制到里面直接执行以下就可以了
#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.14.0.tar.gz
tar -xzf nginx-1.14.0.tar.gz
cd nginx-1.14.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 enable nginx.service --now
#安装vsftpd
yum install vsftpd -y
systemctl enable vsftpd --now
#创建yum源存放目录
mkdir -p /var/ftp/pub/epel/7/
mkdir -p /var/ftp/pub/centos/7/os/x86_64/
mkdir -p /var/ftp/pub/centos/7/updates/x86_64/
mkdir -p /var/ftp/pub/centos/7/extras/x86_64/
mkdir -p /var/ftp/pub/centos/7/centosplus/x86_64/
echo "
SRPMS
aarch64
ppc64
repodata
EFI
LiveOS
CentOS_BuildTag
EULA
GPL
drpms
" >/var/ftp/pub/exclude.list
echo "

#epel
rsync -avz --exclude-from=/var/ftp/pub/exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/epel/7/ /var/ftp/pub/epel/7/
createrepo /var/ftp/pub/epel/7/
 
#centos7-base
rsync -avz --exclude-from=/var/ftp/pub/exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/ /var/ftp/pub/centos/7/os/x86_64/
createrepo /var/ftp/pub/centos/7/os/x86_64/
 
#centos7-updates
rsync -avz --exclude-from=/var/ftp/pub/exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/x86_64/ /var/ftp/pub/centos/7/updates/x86_64/
createrepo /var/ftp/pub/centos/7/updates/x86_64/
 
#centos7-extras
rsync -avz --exclude-from=/var/ftp/pub/exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/extras/x86_64/ /var/ftp/pub/centos/7/extras/x86_64/
createrepo /var/ftp/pub/centos/7/extras/x86_64/
 
#centos7-centosplus
rsync -avz --exclude-from=/var/ftp/pub/exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/centosplus/x86_64/ /var/ftp/pub/centos/7/centosplus/x86_64/
createrepo /var/ftp/pub/centos/7/centosplus/x86_64/
" >/var/ftp/pub/centos7-rsync.sh
#这条命令可以做一个定时任务,每星期1的凌晨2点定时同步一下
sh /var/ftp/pub/centos7-rsync.sh

客户端配置:

先把原有的删除掉或者移动走

例子:

cd /etc/yum.repos.d/

mkdir bak

mv *.repo bak/

再来编辑一个新的yum配置文件如下:

vim /etc/yum.repos.d/centos7.repo

写入以下内容

[base]
name=Base
baseurl=http://192.168.123.57/centos/7/os/x86_64/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[epel]
name=epel
baseurl=http://192.168.123.57/epel/7/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=Updates
baseurl=http://192.168.123.57/centos/7/updates/x86_64/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=Extras
baseurl=http://192.168.123.57/centos/7/extras/x86_64/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=Plus
baseurl=http://192.168.123.57/centos/7/centosplus/x86_64/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS

然后把原有的缓存清空一下:

yum clean all

再来生成一下缓存

yum makecache

这样就可以了,这样安装rpm包软件的时候就直接走本地的仓库而不需要走外网了!!!

Powered By Z-BlogPHP 1.7.3

 Theme By 优美模版

本博客为开源博客,本博客联系QQ:372097243