zabbix_agentd监控配置说明

Agent 监控配置说明

 

Linux安装Agent

1.查看系统版本

查看系统版本

uname -a
1
根据系统版本下载对应的zabbix-agent版本安装
下载地址:http://repo.zabbix.com/zabbix

2.安装zabbix-agent

把下载好的rpm安装包拷贝到主机上
运行命令安装

rpm -ivh zabbix-agent-3.0.4-1.el7.x86_64.rpm
1
安装完成后设置开机自动启动

chkconfig zabbix-agent on
1
3.配置zabbix-agent

ServerActive=10.0.0.105(zabbix-server的IP地址)
Timeout=15(超时时间)
AllowRoot=1(允许以root运行)
UnsafeUserParameters=1(允许特殊字符)
UserParameter(配置自定义key)

详细配置详解

############ GENERAL PARAMETERS #################

### Option: PidFile
# Name of PID file.
#
# Mandatory: no
# Default:
# PidFile=/tmp/zabbix_agentd.pid

PidFile=/var/run/zabbix/zabbix_agentd.pid

PidFile
默认值:/tmp/zabbix_agentd.pid
PID文件名

### Option: LogType
# Specifies where log messages are written to:
# system – syslog
# file – file specified with LogFile parameter
# console – standard output
#
# Mandatory: no
# Default:
# LogType=file

LogType
指定日志消息写入的位置
system:syslog
file:使用LogFile参数指定的文件
console:标准输出

### Option: LogFile
# Log file name for LogType ‘file’ parameter.
#
# Mandatory: no
# Default:
# LogFile=

LogFile=/var/log/zabbix/zabbix_agentd.log

LogFile
日志文件路径
如果未配置,日志会记录到syslog中

### Option: LogFileSize
# Maximum size of log file in MB.
# 0 – disable automatic log rotation.
#
# Mandatory: no
# Range: 0-1024
# Default:
# LogFileSize=1
LogFileSize=0

LogFileSize
取值范围:0-1024
默认值:1
日志文件大小,单位为MB。
0 – 关闭自动轮滚.
备注:如果日志文件到达了最大值并且文件轮滚失败,那么老日志文件会被清空掉。

### Option: DebugLevel
# Specifies debug level:
# 0 – basic information about starting and stopping of Zabbix processes
# 1 – critical information
# 2 – error information
# 3 – warnings
# 4 – for debugging (produces lots of information)
# 5 – extended debugging (produces even more information)
#
# Mandatory: no
# Range: 0-5
# Default:
# DebugLevel=3

DebugLevel
取值范围:0-5
默认值:3
指定日志级别
0 – basic information about starting and stopping of Zabbix processes
1 – critical级别
2 – error级别
3 – warnings级别
4 – debug级别
5 – extended debugging (与级别4一样. 只能使用runtime control 来设置.)

### Option: SourceIP
# Source IP address for outgoing connections.
#
# Mandatory: no
# Default:
# SourceIP=

SourceIP
zabbix对外连接的出口IP地址

### Option: EnableRemoteCommands
# Whether remote commands from Zabbix server are allowed.
# 0 – not allowed
# 1 – allowed
#
# Mandatory: no
# Default:
# EnableRemoteCommands=0

EnableRemoteCommands
默认值:0
是否运行zabbix server在此服务器上执行远程命令
0 – 禁止
1 – 允许

### Option: LogRemoteCommands
# Enable logging of executed shell commands as warnings.
# 0 – disabled
# 1 – enabled
#
# Mandatory: no
# Default:
# LogRemoteCommands=0

LogRemoteCommands
默认值:0
记录原型执行的shell命令日志,级别为warrning
0 – disabled
1 – enabled

### Option: Server
# List of comma delimited IP addresses (or hostnames) of Zabbix servers.
# Incoming connections will be accepted only from the hosts listed here.
# If IPv6 support is enabled then ‘127.0.0.1’, ‘::127.0.0.1’, ‘::ffff:127.0.0.1’ are treated equally.
#
# Mandatory: no
# Default:
# Server=

Server=10.0.0.100

Server
zabbix server的ip地址,多个ip使用逗号分隔

### Option: ListenPort
# Agent will listen on this port for connections from the server.
#
# Mandatory: no
# Range: 1024-32767
# Default:
# ListenPort=10050

ListenPort
取值范围:1024-32767
默认值10050
监听端口

### Option: ListenIP
# List of comma delimited IP addresses that the agent should listen on.
# First IP address is sent to Zabbix server if connecting to it to retrieve list of active checks.
#
# Mandatory: no
# Default:
# ListenIP=0.0.0.0

ListenIP
默认值:0.0.0.0
监听IP地址,默认为所有接口,多个ip之间使用逗号分隔

