SecureCRT设置超时不自动断开

SecureCRT连接时经常会遇到因长时间没有与服务器交互而连接断开的问题,调整下Session Options中的配置即可不会断开:
设置步骤如下: Options->Session Options->Terminal->Anti-idle->勾选Send protocol NO-OP :
Send string: n every 300 seconds

在选项后面有个时间的配置,默认是60秒,可改为其他合适时间,只要小于自动断开连接的时限就可以了。
seesion.png

GreenPlum集群安装时ntpd not detected on machine问题解决

安装GreenPlum的时候需要注意时间服务器保持一致,在gpcheck时会提示:

ntpd not detected on machine

解决方法:
安装ntpd服务:各节点都需安装

yum install ntp -y

假设以某个服务器上的时间为基准时间,该服务器的IP为x.x.x.x。
编辑文件vi /etc/ntp.conf,在末尾追加信息(三种节点添加的东西不一样):

# Master 节点
server x.x.x.x

# Master Standby 节点
server mdw perfer
server x.x.x.x

# Segment 节点
server mdw perfer
server mdw1 perfer

# mdw为Master,mdw1为Master Standby

设置ntpd服务开机启动,在/etc/rc.local中添加如下信息:

/etc/init.d/ntpd start

如果只是简单的试验环境,并没有时间服务器,则只需要从Master上同步时间即可;

pkill按终端号踢出用户

当作于管理进程时,pkill 命令和 killall 命令的用法相同,都是通过进程名杀死一类进程,该命令的基本格式如下:
[root@localhost ~]# pkill [信号] 进程名
表 1 pkill 命令常用信号及其含义
信号编号 信号名 含义
0 EXIT 程序退出时收到该信息。
1 HUP 挂掉电话线或终端连接的挂起信号,这个信号也会造成某些进程在没有终止的情况下重新初始化。
2 INT 表示结束进程,但并不是强制性的,常用的 "Ctrl+C" 组合键发出就是一个 kill -2 的信号。
3 QUIT 退出。
9 KILL 杀死进程,即强制结束进程。
11 SEGV 段错误。
15 TERM 正常结束进程,是 kill 命令的默认信号。
pkill命令踢出登陆用户

pkill [-t 终端号] 进程名
pkill -kill -t tty
或者pkill -9 -t tty

可以先用w命令查看当前在线用户,然后强制下线;

Grafana参数配置文件详解

grafana_screenshot1.png
grafana安装后目录的说明:

#主配置文件
/etc/grafana/grafana.ini
#数据文件
/var/lib/grafana
#home目录
/usr/share/grafana
#日志目录
/var/log/grafana
#插件目录
/var/lib/grafana/plugins
#自定义一些精细化配置的文件夹
/etc/grafana/provisioning

grafana的默认配置文件在/etc/grafana,目录下文件结构如下:

├── config.monitoring
├── grafana.ini
├── ldap.toml
└── provisioning
    ├── dashboards
    │   ├── Ceph\ -\ Cluster-1544005047598.json
    │   ├── dashboard.yml
    │   └── Node\ Exporter\ Full-1544005083113.json
    └── datasources
        └── datasource.yml

grafana.ini配置文件说明:

app_mode:应用名称,默认是production

[path]
data:一个grafana用来存储sqlite3、临时文件、回话的地址路径
logs:grafana存储logs的路径

[server]
http_addr:监听的ip地址,,默认是0.0.0.0
http_port:监听的端口,默认是3000
protocol:http或者https,,默认是http
domain:这个设置是root_url的一部分,当你通过浏览器访问grafana时的公开的domian名称,默认是localhost
enforce_domain:如果主机的header不匹配domian,则跳转到一个正确的domain上,默认是false
root_url:这是一个web上访问grafana的全路径url,默认是%(protocol)s://%(domain)s:%(http_port)s/
router_logging:是否记录web请求日志,默认是false
cert_file:如果使用https则需要设置
cert_key:如果使用https则需要设置

[database]
grafana默认需要使用数据库存储用户和dashboard信息,默认使用sqlite3来存储,你也可以换成其他数据库
type:可以是mysql、postgres、sqlite3,默认是sqlite3
path:只是sqlite3需要,定义sqlite3的存储路径
host:只是mysql、postgres需要,默认是127.0.0.1:3306
name:grafana的数据库名称,默认是grafana
user:连接数据库的用户
password:数据库用户的密码
ssl_mode:只是postgres使用


[security]
admin_user:grafana默认的admin用户,默认是admin
admin_password:grafana admin的默认密码,默认是admin
login_remember_days:多少天内保持登录状态
secret_key:保持登录状态的签名
disable_gravatar:


[users]
allow_sign_up:是否允许普通用户登录,如果设置为false,则禁止用户登录,默认是true,则admin可以创建用户,并登录grafana
allow_org_create:如果设置为false,则禁止用户创建新组织,默认是true
auto_assign_org:当设置为true的时候,会自动的把新增用户增加到id为1的组织中,当设置为false的时候,新建用户的时候会新增一个组织
auto_assign_org_role:新建用户附加的规则,默认是Viewer,还可以是Admin、Editor


