Copy #!/bin/bash
# make local yum repo dir
mkdir /yum_local -p
mkdir /yum_local/nginx
mkdir /yum_local/mysql
mkdir /yum_local/php
mkdir /yum_local/apache
mkdir /yum_local/other
# configure yum.conf, don't delete the packages after install software
sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf
# add nginx official yum source
cat > /etc/yum.repos.d/nginx.repo << EOF
[nginx]
name=Nginx
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
EOF
# add php tsinghua remi yum source
cat > /etc/yum.repos.d/remi-safe.repo << EOF
# This repository is safe to use with RHEL/CentOS base repository
# it only provides additional packages for the PHP stack
# all dependencies are in base repository or in EPEL
[remi-safe]
name=Safe Remi's RPM repository for Enterprise Linux 7 - \$basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/7/safe/\$basearch/
#baseurl=http://rpms.remirepo.net/enterprise/7/safe/\$basearch/
#mirrorlist=http://cdn.remirepo.net/enterprise/7/safe/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
EOF
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-remi https://rpms.remirepo.net/RPM-GPG-KEY-remi
# create yum cache
yum clean all
yum makecache
# install createrepo
yum install createrepo -y
# create local yum
createrepo /yum_local/
# install nginx
yum install nginx -y
# configure local yum nginx conf
cat > /etc/nginx/conf.d/yum_local.conf << EOF
server {
listen 80;
server_name 10.0.0.10;
location / {
root /yum_local;
index index.html;
autoindex on;
}
}
EOF
# start nginx service
systemctl start nginx
systemctl enable nginx
# copy software packages to local yum directory
# copy nginx
cp /var/cache/yum/x86_64/7/nginx/packages/* /yum_local/nginx/
createrepo --update /yum_local/
# install php
yum install php73-php php73-php-cli php73-php-common php73-php-devel php73-php-embedded php73-php-json php73-runtime -y
yum install php73-php php73-php-cli php73-php-common php73-php-devel php73-php-embedded php73-php-json php73-runtime -y
yum install php73-php-gd php73-php-mbstring php73-php-pdo php73-php-xml -y
yum install php73-php-gd php73-php-mbstring php73-php-pdo php73-php-xml -y
yum install php73-php-fpm php73-php-mysqlnd php73-php-opcache -y
yum install php73-php-fpm php73-php-mysqlnd php73-php-opcache -y
yum install php73-php-pecl-memcached php73-php-pecl-redis5 php73-php-pecl-mongodb -y
yum install php73-php-pecl-memcached php73-php-pecl-redis5 php73-php-pecl-mongodb -y
# 使用清华源进行下载
# https://mirrors.tuna.tsinghua.edu.cn/mysql/
# https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/
cd /yum_local
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/mysql-community-libs-5.7.26-1.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/mysql-community-common-5.7.26-1.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/mysql-community-client-5.7.26-1.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/mysql-community-server-5.7.26-1.el7.x86_64.rpm
# mysql服务需要下载4个包:
# mysql-client mysql-common mysql-libs mysql-server
# 卸载掉mariadb-lib后需要安装mysql-community-libs-compat,否则postfix无法启动
cp -f /var/cache/yum/x86_64/7/base/packages/* /yum_local/
cp -f /var/cache/yum/x86_64/7/epel/packages/* /yum_local/
cp -f /var/cache/yum/x86_64/7/extras/packages/* /yum_local/
cp -f /var/cache/yum/x86_64/7/nginx/packages/* /yum_local/
cp -f /var/cache/yum/x86_64/7/remi-safe/packages/* /yum_local/
cp -f /var/cache/yum/x86_64/7/updates/packages/* /yum_local/
mv -f /yum_local/nginx*.rpm /yum_local/nginx/
mv -f /yum_local/php*.rpm /yum_local/php/
mv -f /yum_local/mysql*.rpm /yum_local/mysql/
mv -f /yum_local/*.rpm /yum_local/other/
createrepo --update /yum_local/