### Option: StartAgents
# Number of pre-forked instances of zabbix_agentd that process passive checks.
# If set to 0, disables passive checks and the agent will not listen on any TCP port.
#
# Mandatory: no
# Range: 0-100
# Default:
# StartAgents=3

StartAgents
取值范围:0-100
默认值:3
zabbix启动之后开启被动监控的进程数量,如果设置为0,那么zabbix被动监控被禁用,并且不会监听相应端口,也就是说10050端口不会开启。

### Option: ServerActive
# List of comma delimited IP:port (or hostname:port) pairs of Zabbix servers for active checks.
# If port is not specified, default port is used.
# IPv6 addresses must be enclosed in square brackets if port for that host is specified.
# If port is not specified, square brackets for IPv6 addresses are optional.
# If this parameter is not specified, active checks are disabled.
# Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]
#
# Mandatory: no
# Default:
# ServerActive=

ServerActive=10.0.0.100:10052

ServerActive
zabbix 主动监控server的ip地址,使用逗号分隔多IP,如果注释这个选项,那么当前服务器的主动监控就被禁用了

### Option: Hostname
# Unique, case sensitive hostname.
# Required for active checks and must match hostname as configured on the server.
# Value is acquired from HostnameItem if undefined.
#
# Mandatory: no
# Default:
# Hostname=

Hostname
默认值:HostnameItem配置的值
主机名,必须唯一,区分大小写。Hostname必须和zabbix web上配置的一直,否则zabbix主动监控无法正常工作。为什么呢?因为agent拿着这个主机名去问server,我有配置主动监控项 吗?server拿着这个主机名去配置里面查询,然后返回信息。
支持字符:数字字母、’.’、’ ‘、 ‘_’、 ‘-‘,不超过64个字符

### Option: HostnameItem
# Item used for generating Hostname if it is undefined. Ignored if Hostname is defined.
# Does not support UserParameters or aliases.
#
# Mandatory: no
# Default:
# HostnameItem=system.hostname

HostnameItem
默认值:system.hostname
设置主机名,只有当HostMetadata没设置,她才生效。不支持UserParameters 、aliases,支持system.run[]

### Option: HostMetadata
# Optional parameter that defines host metadata.
# Host metadata is used at host auto-registration process.
# An agent will issue an error and not start if the value is over limit of 255 characters.
# If not defined, value will be acquired from HostMetadataItem.
#
# Mandatory: no
# Range: 0-255 characters
# Default:
# HostMetadata=

HostMetadata
取值范围:0-255 字符
仅用于主机自动注册功能,如果当前值为定义,那么它的值默认为HostMetadataItem的值。这个选项在2.2.0之后加入,并且确保支付不能超过限制,以及字符串必须是UTF8,否则服务器无法启动

### Option: HostMetadataItem
# Optional parameter that defines an item used for getting host metadata.
# Host metadata is used at host auto-registration process.
# During an auto-registration request an agent will log a warning message if
# the value returned by specified item is over limit of 255 characters.
# This option is only used when HostMetadata is not defined.
#
# Mandatory: no
# Default:
# HostMetadataItem=

HostMetadataItem
功能同上,如果HostMetadata值未设置,这个配置才有效。支持使用UserParameters、alias、system.run[]

### Option: RefreshActiveChecks
# How often list of active checks is refreshed, in seconds.
#
# Mandatory: no
# Range: 60-3600
# Default:
# RefreshActiveChecks=120

RefreshActiveChecks
取值范围:60-3600
默认值:120
多久时间(秒)刷新一次主动监控配置信息,如果刷新失败,那么60秒之后会重试一次

### Option: BufferSend
# Do not keep data longer than N seconds in buffer.
#
# Mandatory: no
# Range: 1-3600
# Default:
# BufferSend=5

BufferSend
取值范围:1-3600
默认值:5
数据存储在buffer中最长多少秒

### Option: BufferSize
# Maximum number of values in a memory buffer. The agent will send
# all collected data to Zabbix Server or Proxy if the buffer is full.
#
# Mandatory: no
# Range: 2-65535
# Default:
# BufferSize=100

BufferSize
取值范围:2-65535
默认值:100
buffer最大值,如果buffer满了,zabbix将会将检索到的数据发送给zabbix server或者proxy

### Option: MaxLinesPerSecond
# Maximum number of new lines the agent will send per second to Zabbix Server
# or Proxy processing ‘log’ and ‘logrt’ active checks.
# The provided value will be overridden by the parameter ‘maxlines’,
# provided in ‘log’ or ‘logrt’ item keys.
#
# Mandatory: no
# Range: 1-1000
# Default:
# MaxLinesPerSecond=20

MaxLinesPerSecond
取值范围:1-1000
默认值:20
处理监控类型为log何eventlog日志时,agent每秒最大发送的行数。默认为20行