[auth.anonymous]
enabled:设置为true,则开启允许匿名访问,默认是false
org_name:为匿名用户设置组织名称
org_role:为匿名用户设置的访问规则,默认是Viewer


[auth.github]
针对github项目的,很明显
enabled = false
allow_sign_up = false
client_id = some_id
client_secret = some_secret
scopes = user:email
auth_url = https://github.com/login/oauth/authorize
token_url = https://github.com/login/oauth/access_token
api_url = https://api.github.com/user
team_ids =
allowed_domains =
allowed_organizations =


[auth.google]
针对google app的
enabled = false
allow_sign_up = false
client_id = some_client_id
client_secret = some_client_secret
scopes = https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email
auth_url = https://accounts.google.com/o/oauth2/auth
token_url = https://accounts.google.com/o/oauth2/token
api_url = https://www.googleapis.com/oauth2/v1/userinfo
allowed_domains =


[auth.basic]
enabled:当设置为true,则http api开启基本认证


[auth.ldap]
enabled:设置为true则开启LDAP认证,默认是false
config_file:如果开启LDAP,指定LDAP的配置文件/etc/grafana/ldap.toml


[auth.proxy]
允许你在一个HTTP反向代理上进行认证设置
enabled:默认是false
header_name:默认是X-WEBAUTH-USER
header_property:默认是个名称username
auto_sign_up:默认是true。开启自动注册,如果用户在grafana DB中不存在

[analytics]
reporting_enabled:如果设置为true,则会发送匿名使用分析到stats.grafana.org,主要用于跟踪允许实例、版本、dashboard、错误统计。默认是true
google_analytics_ua_id:使用GA进行分析,填写你的GA ID即可


[dashboards.json]
如果你有一个系统自动产生json格式的dashboard,则可以开启这个特性试试
enabled:默认是false
path:一个全路径用来包含你的json dashboard,默认是/var/lib/grafana/dashboards


[session]
provider:默认是file,值还可以是memory、mysql、postgres
provider_config:这个值的配置由provider的设置来确定,如果provider是file,则是data/xxxx路径类型,如果provider是mysql,则是user:password@tcp(127.0.0.1:3306)/database_name,如果provider是postgres,则是user=a password=b host=localhost port=5432 dbname=c sslmode=disable
cookie_name:grafana的cookie名称
cookie_secure:如果设置为true,则grafana依赖https,默认是false
session_life_time:session过期时间,默认是86400秒,24小时


以下是官方文档没有,配置文件中有的
[smtp]
enabled = false
host = localhost:25
user =
password =
cert_file =
key_file =
skip_verify = false
from_address = admin@grafana.localhost

