Surick's blog


  • 首页

  • 标签

  • 分类

  • 归档

监控环境常用的命令

发表于 2019-05-13 | 分类于 Linux |

生产环境服务器变慢

查看整机情况

  • 使用top命令查看CPU占用率、内存占用率以及第一行的load average
  • load average后的三个数字分别记录了一分钟、五分钟、以及十五分钟的系统平均负载
  • 还可以使用uptime命令,是系统性能命令的精简版

查看 CPU 情况

  • 使用vmstat -n 2 3代表每2秒采样一次,一共采样3次
  • procs中r代表运行和等待CPU时间片的进程数,整个系统的运行队列不应超过总核数的2倍,否则代表系统压力过大
    • b 代表等待资源如磁盘I/O,网络 I/O的进程数cpu中
    • us 代表用户进程消耗CPU时间百分比,如果长期大于50%要优化程序
    • sy 代表内核进程消耗CPU时间百分比us + sy参考值为80%,如果和大于80%,可能存在CPU不足
  • 使用mpstat -P ALL 2查看所有CPU核信息
  • 使用pidstat -u 1 -p pid查看每个进程使用CPU的用量分解信息

查看内存信息

  • 使用free -m来查看内存情况,单位为mb,应用程序可用内存/系统物理内存 应该在20%~70%
  • 使用pidstat -p pid -r采样间隔秒数

查看硬盘信息

  • 使用df -h查看磁盘IO
  • 使用iostat -xdk 2 3
    • rkB/s 每秒读取数据量
    • wkB/s 每秒写入数据量
    • svctm I/O请求的平均服务时间,单位为ms
    • util 一秒有百分之多少的时间用于I/O操作
  • 使用pidstat -d采样间隔秒 -p pid

查看网络IO

  • 使用ifstat采样间隔秒

CPU 占用过高的分析

  • 使用top命令找出CPU占比最高的进程
  • ps -ef或者jps进一步定位该进程信息定位到具体线程或代码
  • 使用ps -mp pid -o THREAD,tid,time
    • -m 显示所有线程
    • -p pid进程使用cpu的时间
    • -o 后是用户自定义格式将需要的线程id转换为16进制(英文小写格式)
  • jstack 进程id | grep tid -A60

mysql中group by报错

发表于 2019-05-10 | 分类于 数据库 |

mysql中group by报错

报错

which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

解决方法

  • sudo vi /etc/mysql/my.cnf
  • 1
    2
    [mysqld]
    sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
  • Type esc to exit input mode

  • Type :wq to save and close vim.
  • Type sudo service mysql restart to restart MySQL.

记一次springboot启动项目阻塞问题

发表于 2019-05-05 | 分类于 坑 |

springboot启动项目卡在mybatis-plus init success下没有任何报错信息

问题

  • springboot启动项目卡在log4j:WARN Please initialize the log4j system properly.下
  • log4j:WARN Please initialize the log4j system properly.上是mybatis-plus init success信息
  • 没有任何报错信息

原因

mybatis-plus插件启动的时候会访问数据库,如果数据库连接不上,就会一直阻塞,卡着tomcat线程启动不了,并且没有任何提醒信息、报错信息

解决方法

确认mysql数据库可访问

mysql按时间段统计例子

发表于 2019-04-25 | 分类于 数据库 |

mysql按时间段统计(年,季度,月,天,时)

按年汇总,统计:

1
select sum(mymoney) as totalmoney, count(*) as sheets from mytable group by date_format(col, '%Y');

按月汇总,统计:

1
select sum(mymoney) as totalmoney, count(*) as sheets from mytable group by date_format(col, '%Y-%m');

按季度汇总,统计:

1
select sum(mymoney) as totalmoney,count(*) as sheets from mytable group by concat(date_format(col, '%Y'),FLOOR((date_format(col, '%m')+2)/3));
1
select sum(mymoney) as totalmoney,count(*) as sheets from mytable group by concat(date_format(col, '%Y'),FLOOR((date_format(col, '%m')+2)/3));
阅读全文 »

tomcat上传文件默认权限问题

发表于 2019-04-25 | 分类于 坑 |

Tomcat 8.5版本图片上传后,Nginx访问403

问题

  • springboot项目上传背景图,之后通过nginx访问一直报403 forbidden
  • 查看服务器上传文件夹权限为之前设置755(rwxr-xr-x),但是里面图片文件权限为640(rw-r-----)
  • 查看umask为0022,umask002对应文件权限664,文件夹权限775,umask022对应文件权限644,文件夹权限755,默认文件权限没有问题

