专栏名称: 马哥Linux运维
马哥linux致力于linux运维培训,连续多年排名第一,订阅者可免费获得学习机会和相关Linux独家实战资料!
目录
相关文章推荐
51好读  ›  专栏  ›  马哥Linux运维

万字长文利用ELK分析Nginx日志生产实战(高清多图)

马哥Linux运维  · 公众号  · 运维  · 2019-10-09 21:00

正文

请到「今天看啥」查看全文


/updates/ $basearch /
gpgcheck= 1
gpgkey=http://mirrors.cloud.aliyuncs.com/centos/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS- $releasever
enabled= 1
failovermethod=priority
baseurl=http://mirrors.cloud.aliyuncs.com/centos/ $releasever /extras/ $basearch /
gpgcheck= 1
gpgkey=http://mirrors.cloud.aliyuncs.com/centos/RPM-GPG-KEY-CentOS-7

4.5、清理开机自启动服务

for i in `chkconfig --list|grep 3:on |awk '{print $1}'`;do chkconfig$i off;done
for i in crond network rsyslog sshd;do chkconfig --level 3 $ion;done
chkconfig --list|grep 3:on

4.6、服务器时间同步

echo '*/5 * * * * /usr/sbin/ntpdate time.windows.com > /dev/null2>&1' >>/var/spool/cron/root

4.7、加大文件描述符

echo '*        -    nofile 65535' >> /etc/security/limits.conf
tail -1 /etc/security/limits.conf
#重新登陆后生效(无需重启)
ulimit -n(重新登陆后查看)

4.8、 内核参数调优 ( 可不操作 )

\cp /etc/sysctl.conf /etc/sysctl.conf.bak
cat>>/etc/sysctl.conf<net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 65536 16777216
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout=1
net.ipv4.tcp_keepalive_time=1200
net.ipv4.tcp_max_syn_backlog = 65536
net.ipv4.ip_local_port_range = 1024 65535
EOF
/sbin/sysctl -p

五、部署开始

5.1、更改 nginx 志输出格式

5.1.1、定义日志格式

cat /etc/nginx/nginx.conf
log_format main '$remote_addr - $remote_user [$time_local]"$request" '
'$status$body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

5.1.2、加载日志格式到对应域名配置中

cat /etc/nginx/conf.d/vhost/api.mingongge.com.cn.conf
server {
listen 80;
server_name  newtest-msp-api.mingongge.com.cn;
access_log   /var/log/nginx/api.mingongge.com.cn.log main;
}

5.1.3、reload生效

nginx -s reload

5.1.4、清空原输出文件,并查看输出的日志格式

:> /var/log






请到「今天看啥」查看全文