[emails]
welcome_email_on_sign_up = false
templates_pattern = emails/*.html


[log]
mode:可以是console、file,默认是console、file,也可以设置多个,用逗号隔开
buffer_len:channel的buffer长度,默认是10000
level:可以是"Trace", "Debug", "Info", "Warn", "Error", "Critical",默认是info

[log.console]
level:设置级别

[log.file]
level:设置级别
log_rotate:是否开启自动轮转
max_lines:单个日志文件的最大行数,默认是1000000
max_lines_shift:单个日志文件的最大大小,默认是28,表示256MB
daily_rotate:每天是否进行日志轮转,默认是true
max_days:日志过期时间,默认是7,7天后删除

via:https://www.li-rui.top/2018/12/12/monitor/grafana%E4%BD%BF%E7%94%A8/
http://www.51niux.com/?id=237

[warn] 1539#0: 65535 worker_connections exceed open file resource limit: 1024报错解决

Cenos7.x系统中已经设置了ulimit最大值为65535,reload nginx的时候发现error.log里面有一行报错:

2019/10/28 16:09:27 [notice] 32473#0: signal process started
2019/10/28 16:09:27 [notice] 1539#0: using the "epoll" event method
2019/10/28 16:09:27 [warn] 1539#0: 65535 worker_connections exceed open file resource limit: 1024
2019/10/28 16:09:27 [notice] 1539#0: start worker processes
2019/10/28 16:09:27 [notice] 1539#0: start worker process 32474
2019/10/28 16:09:27 [notice] 1539#0: start worker process 32475

解决方法如下:
在nginx.conf中增加:

worker_rlimit_nofile 65535; 

nginx-ulimit.png
worker_rlimit_nofile参数说明:

worker_rlimit_nofile 一个nginx进程打开的最多文件描述符数目  
理论值应该是系统最多打开文件数(系统的值ulimit -n)与nginx进程数相除,但是nginx分配请求并不均匀,所以建议与ulimit -n的值保持一致。

最后reload nginx,报错消失问题解决;

Zabbix Web场景监控小记

页面或接口直接请问失败或打不开监控项表达式:主机端口宕掉时会会触发·

{sso-git-zull-c:web.test.fail[Zuul网关接口_134].last()}<>0   #对应Failed step of scenario "Zuul网关接口_134"

页面或接口请求状态非200表达式:

{sso-git-zull-c:web.test.rspcode[Zuul网关接口_134,zuul网关_134].last()}<>200  #对应Response code for step "zuul网关_134" of scenario "Zuul网关接口_134"

页面或接口请求缓慢表达式:

{sso-git-zull-c:web.test.time[Zuul网关接口_134,zuul网关_134,resp].last()}>10 #对应Response time for step "zuul网关_134" of scenario "Zuul网关接口_134".

/var/log/message大量systemd: Started Session 1120 of user root日志解决

rsyslog.png
查看/var/log/message日志发现大量systemd: Started Session 4850 of user root.
log如下:

Oct 17 13:40:01 monitor-test systemd: Started Session 4850 of user root.
Oct 17 13:50:01 monitor-test systemd: Started Session 4851 of user root.
Oct 17 14:00:01 monitor-test systemd: Started Session 4852 of user root.
Oct 17 14:00:01 monitor-test systemd: Started Session 4853 of user root.
Oct 17 14:01:01 monitor-test systemd: Started Session 4854 of user root.
Oct 17 14:10:01 monitor-test systemd: Started Session 4855 of user root.
Oct 17 14:20:01 monitor-test systemd: Started Session 4856 of user root.
Oct 17 14:30:01 monitor-test systemd: Started Session 4857 of user root.
Oct 17 14:30:01 monitor-test systemd: Started Session 4858 of user root.
Oct 17 14:40:01 monitor-test systemd: Started Session 4859 of user root.
Oct 17 14:50:01 monitor-test systemd: Started Session 4860 of user root.
Oct 17 15:00:01 monitor-test systemd: Started Session 4861 of user root.
Oct 17 15:00:01 monitor-test systemd: Started Session 4862 of user root.
Oct 17 15:01:01 monitor-test systemd: Started Session 4863 of user root.
Oct 17 15:10:01 monitor-test systemd: Started Session 4864 of user root.
Oct 17 15:20:01 monitor-test systemd: Started Session 4865 of user root.
Oct 17 15:30:01 monitor-test systemd: Started Session 4866 of user root.
Oct 17 15:30:01 monitor-test systemd: Started Session 4867 of user root.
Oct 17 15:40:01 monitor-test systemd: Started Session 4868 of user root.
Oct 17 15:50:01 monitor-test systemd: Started Session 4869 of user root.
Oct 17 16:00:01 monitor-test systemd: Started Session 4870 of user root.
Oct 17 16:00:01 monitor-test systemd: Started Session 4871 of user root.
Oct 17 16:01:01 monitor-test systemd: Started Session 4872 of user root.
Oct 17 16:10:01 monitor-test systemd: Started Session 4873 of user root.
Oct 17 16:20:01 monitor-test systemd: Started Session 4874 of user root.
Oct 17 16:30:01 monitor-test systemd: Started Session 4876 of user root.
Oct 17 16:30:01 monitor-test systemd: Started Session 4875 of user root.
Oct 17 16:40:01 monitor-test systemd: Started Session 4877 of user root.

redhat官方回复这是正常的,每个用户登录后都能看到,如果要过滤并禁止掉该消息,用如下方法:

echo 'if $programname == "systemd" and ($msg contains "Starting Session" or $msg contains "Started Session" or $msg contains "Created slice" or $msg contains "Starting user-" or $msg contains "Starting User Slice of" or $msg contains "Removed session" or $msg contains "Removed slice User Slice of" or $msg contains "Stopping User Slice of") then stop' >/etc/rsyslog.d/ignore-systemd-session-slice.conf

最后重启rsyslog服务即可:

systemctl restart rsyslog

redhat官方说明:https://access.redhat.com/solutions/1564823

ERROR 1786 (HY000): Statement violates GTID consistency: CREATE TABLE ... SELECT.问题解决

ogp-mysql57-gtid-replication-b.png
MySQL使用Create table select的时候报错如下:

root@monitor-db 19:35:25 [test]>create table a3 select * from a2 ;
ERROR 1786 (HY000): Statement violates GTID consistency: CREATE TABLE ... SELECT.

问题分析:
MySQL开启gtid以后就不能使用了,MySQL只允许能够保障事务安全,并且能够被日志记录的SQL语句被执行,像create table … select 和 create temporarytable语句,以及同时更新事务表和非事务表的SQL语句或事务都不允许执行

root@monitor-db 19:35:12 [test]>show global variables like '%gtid_mode%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| gtid_mode     | ON    |
+---------------+-------+
1 row in set (0.00 sec)

如业务需要,可以在线关闭掉gtid,执行如下SQL关闭gtid:

set global gtid_mode='ON_PERMISSIVE';

set global gtid_mode='OFF_PERMISSIVE';

SET @@GLOBAL.ENFORCE_GTID_CONSISTENCY = OFF;

set global gtid_mode='OFF';

show global variables like '%gtid_mode%';

查询执行结果:

root@monitor-db 19:21:31 [test]>show global variables like '%gtid_mode%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| gtid_mode     | OFF   |
+---------------+-------+
1 row in set (0.00 sec)

再次创建:

root@monitor-db 19:32:46 [test]>desc a2;
+-----------------+------------------+------+-----+---------+-------+
| Field           | Type             | Null | Key | Default | Extra |
+-----------------+------------------+------+-----+---------+-------+
| id              | int(10) unsigned | NO   |     | 0       |       |
| title           | varchar(100)     | NO   |     | NULL    |       |
| author          | varchar(40)      | NO   |     | NULL    |       |
| submission_date | date             | YES  |     | NULL    |       |
+-----------------+------------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

root@monitor-db 19:32:51 [test]>create table a3 select * from a2 ;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

root@monitor-db 19:32:57 [test]>desc a3;
+-----------------+------------------+------+-----+---------+-------+
| Field           | Type             | Null | Key | Default | Extra |
+-----------------+------------------+------+-----+---------+-------+
| id              | int(10) unsigned | NO   |     | 0       |       |
| title           | varchar(100)     | NO   |     | NULL    |       |
| author          | varchar(40)      | NO   |     | NULL    |       |
| submission_date | date             | YES  |     | NULL    |       |
+-----------------+------------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

已经OK;
在线打开GTID:

root@monitor-db 19:41:31 [test]>set global gtid_mode='OFF_PERMISSIVE';
Query OK, 0 rows affected (0.00 sec)

root@monitor-db 19:44:14 [test]>
root@monitor-db 19:44:14 [test]>set global gtid_mode='ON_PERMISSIVE';
Query OK, 0 rows affected (0.00 sec)

root@monitor-db 19:44:14 [test]>
root@monitor-db 19:44:14 [test]>SET @@GLOBAL.ENFORCE_GTID_CONSISTENCY = ON;
Query OK, 0 rows affected (0.00 sec)

root@monitor-db 19:44:14 [test]>
root@monitor-db 19:44:14 [test]>set global gtid_mode='ON';
Query OK, 0 rows affected (0.01 sec)

root@monitor-db 19:44:14 [test]>
root@monitor-db 19:44:14 [test]>show global variables like '%gtid_mode%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| gtid_mode     | ON    |
+---------------+-------+
1 row in set (0.00 sec)

打开ok,MySQL5.7开启/关闭GTID,不用重启服务很方便;

CentOS7.x 设置系统时间

硬件时钟和系统时钟
(1) 硬件时钟
RTC(Real-Time Clock)或CMOS时钟,一般在主板上靠电池供电,服务器断电后也会继续运行。仅保存日期时间数值,无法保存时区和夏令时设置。

(2) 系统时钟
一般在服务器启动时复制RTC时间,之后独立运行,保存了时间、时区和夏令时设置。

CentOS7开始,使用timedatectl设置日期时间:
(1) 读取时间

timedatectl //等同于 timedatectl status

(2) 设置时间

timedatectl set-time "YYYY-MM-DD HH:MM:SS"

(3) 列出所有时区

timedatectl list-timezones

(4) 设置时区

timedatectl set-timezone Asia/Shanghai

(5) 是否NTP服务器同步

timedatectl set-ntp yes //yes或者no

(6) 将硬件时钟调整为与本地时钟一致

timedatectl set-local-rtc 1
hwclock --systohc --localtime //与上面命令效果一致

注意: 硬件时钟默认使用UTC时间,因为硬件时钟不能保存时区和夏令时调整,修改后就无法从硬件时钟中读取出准确标准时间,因此不建议修改。修改后系统会出现下面的警告。

GMT、UTC、CST、DST 时间

(1) UTC

整个地球分为二十四时区,每个时区都有自己的本地时间。在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC, Universal Time Coordinated)。

(2) GMT

格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。(UTC与GMT时间基本相同,本文中不做区分)

(3) CST

中国标准时间 (China Standard Time)

(4) DST

夏令时(Daylight Saving Time) 指在夏天太阳升起的比较早时,将时钟拨快一小时,以提早日光的使用。(中国不使用)

GMT + 8 = UTC + 8 = CST

zabbix3.x中文图片乱码终极解决

zabbix-logo.png
Zabbix乱码是由于默认使用DejaVuSan.ttf字体,该字体不支持中文,切换语言成中文Zh_cn后,在图表上中文出现乱码,如下图:
lm.png

解决zabbix乱码方法如下:
找到本地C:WindowsFontsmsyh.ttf(微软雅黑)上传到服务器zabbix网站目录fonts目录下
修改includedefines.inc.php中的DejaVuSans为msyh

define('ZBX_GRAPH_FONT_NAME',        'msyh');
define('ZBX_FONT_NAME', 'msyh');

再次刷新即可正常;
tb.png

如果还乱码,就需要检查数据库编码是否是utf8编码了

show create database zabbixdb; #查看数据库创建编码
root@monitor-db 09:23:05 [(none)]>show create database zabbixdb;
+----------+-------------------------------------------------------------------+
| Database | Create Database                                                   |
+----------+-------------------------------------------------------------------+
| zabbixdb | CREATE DATABASE `zabbixdb` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+-------------------------------------------------------------------+
1 row in set (0.00 sec)

若数据库是utf8编码,但还乱码,就需要继续盘查,php编译参数中是否编译了jpeg、png、freetype等组件,
编译顺序如下:

安装libmcrypt:
cd /opt
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure && make && make install

安装 jpeg6

 mkdir /usr/local/jpeg6
 mkdir /usr/local/jpeg6/bin
 mkdir /usr/local/jpeg6/lib
 mkdir /usr/local/jpeg6/include
 mkdir /usr/local/jpeg6/man
 mkdir /usr/local/jpeg6/man/man1
cd /opt
tar zxf jpegsrc.v6b.tar.gz
cd jpeg-6b
cp /usr/share/libtool/config/config.sub .
cp /usr/share/libtool/config/config.guess .
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
make && make install

安装png

cd /opt
tar zxvf libpng-1.6.10.tar.gz
./configure --prefix=/usr/local/png --enable-shared
make && make install

安装freetype

cd /opt
tar zxvf freetype-2.5.3.tar.gz
cd freetype-2.5.3
./configure --prefix=/usr/local/freetype --enable-shared
make && make install

最后编译php参数如下:

./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql --with-mysqli=/usr/bin/mysql_config --with-mysql-sock=/var/lib/mysql/mysql.sock --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir=/usr/local/jpeg6 --with-png-dir=/usr/local/png --with-freetype-dir=/usr/local/freetype --with-mcrypt=/usr/local/libmcrypt --enable-maintainer-zts --with-ldap=shared --without-gdbm 
make -j 8
make install

CentOS7.x 快速申请部署Let’s Encrypt 证书

Let's Encrypt作为一个公共且免费SSL的项目逐渐被广大用户传播和使用,是由Mozilla、Cisco、Akamai、IdenTrust、EFF等组织人员发起,主要的目的也是为了推进网站从HTTP向HTTPS过度的进程,目前已经有越来越多的商家加入和赞助支持。
https.jpg
申请步骤如下:

#安装git及其他用到的包
yum install git zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel -y

#获取letsencrypt
git clone https://github.com/letsencrypt/letsencrypt

#进入letsencrypt目录
cd letsencrypt

#生成证书
./letsencrypt-auto certonly --standalone --email ice@mail.com -d unixso.com -d www.unixso.com

#证书位置
/etc/letsencrypt/live/unixso.com
cert.pem - Apache服务器端证书
chain.pem - Apache根证书和中继证书
fullchain.pem - Nginx所需要ssl_certificate文件
privkey.pem - 安全证书KEY文件

#Nginx环境中,对应的ssl_certificate和ssl_certificate_key路径设置成的2个文件就可以。

附nginx ssl参数配置文件其他省略:

ssl_certificate cert/unixso.com.pem;
ssl_certificate_key cert/unixso.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
        ssl_session_cache builtin:1000 shared:SSL:10m;

Let's Encrypt证书有效期90天的,需要定时更新续期:

./letsencrypt-auto certonly --renew-by-default --email ice@mail.com -d unixso.com -d www.unixso.com

或者加入crontab定时任务执行即可;

0 0 1 */2 *  /data/letsencrypt/up.sh

