CentOS安装Redis详细步骤

2019-01-30  本文已影响0人  光光小哥

我下载的redis是1.14.0版本,客官可选择其他版本下载,附链接

从本地上传nginx-1.14.0.tar 到 /export/servers

解压: tar -xvf nginx-1.14.0.tar

yum install openssl-devel

yum install gcc-c++

yum install pcre pcre-devel

yum install zlib zlib-devel

yum install openssl

yum install openssl openssl--devel

cd nginx-1.14.0

./configure --prefix=/export/servers/nginx --with-http_stub_status_module --with-http_ssl_module

make install

cd /export/servers/nginx/conf

cp nginx.conf nginx.conf.bak

修改nginx.conf:

user admin admin;

worker_processes 2;

#worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

error_log /export/servers/nginx/logs/nginx_error.log warn;

pid /export/servers/nginx/logs/nginx.pid;

worker_rlimit_nofile 65535;

events

{

use epoll;

worker_connections 65535;

}

http

{

include mime.types;

default_type application/octet-stream;

server_tokens off;

log_format main '$proxy_add_x_forwarded_for,$remote_addr - $remote_user [$time_local] '

'"$request" $status $bytes_sent $request_body'

'"$http_referer" "$http_user_agent" '

'$upstream_addr $request_time $upstream_response_time'

'"$gzip_ratio"';

#charset utf-8;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 300m;

sendfile on;

tcp_nopush on;

keepalive_timeout 0;

tcp_nodelay on;

client_body_buffer_size 512k;

fastcgi_intercept_errors on;

proxy_connect_timeout 90;

proxy_read_timeout 180;

proxy_send_timeout 180;

proxy_buffer_size 256k;

proxy_buffers 4 256k;

proxy_busy_buffers_size 256k;

proxy_temp_file_write_size 256k;

server_name_in_redirect off;

proxy_hide_header X-Powered-By;

gzip on;

gzip_min_length 100;

gzip_buffers 4 16k;

gzip_http_version 1.0;

gzip_comp_level 9;

gzip_types text/plain application/x-javascript text/css application/xml;

gzip_vary on;

#check_shm_size 1000;

#check_shm_size 100m;

proxy_headers_hash_max_size 51200;

proxy_headers_hash_bucket_size 6400;

#error_page 400 401 402 403 404 405 408 410 412 413 414 415 500 501 502 503 506 = [http://www.xxx.com;](http://www.xxx.com/)

include domains/*.com;

###########status#########

server {

    listen 80 default;

    return 200;

 }

}

mkdir domains && cd domains
新建api.example.com, 写入如下配置

server {
listen 80;
listen 443 ssl;
server_name api.example.com;
# 如果不需要证书,则把下面两行去掉即可
ssl_certificate /export/servers/nginx/cert/api.example.com.pem; 
ssl_certificate_key /export/servers/nginx/cert/api.example.com.key;
location /shop {
proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8090; 
expires -1d;
access_log /export/servers/nginx/logs/example/example_access.log main;
error_log /export/servers/nginx/logs/example/example_error.log warn;
}
}

注: 如果不需要https, 把证书和443端口配置注释即可

mkdir -p /export/servers/nginx/logs/
cd /export/servers/nginx/ && mkdir cert && cd cert
上传ssl证书(在阿里云下载)到 /export/servers/nginx/cert
切换root用户
cd /export/servers/nginx/sbin && ./nginx

安装到此完成

配置Nginx为系统服务

root账户登录
cd /etc/init.d && touch nginx
在nginx文件编写如下脚本

#!/bin/bash
#
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/export/servers/nginx/sbin/nginx"
NGINX_CONF="/export/servers/nginx/conf/nginx.conf"
NGINX_PID="/export/servers/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL

chmod +x /etc/init.d/nginx
添加开机自启动: chkconfig –-add nginx
检测: chkconfig --list nginx
大功告成, 可以执行 service nginx start验证。

上一篇下一篇

猜你喜欢

热点阅读