centos 一键安装配置nginx脚本

本文介绍了一个用于在CentOS系统上一键安装和配置Nginx的shell脚本`installNginx.ssh`。通过编辑、授权及执行该脚本,可以便捷地完成Nginx的基础安装与设置。同时,文中提到了基本命令的使用,并指出在`/usr/local/nginx/site`目录下,可以管理虚拟主机,如复制并修改`default.conf`模板来创建新的虚拟主机配置文件。
摘要由CSDN通过智能技术生成

centos 一键安装配置nginx脚本

installNginx.ssh

用vi或则vim编辑 installNginx.ssh

#!/bin/bash
# author:kwin
# Email:kwinwong@hotmail.com

src="/usr/local/src/"
cd $src

#找到指定进程,并杀死
#findPortKill 80
findPortKill (){
  processe=`lsof -i:${1} -n|awk '{print $2}'|grep '^[1-9]'`
  for i in $processe
    do
#  echo "Kill the $1 process [ $i ]"
  kill -9 $i
    done
}

#将命令所在目录添加到系统参数PATH中,方便调用
addToPATH(){

bin=${1}

echo $PATH|grep ${bin} >/dev/null
if [ $? -ne 0 ]; then

echo "export PATH=\$PATH:${bin}">>/etc/profile
fi
}



nginxConf(){

cp /usr/local/nginx/conf/nginx.conf  /usr/local/nginx/conf/nginx.conf.bak
sed -i '35,79c  include  ../site/*.conf;' /usr/local/nginx/conf/nginx.conf
mkdir /usr/local/nginx/site

cat>/usr/local/nginx/site/default.conf<<EOF
    server {
        listen       80;
        server_name  localhost;

        gzip on; #开启gizip
        gzip_buffers 32 4K;#压缩在内存中缓冲32块? 每块4K
        gzip_comp_level 6 ;#压缩级别 推荐6
        gzip_min_length 4000;#开始压缩的最小长度4bit
        gzip_types text/css text/xml apploation/x-javascript;
好的,以下是分别针对CentOS系统下的源码一键部署安装配置Redis持久化存储、MongoDB和Nginx脚本,以及CentOS系统下源码一键部署安装配置Redis数据库的脚本。请注意,这些脚本仅供参考,使用前请仔细检查并根据自己的需要进行相应的修改。 1. CentOS系统下源码一键部署安装配置Redis持久化存储脚本 ``` #!/bin/bash # 安装Redis相关依赖 yum install -y gcc make wget # 下载Redis源码 wget http://download.redis.io/releases/redis-6.2.5.tar.gz # 解压Redis源码 tar -zxvf redis-6.2.5.tar.gz # 进入Redis源码目录 cd redis-6.2.5 # 编译Redis源码 make # 安装Redis make install # 创建Redis配置文件 cp redis.conf /etc/redis.conf # 修改Redis配置文件 sed -i 's/daemonize no/daemonize yes/g' /etc/redis.conf sed -i 's/# requirepass foobared/requirepass yourpassword/g' /etc/redis.conf sed -i 's/# appendonly no/appendonly yes/g' /etc/redis.conf # 启动Redis服务 redis-server /etc/redis.conf ``` 2. CentOS系统下源码一键部署安装配置MongoDB脚本 ``` #!/bin/bash # 安装MongoDB相关依赖 yum install -y gcc make wget # 下载MongoDB源码 wget https://fastdl.mongodb.org/src/mongodb-src-r4.4.6.tar.gz # 解压MongoDB源码 tar -zxvf mongodb-src-r4.4.6.tar.gz # 进入MongoDB源码目录 cd mongodb-src-r4.4.6 # 编译MongoDB源码 scons # 安装MongoDB scons --prefix=/usr/local/mongodb install # 创建MongoDB配置文件 mkdir /usr/local/mongodb/conf cp ./mongod.conf /usr/local/mongodb/conf/mongod.conf # 修改MongoDB配置文件 sed -i 's/#auth = true/auth = true/g' /usr/local/mongodb/conf/mongod.conf # 启动MongoDB服务 /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/conf/mongod.conf ``` 3. CentOS系统下源码一键部署安装配置Nginx脚本 ``` #!/bin/bash # 安装Nginx相关依赖 yum install -y gcc make wget zlib-devel openssl-devel pcre-devel # 下载Nginx源码 wget http://nginx.org/download/nginx-1.21.0.tar.gz # 解压Nginx源码 tar -zxvf nginx-1.21.0.tar.gz # 进入Nginx源码目录 cd nginx-1.21.0 # 编译Nginx源码 ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre make && make install # 创建Nginx配置文件 cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak cat > /usr/local/nginx/conf/nginx.conf <<EOF user www www; worker_processes auto; error_log /usr/local/nginx/logs/error.log; pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include 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 /usr/local/nginx/logs/access.log main; sendfile on; tcp_nopush on; keepalive_timeout 60s; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } } server { listen 443 ssl; server_name localhost; ssl_certificate /usr/local/nginx/conf/server.crt; ssl_certificate_key /usr/local/nginx/conf/server.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; } } } EOF # 启动Nginx服务 /usr/local/nginx/sbin/nginx ``` 4. CentOS系统下源码一键部署安装配置Redis数据库一键自己部署安装脚本 ``` #!/bin/bash # 安装Redis相关依赖 yum install -y gcc make wget # 下载Redis源码 wget http://download.redis.io/releases/redis-6.2.5.tar.gz # 解压Redis源码 tar -zxvf redis-6.2.5.tar.gz # 进入Redis源码目录 cd redis-6.2.5 # 编译Redis源码 make # 安装Redis make install # 创建Redis目录 mkdir /usr/local/redis # 将Redis配置文件复制到Redis目录下 cp redis.conf /usr/local/redis/redis.conf # 设置Redis为后台运行模式 sed -i 's/daemonize no/daemonize yes/g' /usr/local/redis/redis.conf # 设置Redis密码 sed -i 's/# requirepass foobared/requirepass yourpassword/g' /usr/local/redis/redis.conf # 设置Redis持久化 sed -i 's/# appendonly no/appendonly yes/g' /usr/local/redis/redis.conf # 启动Redis服务 redis-server /usr/local/redis/redis.conf ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值