每两个月的1日0点执行up.sh更新证书续期;
如果报错"Problem binding to port 80: Could not bind to IPv4 or IPv6."
停掉nginx进程重新执行即可;

蓝天

天很蓝,云很低,这样的天气不错,适合出去转转;

IMG_20190916_082932.jpg

微信小程序开发-js判断是否为空

1、判断undefined:

var tmp = undefined; 
if (typeof(tmp) == "undefined"){ 
   console.log("undefined"); 
}

说明:typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"
2、判断null:

var tmp = 0/0; 
if (isNaN(tmp) ){ 
   console.log("NaN"); 
}

3、判断NaN:

var tmp = 0/0; 
if (isNaN(tmp) ){ 
   console.log("NaN"); 
}

说明:NaN 表示非法,如果把 NaN 与任何值(包括其自身)相比得到的结果均是 false,所以要判断某个值是否是 NaN,不能使用 == 或 === 运算符。

提示:isNaN() 函数通常用于检测 parseFloat() 和 parseInt() 的结果,以判断它们表示的是否是合法的数字。当然也可以用 isNaN() 函数来检测算数错误,比如用 0 作除数的情况。
4.判断undefined和null:

var tmp = undefined; 
if (tmp== undefined) 
{ 
   console.log("null or undefined"); 
}
var tmp = undefined; 
if (tmp== null) 
{ 
   console.log("null or undefined"); 
}