### Option: Alias
# Sets an alias for an item key. It can be used to substitute long and complex item key with a smaller and simpler one.
# Multiple Alias parameters may be present. Multiple parameters with the same Alias key are not allowed.
# Different Alias keys may reference the same item key.
# For example, to retrieve the ID of user ‘zabbix’:
# Alias=zabbix.userid:vfs.file.regexp[/etc/passwd,^zabbix:.:([0-9]+),,,,\1]
# Now shorthand key zabbix.userid may be used to retrieve data.
# Aliases can be used in HostMetadataItem but not in HostnameItem parameters.
#
# Mandatory: no
# Range:
# Default:

Alias
key的别名,例如 Alias=ttlsa.userid:vfs.file.regexp[/etc/passwd,^ttlsa:.:([0-9]+),,,,\1], 或者ttlsa的用户ID。你可以使用key:vfs.file.regexp[/etc/passwd,^ttlsa:.: ([0-9]+),,,,\1],也可以使用ttlsa.userid。

备注: 别名不能重复,但是可以有多个alias对应同一个key。

### Option: Timeout
# Spend no more than Timeout seconds on processing
#
# Mandatory: no
# Range: 1-30
# Default:
# Timeout=3

Timeout
默认值:1-30
默认值:3
超时时间

### Option: AllowRoot
# Allow the agent to run as ‘root’. If disabled and the agent is started by ‘root’, the agent
# will try to switch to the user specified by the User configuration option instead.
# Has no effect if started under a regular user.
# 0 – do not allow
# 1 – allow
#
# Mandatory: no
# Default:
# AllowRoot=0
AllowRoot=1

AllowRoot
默认值:0
是否允许使用root身份运行zabbix,如果值为0,并且是在root环境下,zabbix会尝试使用zabbix用户运行,如果不存在会告知zabbix用户不存在。
0 – 不允许
1 – 允许

### Option: User
# Drop privileges to a specific, existing user on the system.
# Only has effect if run as ‘root’ and AllowRoot is disabled.
#
# Mandatory: no
# Default:
# User=zabbix

User
默认值:zabbix
运行zabbix程序的用户,如果AllowRoot被禁用,才有效果

### Option: Include
# You may include individual files or all files in a directory in the configuration file.
# Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time.
#
# Mandatory: no
# Default:
# Include=

Include=/etc/zabbix/zabbix_agentd.d/

# Include=/usr/local/etc/zabbix_agentd.userparams.conf
# Include=/usr/local/etc/zabbix_agentd.conf.d/
# Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf

