0
点赞
收藏
分享

微信扫一扫

Debezium系列之:在 Kubernetes 上部署 Debezium

40dba2f2a596 2023-07-05 阅读 62
nginx运维

Nginx yum安装

配置Nginx的yum源

[nginx] 
name=nginx repo 
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ 
gpgcheck=0 
enabled=1

安装以及重启,检查

yum -y install nginx 默认安装最新版本
启动 关闭 重启 加载
systemctl start/stop/restart/reload nginx
设置开机自启动
systemctl ensible nginx

测试:浏览器访问或者curl访问
检查服务进程:ps aux |grep nginx
检查端口监听:netstat -lnp |grep ‘:80’
有防火墙,需加规则iptables -I INPUT -p tcp --dport 80 -j ACCEPT
nginx -V查看版本以及各个目录、参数

[root@localhost yum.repos.d]# nginx -V 
nginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

nginx 源码安装

wget http://nginx.org/download/nginx-1.24.0.tar.gz

tar -zxvf nginx-1.24.0.tar.gz -C /opt

安装编译环境
yum -y install gcc pcre-devel openssl-devel
编译安装
./configure --prefix=/opt/nginx-1.24.0
make && make install
nginx启动
/opt/nginx-1.24.0/sbin/nginx
Nginx加载
/opt/nginx-1.24.0/sbin/nginx -s reload
Nginx关闭
/opt/nginx-1.24.0/sbin/nginx -s stop

nginx 的控制脚本

#/bin/bash 
NGINX_SBIN="/opt/nginx-1.24.0/sbin/nginx"
NGINX_CONF="/opt/nginx-1.24.0/conf/nginx.conf"
NGINX_PID="/opt/nginx-1.24.0/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

Nginx的目录解析

ls -la /usr/local/nginx/conf 配置文件
ls -la /usr/local/nginx/logs 日志
ls -la /usr/local/nginx/html 默认页
/usr/local/nginx/sbin/nginx -V 查看版本号

Nginx配置文件

全局配置

全局配置(user、worker_processes、error_log、pid)
注意:Nginx的访问日志access.log的访问日志,不是在全局配置,是在http配置

worker配置

在这里插入图片描述
这个跟worker配置有关系,这个设置大少跟cpu决定

#user  nobody;
worker_processes  2;

events配置项结构

网络连接相关,worker_connections)

默认配置

这个是Nginx的默认配置

events {
    worker_connections  1024;
}

定义每个work_process同时开启的最大连接数,即允许最多只能有这么多连接

选项配置

accept_mutex on;
multi_accept on;
use epoll;

accept_mutex on;
当某一个时刻只有一个网络连接请求服务器时,服务器上有多个睡眠的进程会被同时叫醒,这样会损耗一定的服务器性能。
Nginx中的accept_mutex设置为on,将会对多个Nginx进程(worker processer)接收连接时进行序列化,防止多个进程争抢资源。
默认就是on。

multi_accept on;
nginx worker processer可以做到同时接收多个新到达的网络连接,前提是把该参数设置为on。
默认为off,即每个worker process一次只能接收一个新到达的网络连接。

Nginx服务器提供了多个事件驱动器模型来处理网络消息。
其支持的类型有:select、poll、kqueue、epoll、rtsing、/dev/poll以及eventport。

  • select:只能在Windows下使用,这个事件模型不建议在高负载的系统使用

  • poll:Nginx默认首选,但不是在所有系统下都可用

  • kqueue:这种方式在FreeBSD 4.1+, OpenBSD2.9+, NetBSD 2.0, 和 MacOS X系统中是最高效的

  • epoll: 这种方式是在Linux 2.6+内核中最高效的方式

  • rtsig:实时信号,可用在Linux 2.2.19的内核中,但不适用在高流量的系统中

  • /dev/poll: Solaris 7 11/99+,HP/UX 11.22+, IRIX 6.5.15+, and Tru64 UNIX 5.1A+操作系统最高效的方式

  • eventport: Solaris 10最高效的方式

http配置项

官方文档

MIME-Type

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

include mime.types; //cat conf/mime.types
这个文件在conf同一级别的文件
定义nginx能识别的网络资源媒体类型(如,文本、html、js、css、流媒体等)定义很多Nginx的支持打开的文件的类型,这样浏览器才能打开

default_type application/octet-stream;
定义默认的type,如果不定义该项,默认为text/plain.

log_format

#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  logs/access.log  main;

log_format main '$remote_addr - r e m o t e u s e r [ remote_user [ remoteuser[time_local] “KaTeX parse error: Double superscript at position 30: … '̲status b o d y b y t e s s e n t " body_bytes_sent " bodybytessent"http_referer” ’
‘“ h t t p u s e r a g e n t " " http_user_agent" " httpuseragent""http_x_forwarded_for”’;

其中main为日志格式的名字,后面的为nginx的内部变量组成的一串字符串。
这个可以,设置全流程访问 request_time和转发后台的访问配置upstream_response_time

access_log logs/access.log main;

定义日志的路径以及采用的日志格式,该参数可以在server配置块中定义。

server配置项

举报

相关推荐

0 条评论