说明:null==undefined
5、判断undefined、null与NaN:

var tmp = null; 
if (!tmp) 
{ 
   console.log("null or undefined or NaN"); 
}

提示:一般不那么区分就使用这个足够,举例说明:

    if (typeof (username) == '' || typeof (username) == 'undefined') {
      wx.showModal({
        title: "系统提示",
        content: "资产管理员账号不能为空!",
        showCancel: false
      })
    }else if (typeof (pwd) == '' || typeof (pwd) == 'undefined') {
      wx.showModal({
        title: "系统提示",
        content: "资产管理员密码不能为空!",
        showCancel: false
        
      })
    } else {
      console.log("账号:" + username + "密码:" + pwd)
}
 },

Oracle11g查询数据量最大的表及存储空间大小

数据量最大的表:

select * from user_tables t where t.NUM_ROWS is not  null  order by t.NUM_ROWS  desc

table.png

存储空间可以用如下语句查:

select tablespace_name, sum(bytes) / 1024 / 1024 as MB from dba_data_files group by tablespace_name;

tablespace.png

查询最大表记录:

select count(1) from LBPM_RT_NODEHANDLER_DEFINE;

select_max_row.png
最大记录数量两千三百多万;

秋天到了

秋天到了,河边的花已是晚期了,早晚外面凉快多了,但是室内还是那么闷热;