原因

  • tomcat8.5的catalina.sh中更改了umask

    1
    2
    3
    4
    5
    # Set UMASK unless it has been overridden
    if [ -z "$UMASK" ]; then
    UMASK="0027"
    fi
    umask $UMASK
  • 8.5更新日志

解决方法

修改catalina.sh中umask值为0002,并重启

maven日志包冲突解决

发表于 2019-04-19 |

SLF4J: Class path contains multiple SLF4J bindings报警告

一开始只是在idea里面启动时报警告,并未在意,直到上线时应用启动不了一只到logback相关的错误

原因

腾讯的api包带的日志组件和项目里netty那一块冲突了

解决方法

1
2
3
4
5
6
7
8
9
10
11
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
<version>4.4</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>

怎么让react中某个组件全屏显示

发表于 2019-04-17 |

怎么让react某个组件全屏

需求为高德地图组件增加一个全屏显示功能,但其自api自带控件没有此功能

事件

1
2
3
4
5
6
7
8
9
10
11
12
13
   constructor(props, context) {
super(props, context);
this.key = randomStr();
this.state = {
id: 0, // 投放点id
deviceCount: 0,
isfullscreen: false
};
}
switchFullscreen(){
this.setState({isfullscreen: !this.state.isfullscreen});
console.log(this.state);
}
1
2
3
4
5
<div style={styles.main} onKeyDown={this.switchFullscreen.bind(this)}>
<Button onClick={this.switchFullscreen.bind(this)}>全屏</Button>
<div style={this.state.isfullscreen ? styles.fullscreen : styles.height} id={this.key} />
{sidebarProps.id ? <Sidebar {...sidebarProps} data={queryData} /> : null}
</div>

样式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const styles = {
height: {
height: '650px'
},
fullscreen: {
zIndex: '999',
position: 'fixed',
top: '0',
bottom: '0',
left: '0',
right: '0'
},
main: {
position: 'relative'
}
};

cron表达式

发表于 2019-04-15 |

Cron表达式示例:

表达式说明

  • “0 0 12 ? “每天12点运行
  • “0 15 10 ?”每天10:15运行
  • “0 15 10 ? 2011”2011年的每天10:15运行
  • “0 14 * ?”每天14点到15点之间每分钟运行一次,开始于14:00,结束于14:59。
  • “0 0/5 14 ?”每天14点到15点每5分钟运行一次,开始于14:00,结束于14:55。
  • “0 0/5 14,18 ?”每天14点到15点每5分钟运行一次,此外每天18点到19点每5钟也运行一次。
  • “0 0-5 14 ?”每天14:00点到14:05,每分钟运行一次。
  • “0 10,44 14 ? 3 WED”3月每周三的14:10分到14:44,每分钟运行一次。
  • “0 15 10 ? * MON-FRI”每周一,二,三,四,五的10:15分运行。
  • “0 15 10 15 * ?”每月15日10:15分运行。
  • “0 15 10 L * ?”每月最后一天10:15分运行。
  • “0 15 10 ? * 6L”每月最后一个星期五10:15分运行。
  • “0 15 10 ? * 6L 2007-2009”在2007,2008,2009年每个月的最后一个星期五的10:15分运行。
    阅读全文 »

How to use Hexo and deploy to GitHub Pages

发表于 2019-04-09 |

How to use Hexo and deploy to GitHub Pages

  • https://github.com/hexojs/hexo
  • https://hexo.io/docs/

1. Install Hexo

1
2
3
4
5
6
7
8
9
10
11
12
$ sudo npm install -g hexo-cli

$ hexo -v
hexo-cli: 0.1.9
os: Darwin 14.3.0 darwin x64
http_parser: 2.3
node: 0.12.7
v8: 3.28.71.19
uv: 1.6.1
zlib: 1.2.8
modules: 14
openssl: 1.0.1p
阅读全文 »

Solved cb() never called!

发表于 2019-04-09 |

npm ERR! cb() never called!

  • First of all, verify your node.js version using your terminal with this simple command
    node -v
  • Clear your npm cache
    sudo npm cache clean -f
  • Install the latest version of the Node helper
    npm install -g n
  • Tell the helper (n) to install the latest stable version of Node
    sudo n stable
  • After previous commands finish you will be up-to-date. Let’s run our install again
    npm install

Surick

Just memory trace

10 日志
3 分类
8 标签
GitHub E-Mail Twitter
© 2018 — 2019 Surick
由 Hexo 强力驱动
|
主题 — NexT.Mist v5.1.4