nclude
包含自配置文件,不同的配置写到不同的文件中,然后include,配置文件会显得规范。例如: /absolute/path/to/config/files/*.conf. Zabbix 2.4.0开始支持正则表达式。

### Option: UnsafeUserParameters
# Allow all characters to be passed in arguments to user-defined parameters.
# The following characters are not allowed:
# \ ‘ ” ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @
# Additionally, newline characters are not allowed.
# 0 – do not allow
# 1 – allow
#
# Mandatory: no
# Range: 0-1
# Default:
# UnsafeUserParameters=0
UnsafeUserParameters=1

UnsafeUserParameters
取值范围:0,1
默认值: 0
允许所有字符的参数传递给用户定义的参数(包括特殊字符)。

### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# See ‘zabbix_agentd’ directory for examples.
#
# Mandatory: no
# Default:
# UserParameter=
UserParameter=system.cpu.steal,nproc
UserParameter=dskTotal[*],python /root/disk.py $1 $2
UserParameter=ifNumber,/etc/init.d/network status |awk ‘NR==4’|awk -v RS=”@#$j” ‘{print gsub(/ /,”&”)+1}’
UserParameter=ifInQLen[*],ethtool -S $1 |grep ‘Tx Queue#:’|awk ‘{print $2 3}’
UserParameter=ifOutQLen[*],ethtool -S $1 |grep ‘Rx Queue#:’|awk ‘{print $2 3}’
UserParameter=ifStatus[*],python /root/Net.py $1 $2

UserParameter
用户自定义key,格式: UserParameter=,
例如:serParameter=system.test,who|wc -l

### Option: LoadModulePath
# Full path to location of agent modules.
# Default depends on compilation options.
#
# Mandatory: no
# Default:
# LoadModulePath=${libdir}/modules

LoadModulePath
模块路径,绝对路径

### Option: LoadModule
# Module to load at agent startup. Modules are used to extend functionality of the agent.
# Format: LoadModule=<module.so>
# The modules must be located in directory specified by LoadModulePath.
# It is allowed to include multiple LoadModule parameters.
#
# Mandatory: no
# Default:
# LoadModule=

LoadModule
加载模块文件,可以写多个
格式: LoadModule=
必须配置LoadModulePath,指定模块目录

####### TLS-RELATED PARAMETERS #######

### Option: TLSConnect
# How the agent should connect to server or proxy. Used for active checks.
# Only one value can be specified:
# unencrypted – connect without encryption
# psk – connect using TLS and a pre-shared key
# cert – connect using TLS and a certificate
#
# Mandatory: yes, if TLS certificate or PSK parameters are defined (even for ‘unencrypted’ connection)
# Default:
# TLSConnect=unencrypted

### Option: TLSAccept
# What incoming connections to accept.
# Multiple values can be specified, separated by comma:
# unencrypted – accept connections without encryption
# psk – accept connections secured with TLS and a pre-shared key
# cert – accept connections secured with TLS and a certificate
#
# Mandatory: yes, if TLS certificate or PSK parameters are defined (even for ‘unencrypted’ connection)
# Default:
# TLSAccept=unencrypted

### Option: TLSCAFile
# Full pathname of a file containing the top-level CA(s) certificates for
# peer certificate verification.
#
# Mandatory: no
# Default:
# TLSCAFile=

### Option: TLSCRLFile
# Full pathname of a file containing revoked certificates.
#
# Mandatory: no
# Default:
# TLSCRLFile=

### Option: TLSServerCertIssuer
# Allowed server certificate issuer.
#
# Mandatory: no
# Default:
# TLSServerCertIssuer=

### Option: TLSServerCertSubject
# Allowed server certificate subject.
#
# Mandatory: no
# Default:
# TLSServerCertSubject=

### Option: TLSCertFile
# Full pathname of a file containing the agent certificate or certificate chain.
#
# Mandatory: no
# Default:
# TLSCertFile=

### Option: TLSKeyFile
# Full pathname of a file containing the agent private key.
#
# Mandatory: no
# Default:
# TLSKeyFile=

### Option: TLSPSKIdentity
# Unique, case sensitive string used to identify the pre-shared key.
#
# Mandatory: no
# Default:
# TLSPSKIdentity=

### Option: TLSPSKFile
# Full pathname of a file containing the pre-shared key.
#
# Mandatory: no
# Default:
# TLSPSKFile=

windows安装Agent

1.下载zabbix-agent压缩包

下载地址:http://www.zabbix.com/download

2.安装zabbix-agent

1)在非C盘的任意盘创建zabbix文件夹(以D盘为例)
2)解压下载的zabbix-agent文件,根据系统是64位还是32位系统,选择对应版本(以64位为例)
3)将解压出来的文件夹下的 bin\win64 文件夹中的文件拷贝到创建的zabbix文件夹下
4)将解压出来的文件夹下的 conf 文件夹拷贝到创建的zabbix文件夹下
5)打开 zabbix\conf\ 下的zabbix_agentd.win.conf 修改配置(方法同上)
6)修改好后保存退出,打开终端,运行

D:\zabbix\zabbix_agentd.exe -c D:\zabbix\conf\zabbix_agentd.win.conf -i

D:\zabbix\zabbix_agentd.exe -c D:\zabbix\conf\zabbix_agentd.win.conf -s

-i 安装
-d 卸载
-s 启动
-x 停止
-h 帮助
-c 配置文件位置
注意: 关闭防火墙,或者开放指定端口

转自:http://blog.csdn.net/qq_28426351/article/details/53485435

发表在 zabbix | 标签为 | 留下评论

Python 报错:UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe6 in position 0: ordinal not in range(128)

照着网上的脚本,运行时候发现UnicodeDecodeError

本身我在脚本里面已经申明了ASCII编码

# -*-coding:utf-8-*-
解决办法:加入一下代码
#sys模块包括了一组非常实用的服务,内含很多函数方法和变量,用来处理Python运行时配置以及资源,从而可以与前当程序之外的系统环境交互(具体介绍和使用可以自行百度)
#导入sys库
import sys
# 设置系统默认编码,执行dir(sys)时不会看到这个方法,在解释器中执行不通过,可以先执行reload(sys),在执行 setdefaultencoding('utf-8'),此时将系统默认编码设置为utf-8。(见设置系统默认编码 )
reload(sys)

sys.setdefaultencoding('utf-8')#添加该方法声明编码
搞完收工,一切正常了
转载自https://www.jianshu.com/p/bca627a3975c,感谢原作者
发表在 python | 留下评论

ls 按文件大小、时间排序

ls 按文件大小、时间排序

ls可以按照文件大小进行输出排序,这是一个很实用的参数。

man ls

-S sort by file size

由大到小排序

ls -Sl
从小到大排序

ls -Slr
-h,表示”–human-readable”,单位是k或者M ,比较容易看清楚结果。

显示子目录结构

ls -R
附:ls按时间排序

ls -lt 从新到旧
ls -lrt 从旧到新

发表在 LinuxBasic | 标签为 | 留下评论

mysql TPS和QPS查询sql

mysql TPS和qps查询sql

TPS查询

select VARIABLE_VALUE into @num_com from GLOBAL_STATUS
where VARIABLE_NAME =’COM_COMMIT’;
select VARIABLE_VALUE into @num_roll from GLOBAL_STATUS
where VARIABLE_NAME =’COM_ROLLBACK’;
select VARIABLE_VALUE into @uptime from GLOBAL_STATUS
where VARIABLE_NAME =’UPTIME’;
select (@num_com+@num_roll)/@uptime;

QPS查询

select VARIABLE_VALUE into @num_queries from GLOBAL_STATUS
where VARIABLE_NAME =’QUESTIONS’;
select VARIABLE_VALUE into @uptime from GLOBAL_STATUS
where VARIABLE_NAME =’UPTIME’;
select @num_queries/@uptime;

发表在 mysql | 标签为 , , | 留下评论

shell脚本中echo显示内容带颜色

shell脚本中echo显示内容带颜色显示,echo显示带颜色,需要使用参数-e 格式如下:

echo -e "\033[字背景颜色;文字颜色m字符串\033[0m"

例如:

echo -e "\033[41;36m something here \033[0m"

其中41的位置代表底色, 36的位置是代表字的颜色c
注:
1、字背景颜色和文字颜色之间是英文的””
2、文字颜色后面有个m
3、字符串前后可以没有空格,如果有的话,输出也是同样有空格
下面是相应的字和背景颜色,可以自己来尝试找出不同颜色搭配

echo -e “\033[31m 红色字 \033[0m”
echo -e “\033[34m 黄色字 \033[0m”
echo -e “\033[41;33m 红底黄字 \033[0m”
echo -e “\033[41;37m 红底白字 \033[0m”
字颜色:30—–37
echo -e “\033[30m 黑色字 \033[0m”
echo -e “\033[31m 红色字 \033[0m”
echo -e “\033[32m 绿色字 \033[0m”
echo -e “\033[33m 黄色字 \033[0m”
echo -e “\033[34m 蓝色字 \033[0m”
echo -e “\033[35m 紫色字 \033[0m”
echo -e “\033[36m 天蓝字 \033[0m”
echo -e “\033[37m 白色字 \033[0m”

字背景颜色范围:40—–47

echo -e “\033[40;37m 黑底白字 \033[0m”
echo -e “\033[41;37m 红底白字 \033[0m”
echo -e “\033[42;37m 绿底白字 \033[0m”
echo -e “\033[43;37m 黄底白字 \033[0m”
echo -e “\033[44;37m 蓝底白字 \033[0m”
echo -e “\033[45;37m 紫底白字 \033[0m”
echo -e “\033[46;37m 天蓝底白字 \033[0m”
echo -e “\033[47;30m 白底黑字 \033[0m”

最后面控制选项说明

\33[0m 关闭所有属性
\33[1m 设置高亮度
\33[4m 下划线
\33[5m 闪烁
\33[7m 反显
\33[8m 消隐
\33[30m — \33[37m 设置前景色
\33[40m — \33[47m 设置背景色
\33[nA 光标上移n行
\33[nB 光标下移n行
\33[nC 光标右移n行
\33[nD 光标左移n行
\33[y;xH设置光标位置
\33[2J 清屏
\33[K 清除从光标到行尾的内容
\33[s 保存光标位置
\33[u 恢复光标位置
\33[?25l 隐藏光标
\33[?25h 显示光标
发表在 shell | 标签为 | 留下评论

Jumpserver使用域名访问报错 使用IP+端口没有错误

转载自https://blog.csdn.net/qq_43010883/article/details/99692455。非常感谢原作者,解决了我的问题!

Jumpserver使用域名访问报错 使用IP+端口没有错误

首先我给大家介绍一下我部署Jumpserver环境
docker部署jumpserver使用Nginx进行代理 使用域名访问

我用域名访问jumpserver是正常可以访问的, 但是在web会话那个地方连接到其他服务器的时候 ,有时候web终端连接不上其他服务器 有时候能连接上去 但是使用 IP+端口就没有问题 使用域名+端口也没有问题 这样就排除了docker镜像是没有问题的 这样我就锁定了是Nginx问题 下面是我有问题之前的jumpserver.conf nginx配置文件
我docker映射端口是 5000

server {
listen 80;
server_name jumpserver.xxxxxx.com;
access_log logs/jumpserver.xxxxxx.log;
location / {
root html;
index index.html index.htm;
proxy_pass http://localhost:5000;
proxy_cookie_path / /;
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_redirect off;
}
}

 

经过我两天的查看是原来是coco的session会话有时候连接不上 然后我就在Nginx配置了一条 直接指定socker.io
我在Nginx里面指定了一条 然后重启Nginx就可以正常使用

[root@*** ***]# cat jumpserver.xxxxxxx.conf 
server {
listen 80;
server_name jumpserver.xxxxx.com;
access_log logs/jumpserver.xxxxx.log;

location /socket.io/ {
proxy_pass http://localhost:5000/socket.io/;
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
access_log off;
}

location / {
root html;
index index.html index.htm;
proxy_pass http://localhost:5000;
proxy_cookie_path / /;
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_redirect off;
}
}

发表在 jumpserver | 标签为 | 留下评论

国内公共DNS

中国互联网络中心:1.2.4.8、210.2.4.8、101.226.4.6(电信及移动)、123.125.81.6(联通)

阿里DNS:223.5.5.5、223.6.6.6

googleDNS:8.8.8.8、8.8.4.4

openDNS:
208.67.222.222
208.67.220.220
208.67.222.220
208.67.220.222

另有两个为Family Shield Servers, 可以阻挡含有恶意网站

208.67.220.123 IPv6地址

2620:0:ccc::2

2620:0:ccd::2

纯净 无劫持 无需再忍受被强扭去看广告或粗俗网站之痛苦服务地址为:114.114.114.114 和 114.114.115.115

拦截 钓鱼病毒木马网站 增强网银、证券、购物、游戏、隐私信息安全服务地址为:114.114.114.119 和 114.114.115.119

opener(不稳定):42.120.21.30

发表在 通用 | 标签为 | 留下评论

Nginx超时(timeout)详细配置

转载自:https://juejin.im/post/5b696a24e51d45191e0d3e56

Nginx 处理的每个请求均有相应的超时设置。如果做好这些超时时间的限定,判定超时后资源被释放,用来处理其他的请求,以此提升 Nginx 的性能。

keepalive_timeout

HTTP 是一种无状态协议,客户端向服务器发送一个 TCP 请求,服务端响应完毕后断开连接。

如果客户端向服务器发送多个请求,每个请求都要建立各自独立的连接以传输数据。

HTTP 有一个 KeepAlive 模式,它告诉 webserver 在处理完一个请求后保持这个 TCP 连接的打开状态。若接收到来自客户端的其它请求,服务端会利用这个未被关闭的连接,而不需要再建立一个连接。

KeepAlive 在一段时间内保持打开状态,它们会在这段时间内占用资源。占用过多就会影响性能。

Nginx 使用 keepalive_timeout 来指定 KeepAlive 的超时时间(timeout)。指定每个 TCP 连接最多可以保持多长时间。Nginx 的默认值是 75 秒,有些浏览器最多只保持 60 秒,所以可以设定为 60 秒。若将它设置为 0,就禁止了 keepalive 连接。

# 配置段: http, server, location
keepalive_timeout 60s;

client_body_timeout

指定客户端与服务端建立连接后发送 request body 的超时时间。如果客户端在指定时间内没有发送任何内容,Nginx 返回 HTTP 408(Request Timed Out)。

# 配置段: http, server, location
client_body_timeout 20s;

client_header_timeout

客户端向服务端发送一个完整的 request header 的超时时间。如果客户端在指定时间内没有发送一个完整的 request header,Nginx 返回 HTTP 408(Request Timed Out)。

# 配置段: http, server, location
client_header_timeout 10s;

send_timeout

服务端向客户端传输数据的超时时间。

# 配置段 : http, server, location
send _ timeout 30 s;

客户度连接nginx超时, 建议5s内

接收客户端header超时, 默认60s, 如果60s内没有收到完整的http包头, 返回408

Syntax: client_header_timeout time;
Default:
client_header_timeout 60s;
Context: http, server
Defines a timeout for reading client request header. If a client does not transmit the entire header within this time,
the 408 (Request Time-out) error is returned to the client.

接收客户端body超时, 默认60s, 如果连续的60s内没有收到客户端的1个字节, 返回408

Syntax: client_body_timeout time;
Default:
client_body_timeout 60s;
Context: http, server, location
Defines a timeout for reading client request body. The timeout is set only for a period between two successive read operations, not for the transmission of the whole request body.
If a client does not transmit anything within this time,
the 408 (Request Time-out) error is returned to the client.

keepalive时间,默认75s,通常keepalive_timeout应该比client_body_timeout大

Syntax: keepalive_timeout timeout [header_timeout];
Default:
keepalive_timeout 75s;
Context: http, server, location
The first parameter sets a timeout during which a keep-alive client connection will stay open on the server side. The zero value disables keep-alive client connections.
The optional second parameter sets a value in the “Keep-Alive: timeout=time” response header field. Two parameters may differ.

The “Keep-Alive: timeout=time” header field is recognized by Mozilla and Konqueror. MSIE closes keep-alive connections by itself in about 60 seconds.

可以理解为TCP连接关闭时的SO_LINGER延时设置,默认5s

Syntax: lingering_timeout time;
Default:
lingering_timeout 5s;
Context: http, server, location
When lingering_close is in effect, this directive specifies the maximum waiting time for more client data to arrive. If data are not received during this time,
the connection is closed. Otherwise, the data are read and ignored, and nginx starts waiting for more data again.
The “wait-read-ignore” cycle is repeated, but no longer than specified by the lingering_time directive.

域名解析超时,默认30s

Syntax: resolver_timeout time;
Default:
resolver_timeout 30s;
Context: http, server, location
Sets a timeout for name resolution, for example:
resolver_timeout 5s;

发送数据至客户端超时, 默认60s, 如果连续的60s内客户端没有收到1个字节, 连接关闭

Syntax: send_timeout time;
Default:
send_timeout 60s;
Context: http, server, location
Sets a timeout for transmitting a response to the client. The timeout is set only between two successive write operations,
not for the transmission of the whole response. If the client does not receive anything within this time, the connection is closed.

nginx与upstream server的连接超时时间

Syntax: proxy_connect_timeout time;
Default:
proxy_connect_timeout 60s;
Context: http, server, location
Defines a timeout for establishing a connection with a proxied server. It should be noted that this timeout cannot usually exceed 75 seconds.

nginx接收upstream server数据超时, 默认60s, 如果连续的60s内没有收到1个字节, 连接关闭

Syntax: proxy_read_timeout time;
Default:
proxy_read_timeout 60s;
Context: http, server, location
Defines a timeout for reading a response from the proxied server. The timeout is set only between two successive read operations,
not for the transmission of the whole response. If the proxied server does not transmit anything within this time, the connection is closed.

nginx发送数据至upstream server超时, 默认60s, 如果连续的60s内没有发送1个字节, 连接关闭

Syntax: proxy_send_timeout time;
Default:
proxy_send_timeout 60s;
Context: http, server, location
Sets a timeout for transmitting a request to the proxied server. The timeout is set only between two successive write operations,
not for the transmission of the whole request. If the proxied server does not receive anything within this time, the connection is closed.
发表在 Nginx | 标签为 | 留下评论

停止、删除所有的docker容器和镜像

列出所有的容器 ID
1 docker ps -aq
停止所有的容器
1 docker stop $(docker ps -aq)
删除所有的容器
1 docker rm $(docker ps -aq)
删除所有的镜像
1 docker rmi $(docker images -q)
复制文件
1 docker cp mycontainer:/opt/file.txt /opt/local/
2 docker cp /opt/local/file.txt mycontainer:/opt/

docker 1.13 中增加了 docker system prune的命令,针对container、image可以使用docker container prune、docker image prune命令。

docker image prune –force –all或者docker image prune -f -a` : 删除所有不使用的镜像
docker container prune -f: 删除所有停止的容器

发表在 Docker | 标签为 | 留下评论

Linux 计划任务之crontab

转载自:https://blog.csdn.net/richerg85/article/details/23442411

cron 简介
cron 是 UNIX, SOLARIS,LINUX 下的一个十分有用的工具。通过 cron 脚本能使计划任务定期地在系统后台自动运行。

cron 命令
crontab -e – 编辑该用户的 crontab,当指定 crontab 不存在时新建。
crontab -l – 列出该用户的 crontab。
crontab -r – 删除该用户的 crontab。
crontab -u<用户名称> – 指定要设定 crontab 的用户名称。
Linux Crontab 格式
表格: Crontab 字段与允许的值 (Linux Crontab)

字段 描述 允许的值
分钟 一小时的第几分 0-59
小时 一天的第几小时 0-23
日期 一个月的的第几天 1-31
月份 一年的第几个月 1-12
周几 一周的第几天 0-6
命令 命令 可以被执行的任何命令
cron 实例
1. 特定时间执行
cron 的基本用法是在特定的时间执行一项任务,如下是 6 月 10 上午 8:30 执行 Full backup shell script。 要注意的是时间字段采用的是 24 小时制,如果是下午 8 点,则改写为 20 点

30 08 10 06 * /home/ramesh/full-backup
30 – 第 30 分钟
08 – 早上 8 点
10 – 10 号
06 – 第 6 个月 (6 月)
* – 一周的任何一天
2. 安排多个实例(比如一天执行两次)
下面的增量备份脚本每天执行两次。

每天于 11:00, 16:00 执行,逗号两侧的时间都会执行。

00 11,16 * * * /home/ramesh/bin/incremental-backup
00 – 第 0 分钟 (每小时开时)
11,16 – 早上 11 点与下午 4 点
* – 每天
* – 每个月
* – 一周的任何一天
3. 让任务只在特定时间执行(比如仅当工作日时执行)
下面这个例子是每天 9:00-16:00 检查数据库状态(包括周六)

00 09-18 * * * /home/ramesh/bin/check-db-status
00 – 第 0 分钟 (每小时开时)
09-18 – 9 点, 10 点, 11 点, 12 点, 下午 1 点, 下午 2 点, 下午 3 点, 下午 4 点, 下午 5 点, 下午 6 点
* – 每天
* – 每个月
* – 一周的任何一天
如果只想工作日执行此操作

00 09-18 * * 1-5 /home/ramesh/bin/check-db-status
00 – 第 0 分钟 (每小时开时)
09-18 – 9 点, 10 点, 11 点, 12 点, 下午 1 点, 下午 2 点, 下午 3 点, 下午 4 点, 下午 5 点, 下午 6 点
* – 每天
* – 每个月
1-5 – 周一, 周二, 周三, 周四和周五 (工作日)
4. 如何查看 cron 定时任务
查看当前用户定时任务

ramesh@dev-db$ crontab -l
查看 ROOT 用户定时任务,用 root 登入 su-root,再执行 crontab -l

root@dev-db# crontab -l
no crontab for root
查看其它用户定时任务

root@dev-db# crontab -u sathiya -l
@monthly /home/sathiya/monthly-backup
00 09-18 * * * /home/sathiya/check-db-status
5. 如何编辑 cron 定时任务
ramesh@dev-db$ crontab -e
6. 安排每分钟都执行定时任务
理论情况下,没有每分钟都要执行的 shell,但下面这个例子,让我们更好的了解 crontab

* * * * * 命令
* 代表着所有可能取到的值,除了直接用 * 外,下面的几个例子也较为常用

当指定 */5 在分钟字段,代表每五分钟。
当指定 0-10/2 在分钟字段,代表在前十分钟的每两分钟
上面的例子对于其它四个字段同样试用

