前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS7 nginx安装并负载mysql

CentOS7 nginx安装并负载mysql

作者头像
肖哥哥
发布2020-08-06 19:31:41
5600
发布2020-08-06 19:31:41
举报
文章被收录于专栏:后台及大数据开发
代码语言:javascript
复制
#1.安装依赖项目:PCRE
链接: https://pan.baidu.com/s/1JA-Tifch8ftM32znQO1csQ 提取码: svgw
./configure
make && make install

#2.安装依赖项目:libtool 
链接: https://pan.baidu.com/s/18UohgCRggfhlwcAoVOlkvw 提取码: dnd6
./configure
make && make install

#3.安装nginx
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -xvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure --with-stream
make && make install

#4.直接启动
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx -s stop (quit)   #停止nginx
/usr/local/nginx/sbin/nginx -s reload        #重启nginx

#5.将nginx设置为服务并开机启动
cat > /usr/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable nginx
systemctl start nginx

定期清理日志

cat > /usr/local/nginx/clean_nginx_logs.sh <<"EOF"

#!/bin/bash

base_path='/usr/local/nginx/logs'
log_path=$(date -d yesterday +"%Y%m")
day=$(date -d yesterday +"%Y%m%d")

mkdir -p $base_path/$log_path
mv $base_path/access.log $base_path/$log_path/access_$day.log
mv $base_path/error.log $base_path/$log_path/error_$day.log


kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
EOF

chmod +x /usr/local/nginx/clean_nginx_logs.sh

加入crontab 定期执行日志清理
执行crontab -e,加入一行
0 0 * * * /bin/bash /usr/local/nginx/clean_nginx_logs.sh


默认配置文件

worker_processes auto;
worker_rlimit_nofile 100000;

events {
    worker_connections 2048;
    multi_accept on;
    use epoll;
}

stream{
    upstream mysql {
       hash $remote_addr consistent;
       server 192.168.6.117:3306 weight=5 max_fails=3 fail_timeout=30s;
       server 192.168.6.118:3306 weight=5 max_fails=3 fail_timeout=30s;
    }
    
    server {
       listen 23306;
       proxy_connect_timeout 1s;
       proxy_timeout 3s;
       proxy_pass mysql;
    }
}


http {
include mime.types;
    default_type application/octet-stream;

    log_format main '$time_iso8601, status: $status, request: $http_host $request, spent: $request_time, upstreamAaddr: $upstream_addr, clientIp: $remote_addr, agent: $http_user_agent';
    access_log /var/log/nginx/access.log main;

    sendfile on;
    proxy_ignore_client_abort on;

    #for upload
    client_max_body_size 60M;
    client_body_buffer_size 128k;

    client_header_buffer_size 128k;
    large_client_header_buffers 4 128k;

    keepalive_timeout 65;
    send_timeout 60;
    fastcgi_buffers 8 128k;
    proxy_connect_timeout 180;
    proxy_send_timeout 180;
    proxy_read_timeout 640;
    gzip on;

    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
    }



    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.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;
    #    }
    #}

}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-08-05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MySQL
腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档