欢迎访问我的博客,你的支持,是我最大的动力!

Tengine2.3.2编译/内核参数优化/其他相关优化

Linux 小马奔腾 332℃ 评论
目录:
[显示]

系统为centos 8.1

Tengine 2.3.2 编译安装

此安装包含的模块如下

/opt/tengine/sbin/nginx -Vm
Tengine version: Tengine/2.3.2
nginx version: nginx/1.17.3
built by gcc 8.3.1 20190507 (Red Hat 8.3.1-4) (GCC)
built with OpenSSL 1.1.1c FIPS 28 May 2019
TLS SNI support enabled
configure arguments: --prefix=/opt/tengine --with-http_realip_module --with-http_geoip_module --with-http_lua_module --with-luajit-lib=/usr/local/lib --with-luajit-inc=/usr/local/include/luajit-2.1 --add-module=../nginx-module-vts --add-module=../ngx_devel_kit-0.3.1 --add-module=modules/ngx_http_upstream_session_sticky_module --add-module=modules/ngx_http_upstream_check_modulenginx: loaded modules:
nginx: ngx_core_module (static)
nginx: ngx_errlog_module (static)
nginx: ngx_conf_module (static)
nginx: ngx_openssl_module (static)
nginx: ngx_regex_module (static)
nginx: ngx_events_module (static)
nginx: ngx_event_core_module (static)
nginx: ngx_epoll_module (static)
nginx: ngx_procs_module (static)
nginx: ngx_proc_core_module (static)
nginx: ngx_http_module (static)
nginx: ngx_http_core_module (static)
nginx: ngx_http_log_module (static)
nginx: ngx_http_upstream_module (static)
nginx: ngx_http_static_module (static)
nginx: ngx_http_autoindex_module (static)
nginx: ngx_http_index_module (static)
nginx: ngx_http_mirror_module (static)
nginx: ngx_http_try_files_module (static)
nginx: ngx_http_auth_request_module (static)
nginx: ngx_http_auth_basic_module (static)
nginx: ngx_http_access_module (static)
nginx: ngx_http_limit_conn_module (static)
nginx: ngx_http_limit_req_module (static)
nginx: ngx_http_realip_module (static)
nginx: ngx_http_geo_module (static)
nginx: ngx_http_geoip_module (static)
nginx: ngx_http_map_module (static)
nginx: ngx_http_split_clients_module (static)
nginx: ngx_http_referer_module (static)
nginx: ngx_http_rewrite_module (static)
nginx: ngx_http_ssl_module (static)
nginx: ngx_http_proxy_module (static)
nginx: ngx_http_fastcgi_module (static)
nginx: ngx_http_uwsgi_module (static)
nginx: ngx_http_scgi_module (static)
nginx: ngx_http_memcached_module (static)
nginx: ngx_http_empty_gif_module (static)
nginx: ngx_http_browser_module (static)
nginx: ngx_http_upstream_hash_module (static)
nginx: ngx_http_upstream_ip_hash_module (static)
nginx: ngx_http_upstream_least_conn_module (static)
nginx: ngx_http_upstream_random_module (static)
nginx: ngx_http_upstream_keepalive_module (static)
nginx: ngx_http_upstream_zone_module (static)
nginx: ngx_http_stub_status_module (static)
nginx: ngx_http_vhost_traffic_status_module (static)
nginx: ndk_http_module (static)
nginx: ngx_http_upstream_check_module (static)
nginx: ngx_http_write_filter_module (static)
nginx: ngx_http_header_filter_module (static)
nginx: ngx_http_chunked_filter_module (static)
nginx: ngx_http_range_header_filter_module (static)
nginx: ngx_http_gzip_filter_module (static)
nginx: ngx_http_postpone_filter_module (static)
nginx: ngx_http_ssi_filter_module (static)
nginx: ngx_http_charset_filter_module (static)
nginx: ngx_http_userid_filter_module (static)
nginx: ngx_http_headers_filter_module (static)
nginx: ngx_http_upstream_session_sticky_module (static)
nginx: ngx_http_lua_module (static)
nginx: ngx_http_copy_filter_module (static)
nginx: ngx_http_range_body_filter_module (static)
nginx: ngx_http_not_modified_filter_module (static)

内核参数优化

注意 某些情况下 net.ipv4.ip_no_pmtu_disc 不能设置为 1 这会会导致ssh连接的时候不稳定 需设置为 0

其他相关优化

bcc 工具安装

项目地址:https://github.com/iovisor/bcc
yum update kernel
yum install bcc
安装完成后工具目录 /usr/share/bcc/tools
echo 'export PATH=$PATH:/usr/share/bcc/tools' >> /etc/profile
echo 'export PATH=$PATH:/usr/share/bcc/tools' >> /etc/bashrc
示例:
cd /usr/share/bcc/tools && ./tcpconnlat -t 1000

~/.bashrc 文件,追加

. /etc/profile
export PS1='\033[36m[\u@\h\033[0m \033[37m$(/sbin/ip a|grep inet|grep -v 127.0.0.1|cut -c 10-|cut -f 1 -d /|grep -v :|head -n 1)\033[0m \033[36m \t \w]\033[0m \n\$'

/etc/profile 追加

alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'

常用工具

yum install unzip lrzsz iotop htop atop iftop git
cd /usr/bin && ln -s python2 python

创建用户

useradd nginx
chown -R nginx:nginx /opt/tengine/

设置worker_processes worker_cpu_affinity 参数

启动nginx

/opt/tengine/sbin/nginx

添加开机启动

echo '/opt/tengine/sbin/nginx' >> /etc/rc.local
chmod +x /etc/rc.d/rc.local

日志轮换

nginx配置高亮

cd /usr/share/vim/vim80/syntax && wget http://www.vim.org/scripts/download_script.php?src_id=19394 -O nginx.vim
编辑/usr/share/vim/vim80/filetype.vim 添加
au BufRead,BufNewFile /opt/tengine/conf/*.conf,/opt/tengine/conf/*/*.conf if &ft == '' | setfiletype nginx | endif

vim出现兼容问题的解决(刚打开文件时光标处显示一个字符p)

git clone https://github.com/vim/vim.git
yum install ncurses-devel
cd vim/src
make
make install
cd /usr/bin/ && ln -s /usr/local/bin/vim vim
cd /usr/bin/ && ln -s /usr/local/bin/vim vi
cd /usr/local/share/vim/vim82/syntax && wget http://www.vim.org/scripts/download_script.php?src_id=19394 -O nginx.vim
vi ../filetype.vim
au BufRead,BufNewFile /opt/tengine/conf/*.conf,/opt/tengine/conf/*/*.conf if &ft == '' | setfiletype nginx | endif

vts配置

全局添加header头

# http 区块
access_by_lua 'ngx.req.set_header("Time", "t=" .. ngx.now())';

其他相关

坑:

nginx的语法检查不能检查lua代码块,如果lua中有语法错误,nginx -t 是不能识别到的
解决方法可参考:https://gist.github.com/cwarden/1207556
另,nginx中注释为 # 而lua中注释为 -- 错用会出现语法错误

-- 以上为部署概要,备查

 

转载请注明:轻风博客 » Tengine2.3.2编译/内核参数优化/其他相关优化

喜欢 (0)or分享 (0)