写一个关于源码安装nginx的shell脚本,关于centos7的
时间: 2023-03-14 11:20:45 浏览: 132
#!/bin/bash# 安装nginx
yum -y install nginx# 启动nginx
systemctl start nginx# 开放80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent# 重启防火墙
systemctl restart firewalld.service# 添加nginx服务
systemctl enable nginx.service
相关问题
写一个Centos系统的安装Nginx的shell脚本,需要离线安装
好的,我可以回答这个问题。以下是一个Centos系统的安装Nginx的shell脚本,可以离线安装:
```
#!/bin/bash
# 安装依赖
yum install -y gcc gcc-c++ make zlib-devel pcre-devel openssl-devel
# 下载Nginx源码包
wget http://nginx.org/download/nginx-1.18..tar.gz
# 解压源码包
tar -zxvf nginx-1.18..tar.gz
# 进入解压后的目录
cd nginx-1.18.
# 配置编译参数
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# 编译并安装
make && make install
# 启动Nginx
/usr/local/nginx/sbin/nginx
```
注意:在执行脚本之前,需要将Nginx源码包下载到当前目录下。此脚本仅适用于Centos系统,其他Linux系统可能需要稍作修改。
用shell脚本分别写出centos系统下源码一键部署安装配置redis持久化存储脚本,和centos系统下源码一键部署安装配置mongodb,以及和centos系统下源码一键部署安装配置Nginx,和centos系统下源码一键部署安装配置Redis数据库一键自己部署安装脚本
好的,以下是分别针对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
```
阅读全文