CentOS7 nginx安装并负载mysql
#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; # } #} }