7. 安排后台每十分钟执行定时任务
*/10 * * * * /home/ramesh/check-disk-space
有一些特殊的例子,可以用关键字替代上述五个字段– reboot, midnight, yearly, hourly

Table: Cron special keywords and its meaning

Keyword Equivalent
@yearly 0 0 1 1 *
@daily 0 0 * * *
@hourly 0 * * * *
@reboot 重启时运行
8. 每一年的第一分钟执行定时任务(@yearly)
下面的例子将在每一年的 1 月 1 日 0:00 执行

@yearly /home/ramesh/red-hat/bin/annual-maintenance
9. 每月执行定时任务(@mothly)
下面的例子将在每月 1 日 0:00 执行

@monthly /home/ramesh/suse/bin/tape-backup
10. 每天执行定时任务(@daily)
下面的例子将在每天 0:00 执行

@daily /home/ramesh/arch-linux/bin/cleanup-logs “day started”
11. 每次重启时执行定时任务(@reboot)
@reboot CMD
12. 如何用 mail 关键字禁止/重定向 cron 的邮件
默认情况下,crontab 将向布置定时任务的管理员发送邮件,如果想重定向此用户,添加并更新 MAIL

ramesh@dev-db$ crontab -l
MAIL=”ramesh”

@yearly /home/ramesh/annual-maintenance
*/10 * * * * /home/ramesh/check-disk-space
如果不想任何人接收,则直接将 MAIL 置空