立秋以后,北方已经秋高气爽了,魔都估计得到十月份才能彻底凉快下来;

秋天是个收获的季节,不过前提是得种下才有收获;

---阅读剩余部分---

MySQL网络超时错误Got timeout reading communication packets的解决方法

MySQL大量报错Got timeout reading communication packets,error显示日志如下:

2018-11-14T23:27:01.130760Z 2876756 [Note] Aborted connection 2876756 to db: 'zabbix_db' user: 'zabbix_u' host: '192.168.255.209' (Got timeout reading communication packets)
2018-11-14T23:27:03.437908Z 2874970 [Note] Aborted connection 2874970 to db: 'zabbix_db' user: 'zabbix_u' host: '192.168.255.209' (Got timeout reading communication packets)

当前MySQL主要timeout相关的参数如下:

show session variables like '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 10       |
| innodb_rollback_on_timeout  | ON       |
| interactive_timeout         | 60       |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 60      |
| net_write_timeout           | 30      |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| wait_timeout                | 900      |
+-----------------------------+----------+
13 rows in set (0.01 sec)

connect_timeout:默认为10S
wait_timeout:默认是8小时,即28800秒
interactive_timeout:默认是8小时,即28800秒
net_read_timeout:默认是30S
net_write_timeout:默认是60S
如果是认证过程中超时,不管是读还是,都是 connect_timeout;
对于读网络超时,一般是 wait_timeout/interactive_timeout,基本不会是 net_read_timeout(特例是业务用到 LOAD DATA LOCAL FILE);
对于写网络超时,都是 net_write_timeout。
解决方法如下:

set global interactive_timeout=900;
set global net_read_timeout=900;
set global net_write_timeout=900;

再次tail日志,已经无该信息报错了,可以把以上参数加入到my.cnf里面,900根据实际场景设置;

参考文档:
http://mysql.taobao.org/monthly/2017/05/04/
http://cenalulu.github.io/mysql/mysql-timeout/
https://www.cnblogs.com/xiaoboluo768/p/6222862.html

CentOS7启用ena网络增强模块

CentOS7.4.1708及以上版本内核中已经集成了亚马逊的ena驱动程序已被加进内核,参考https://wiki.centos.org/zh/Manuals/ReleaseNotes/CentOS7.1708 官方页面;
maxresdefault.jpg
如果是7.4以上版本直接使用下面的方法即可加载ena模块:

