#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install"
exit 1
fi
# Check the network status
NET_NUM=`ping -c 4 www.baidu.com |awk '/packet loss/{print $6}' |sed -e 's/%//'`
if [ -z "$NET_NUM" ] || [ $NET_NUM -ne 0 ];then
echo "Please check your internet"
exit 1
fi
# Check the OS
if [ "$(awk '{if ( $3 >= 7.0 ) print "CentOS 7.x"}' /etc/redhat-release 2>/dev/null)" != "CentOS 7.x" ];then
err_echo "This script is used for RHEL/CentOS 7.x only."
exit 1
fi
function InitInstall()
{
#Set timezone
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum install -y ntpdate
ntpdate -u pool.ntp.org
date -R
rpm -qa|grep httpd
rpm -e httpd
yum -y remove httpd
yum -y install yum-fastestmirror
yum -y install gcc gcc-c++ make pcre-devel GeoIP* openssl-devel perl-devel perl-ExtUtils-Embed
if [ -s /data/www/vhosts ];then
echo "The web directory already exists!"
else
mkdir -p /data/www/vhosts
fi
}
function CheckAndDownloadFiles()
{
echo "============================check files=================================="
if [ -s nginx-1.10.2.tar.gz ];then
centos一键安装nginx脚本
最新推荐文章于 2024-08-02 08:45:18 发布
这是一个用于在CentOS 7系统上一键安装Nginx的bash脚本。它首先检查是否以root用户运行,然后检查网络连接,接着确认系统为CentOS 7,并移除已有的httpd服务。脚本下载并安装必要的依赖,创建web目录,最后编译并安装Nginx,设置配置文件,并启动Nginx服务。
摘要由CSDN通过智能技术生成