13. 如何系秒每执行一个定时任务
无法安排每秒执行,因为最小处理单元是分钟,另一方面,没有什么理由让我们每秒都执行一任务

14. cron 中的 PATH 变量
上面的例子都是用绝对的路径

如果你想用相对的路径,设置环境变量可以在 crontab 增加

ramesh@dev-db$ crontab -l

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/home/ramesh

@yearly annual-maintenance
*/10 * * * * check-disk-space
15. 从 cron 文件中定义 cron 任务
除了直接编辑外,你也可以先在一个文件中编辑好任务,再导入

ramesh@dev-db$ crontab -l
no crontab for ramesh

$ cat cron-file.txt
@yearly /home/ramesh/annual-maintenance
*/10 * * * * /home/ramesh/check-disk-space

ramesh@dev-db$ crontab cron-file.txt

ramesh@dev-db$ crontab -l
@yearly /home/ramesh/annual-maintenance

*/10 * * * * /home/ramesh/check-disk-space
应用时要注意,此操作会删除原有的cron任务

参考自:http://justjavac.com/other/2013/09/22/linux-scheduled-task-crontab.html
————————————————
版权声明:本文为CSDN博主「richerg85」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/richerg85/article/details/23442411

发表在 LinuxBasic | 标签为 | 留下评论