[root@monitor ~]# yum update -y
[root@monitor ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

[root@monitor ~]# modinfo ena
filename:       /lib/modules/3.10.0-957.12.2.el7.x86_64/kernel/drivers/net/ethernet/amazon/ena/ena.ko.xz
version:        1.5.0K
license:        GPL
description:    Elastic Network Adapter (ENA)
author:         Amazon.com, Inc. or its affiliates
retpoline:      Y
rhelversion:    7.6
srcversion:     1B9931F07C26733BA8D4F94
alias:          pci:v00001D0Fd0000EC21sv*sd*bc*sc*i*
alias:          pci:v00001D0Fd0000EC20sv*sd*bc*sc*i*
alias:          pci:v00001D0Fd00001EC2sv*sd*bc*sc*i*
alias:          pci:v00001D0Fd00000EC2sv*sd*bc*sc*i*
depends:
intree:         Y
vermagic:       3.10.0-957.12.2.el7.x86_64 SMP mod_unload modversions
signer:         CentOS Linux kernel signing key
sig_key:        8D:E6:4F:B5:96:9B:55:7E:DC:7F:03:2E:EA:BC:BE:4F:37:17:7F:4E
sig_hashalgo:   sha256
parm:           debug:Debug level (0=none,...,16=all) (int)

查看内核版本:

[root@monitor ~]# uname -r
3.10.0-957.12.2.el7.x86_64

添加模块:

dracut -f --add-drivers nvme /boot/initramfs-$(uname -r).img $(uname -r)

查看内核镜像内容并过滤nvme:

[root@monitor ~]# lsinitrd /boot/initramfs-3.10.0-957.12.2.el7.x86_64.img | grep -i nvme
Arguments: -f --add-drivers 'nvme'
drwxr-xr-x   3 root     root            0 Aug 14 19:43 usr/lib/modules/3.10.0-957.12.2.el7.x86_64/kernel/drivers/nvme
drwxr-xr-x   2 root     root            0 Aug 14 19:43 usr/lib/modules/3.10.0-957.12.2.el7.x86_64/kernel/drivers/nvme/host
-rw-r--r--   1 root     root        28480 May 15 05:48 usr/lib/modules/3.10.0-957.12.2.el7.x86_64/kernel/drivers/nvme/host/nvme-core.ko.xz
-rw-r--r--   1 root     root        16908 May 15 05:48 usr/lib/modules/3.10.0-957.12.2.el7.x86_64/kernel/drivers/nvme/host/nvme.ko.xz

CentOS7.4以下版本需要重新安装,操作步骤如下:
1、先更新升级Linux内核:

yum --enablerepo=extras install epel-release
yum -y install patch dkms kernel-devel perl
yum update
yum --enablerepo=elrepo-kernel install kernel-lt -y

vi /etc/default/grub
将GRUB_DEFAULT=saved 改成 GRUB_DEFAULT=0
grub2-mkconfig -o /boot/grub2/grub.cfg 
reboot 重启后生效

2、安装ena驱动

cd /opt
curl -o ena_linux_2.1.1.tar.gz https://codeload.github.com/amzn/amzn-drivers/tar.gz/ena_linux_2.1.1
tar zxvf ena_linux_2.1.1.tar.gz
mv amzn-drivers-ena_linux_2.1.1 /usr/src/ena-2.1.1
cat <<EOF > /usr/src/ena-2.1.1/dkms.conf
PACKAGE_NAME="ena"
PACKAGE_VERSION="2.1.1"
AUTOINSTALL="yes"
REMAKE_INITRD="yes"
BUILT_MODULE_LOCATION[0]="kernel/linux/ena"
BUILT_MODULE_NAME[0]="ena"
DEST_MODULE_LOCATION[0]="/updates"
DEST_MODULE_NAME[0]="ena"
CLEAN="cd kernel/linux/ena; make clean"
MAKE="cd kernel/linux/ena; make BUILD_KERNEL=\${kernelver}"
EOF

dkms add -m ena -v 2.1.1
dkms build -m ena -v 2.1.1
dkms install -m ena -v 2.1.1

dracut -f --add-drivers ena

#安装完毕查看
[root@devops ~]# modinfo ena
filename:       /lib/modules/3.10.0-957.27.2.el7.x86_64/extra/ena.ko.xz
version:        2.1.1g
license:        GPL
description:    Elastic Network Adapter (ENA)
author:         Amazon.com, Inc. or its affiliates
retpoline:      Y
rhelversion:    7.6
srcversion:     F342F1BEE707726508E3DF8
alias:          pci:v00001D0Fd0000EC21sv*sd*bc*sc*i*
alias:          pci:v00001D0Fd0000EC20sv*sd*bc*sc*i*
alias:          pci:v00001D0Fd00001EC2sv*sd*bc*sc*i*
alias:          pci:v00001D0Fd00000EC2sv*sd*bc*sc*i*
depends:
vermagic:       3.10.0-957.27.2.el7.x86_64 SMP mod_unload modversions
parm:           debug:Debug level (0=none,...,16=all) (int)
parm:           rx_queue_size:Rx queue size. The size should be a power of 2. Max value is 8K
 (int)
parm:           force_large_llq_header:Increases maximum supported header size in LLQ mode to 224 bytes, while reducing the maximum TX queue size by half.
 (int)

3、添加驱动

查看内核版本:uname -r

添加模块:dracut -f --add-drivers nvme /boot/initramfs-$(uname -r).img $(uname -r)

查看内核镜像内容并过滤nvme:
lsinitrd /boot/initramfs-3.10.0-957.1.3.el7.x86_64.img | grep -i nvme

4、最后关机,并启用ena模块

aws ec2 modify-instance-attribute --instance-id i-07xxxxxxxxxxxxx --ena-support  #使i-07xxxxxxxxxxxxx虚机支持ena
aws ec2 describe-instances --instance-id i-07xxxxxxxxxxxxx --query "Reservations[].Instances[].EnaSupport"  #查询是否启用了ena模块

最后启动虚机即可生效,查看ena信息:

[root@monitor ~]# modinfo ena
filename:       /lib/modules/3.10.0-957.27.2.el7.x86_64/extra/ena.ko.xz
version:        2.1.1g
license:        GPL
description:    Elastic Network Adapter (ENA)
author:         Amazon.com, Inc. or its affiliates
retpoline:      Y
rhelversion:    7.6
srcversion:     F342F1BEE707726508E3DF8
alias:          pci:v00001D0Fd0000EC21sv*sd*bc*sc*i*
alias:          pci:v00001D0Fd0000EC20sv*sd*bc*sc*i*
alias:          pci:v00001D0Fd00001EC2sv*sd*bc*sc*i*
alias:          pci:v00001D0Fd00000EC2sv*sd*bc*sc*i*
depends:        
vermagic:       3.10.0-957.27.2.el7.x86_64 SMP mod_unload modversions 
parm:           debug:Debug level (0=none,...,16=all) (int)
parm:           rx_queue_size:Rx queue size. The size should be a power of 2. Max value is 8K
 (int)
parm:           force_large_llq_header:Increases maximum supported header size in LLQ mode to 224 bytes, while reducing the maximum TX queue size by half.
 (int)

[root@monitor ~]# ethtool -i ens5
driver: ena
version: 2.1.1g
firmware-version: 
expansion-rom-version: 
bus-info: 0000:00:05.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no

via:https://gist.github.com/Ray33/ba189a729d81babc99d7cef0fb6fbcd8

MySQL使用存储过程插入100万条记录

业务上为了测试DB写入性能,需测试大量数据写入速度,数据库部署在aws上,4核8G内存100G硬盘,MySQL5.7.27
mysql.png

--创建测试数据库
create database a1 default charset utf8mb4;
--创建测试表
CREATE TABLE `test110` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `comp` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `create_time` datetime DEFAULT NULL,
  `cid` int(11) DEFAULT NULL,
  `aid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--创建插入存储过程
DELIMITER $$
CREATE PROCEDURE test_insert()
BEGIN
declare i int;
set i=0;
while i<1000000 do
INSERT INTO `test110` VALUES (null,'TMP01','user11','会员中台','2019-08-15 00:00:02','11','22');
set i=i+1;
end while;
end $$
DELIMITER ;

测试如下,速度很快:

mysql> call test_insert();
Query OK, 1 row affected (44.71 sec)

mysql> call test_insert();
Query OK, 1 row affected (44.74 sec)

mysql> call test_insert();
Query OK, 1 row affected (44.71 sec)

mysql> select count(1) from test110;
+----------+
| count(1) |
+----------+
|  3000000 |
+----------+
1 row in set (0.44 sec)

MySQL配置如下my.cnf

[client]
default-character-set = utf8mb4
port        = 3306
socket        = /data/mysql/mysql.sock

[mysql]
default-character-set = utf8mb4
prompt="\u@oatestdb \R:\m:\s [\d]> "
no-auto-rehash

[mysqld]

secure_file_priv = ''
#validate-password = off
slow_query_log = On
log_output = FILE
slow-query-log-file=/data/mysql/slow.log
long_query_time = 30 
log_queries_not_using_indexes = ON

lower_case_table_names=1
auto-increment-increment = 1
auto-increment-offset = 1

log_warnings=1
log_error_verbosity=1

default-storage-engine=INNODB
group_concat_max_len = 18446744073709551615
# generic configuration options
port        = 3306
socket        = /data/mysql/mysql.sock 
pid-file        = /data/mysql/mysqld.pid
basedir        = /usr/local/mysql
datadir         = /data/mysql/db
language    = /usr/local/mysql/share/english 
user        = mysql
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
skip-external-locking
skip-name-resolve
skip-character-set-client-handshake
character-set-server = utf8mb4
explicit_defaults_for_timestamp = true
init_connect='SET NAMES utf8mb4'
character-set-client-handshake = FALSE
collation-server = utf8mb4_unicode_ci
explicit_defaults_for_timestamp

#replication
expire_logs_days = 30
sync-binlog = 1000
server_id=1
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
log_bin=/data/mysql/binlog/binlog
binlog_format=ROW


relay_log_recovery = 1
skip_slave_start = 0
slave-skip-errors = all
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G

#group replication
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="e4668cea-d7ca-11e6-86b5-18a99b76310d"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "db1:24901"
loose-group_replication_group_seeds= "db1:24901,db2:24902,db3:24903"
loose-group_replication_bootstrap_group= off
loose-group_replication_single_primary_mode=FALSE
loose-group_replication_enforce_update_everywhere_checks= TRUE

skip_name_resolve = 1
open_files_limit    = 65535
back_log = 1024
max_connections = 5000
max_connect_errors = 100000
max_prepared_stmt_count=1048576
table_open_cache = 10240
table_definition_cache = 10240
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 7680
query_cache_size = 0
query_cache_type = 0
interactive_timeout = 900
wait_timeout = 900
tmp_table_size = 256M
max_heap_table_size = 256M

# innodb
innodb_buffer_pool_size = 12G 
innodb_data_file_path = IBdata1:1024M;IBdata2:1024M:autoextend
innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_flush_method=O_DSYNC

innodb_io_capacity = 50000
innodb_io_capacity_max = 80000
innodb_flush_neighbors = 0
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_checksum_algorithm = crc32
#innodb_file_format = Barracuda
#innodb_file_format_max = Barracuda
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G
internal_tmp_disk_storage_engine = InnoDB
innodb_stats_on_metadata = 0

[mysqld_safe]
open-files-limit = 8192
log-error=/data/mysql/error.log
pid-file=/data/mysql/mysqld.pid

[mysqldump]
quick
max_allowed_packet = 32M

最新

分类

归档

评论

其它