2019年10月

预请求

if ($request_method = OPTIONS ) {
    add_header Access-Control-Allow-Origin "*";
    add_header Access-Control-Allow-Methods "POST, GET, PUT, OPTIONS, DELETE";
    add_header Access-Control-Max-Age "3600";
    add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization";
    add_header Content-Length 0;
    add_header Content-Type text/plain;
    return 200;
}

备注: 需要放在location节点下面

yarn错误The engine "node" is incompatible with this module

yarn config set ignore-engines true

转发简单例子

server{
  listen 80;
  server_name  kjwoo.cn.test;
  index  index.php index.html index.htm;

  location / {
     proxy_pass  http://192.168.1.9:3300;
  }
}

写日志

server{
  listen 80;
  server_name  kjwoo.cn.test;
  index  index.php index.html index.htm;
  log_format  log_json  '{"@timestamp": "$time_local","user_ip":"$http_x_real_ip","lan_ip":"$remote_addr","log_time":"$time_iso8601","user_req":"$request","http_code":"$status","body_bytes_sents":"$body_bytes_sent","req_time":"$request_time","user_ua":"$http_user_agent"}';
  access_log  /var/log/nginx/access.log  log_json;

  location / {
     proxy_pass  http://192.168.1.9:3300;
  }
}

GCC版本安装或者升级(yum方案)

[root@wkjhost ~]# yum install centos-release-scl
[root@wkjhost ~]# yum install devtoolset-7-gcc*
[root@wkjhost ~]# scl enable devtoolset-7 bash
[root@wkjhost ~]# which gcc
[root@wkjhost ~]# gcc --version

为了提高测试质量与最后把关,决定搭建一个自动化测试平台,基本设想如下:

一、软件地图(测试路径建立)

  1. 前端方面对dom节点记录(建立dom模型)
  2. 流程方面建立站点地图(蜘蛛形式建立)
  3. API方面,结合aws平台(API管理系统)进行搭建地图

二、蜘蛛制作

  1. 抓取站点内容,形成地图
  2. 抓取站点内容做结果分析
  3. 抓取站点内容做代码统计
  4. 抓取站点内容做变化统计

三、搭建自动化测试配置后台

  1. 站点名称、报警邮箱、站点地址、递归次数等
  2. 管理测试结果,多次结果比对等
  3. 接入其他平台授权等

四、前端页面分析

  1. 使用本地正确的页面作为标准,进行抓取,生成dom树型地图
  2. 使用dom型地图进行页面比对,生成dom diff
  3. 对dom diff 分析得到分析结果
  4. 通过dom diff 自动给出解决方案

五、定时执行接口测试

六、报警系统接入

减少重定向: 301、302等

启动gzip压缩

[root@base~]# vi /etc/nginx/conf.d/gzip.conf

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
#gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain font/* application/javascript application/x-javascript text/css application/xml application/json text/javascript application/x-httpd-php image/jpeg image/gif image/png application/pdf;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";

实现步骤:
1、使用循环加上过滤获取到所有的日志文件
2、使用awk对字符串进行处理(比如:切割)
2-1、使用shell判断文件夹是否存在,如果不存在就创建
2-2、文件存在就先删除文件再写入新文件
3、nginx信号处理
4、定时任务建立(每天00:00)进行处理(/usr/local/bin/backup_log是shell文件的全路径)

0 0 * * * /usr/local/bin/backup_log.sh

备注:
1、日志放在/var/www/logs下面
2、日志命名为:[域名]-access.log 和 [域名]-error.log

/usr/local/bin/backup_log.sh代码如下

#!/bin/bash
# use this to backup log
# /usr/local/bin/backup_log.sh
# author: wkj

NGINX_PATH=/etc/nginx/
LOG_PATH=/var/www/logs/
NGINX_PID=/run/nginx.pid
YESTERDAY=`date +%F -d -1day`
cd $LOG_PATH
for logName in `ls ./ | grep .log`
    do
        logPath=`echo $logName|awk -F'-' '{print $1}'`
        fileType=`echo $logName|awk -F'-' '{print $2}'`
        logPathR=${LOG_PATH}${logPath}
        if [ ! -d $logPathR ];then
            mkdir $logPathR
        fi
        fileName=${logPathR}/${YESTERDAY}-${fileType}
        if [ -f $fileName ];then
            rm -f $fileName
        fi
        mv $logName $fileName
    done

kill -USR1 `cat ${NGINX_PID}`

mariadb基础命令

查看数据表的数据表的物理路径
MariaDB [(none)]> show global variables like '%datadir%'

使用'READ-COMMITTED'作为默认隔离级别
MariaDB [(none)]> SET GLOBAL tx_isolation='READ-COMMITTED';

创建用户并授权(把newddb数据库分配给adduser用户并设置密码为:adduser123)
MariaDB [(none)]> grant all privileges on newddb.* to adduser@'localhost' identified by 'adduser123';

创建utf8mb4编码的数据库(数据库名称:newdb)
MariaDB [(none)]> CREATE DATABASE newdb DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;

创建utf8编码的数据库(数据库名称:newdb)
MariaDB [(none)]> CREATE DATABASE newdb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

刷新权限表
MariaDB [(none)]> flush privileges;

删除用户(用户名:testuser)
MariaDB [(none)]> drop user testuser

删除数据库(用户名:testdb)
MariaDB [(none)]> drop database testdb

查看连接数
[root@wkjhost ~]# mysqladmin -uroot -p123 processlist

查看配置遍历
MariaDB [(none)]> show variables like '%query_cache%'

初始化数据库密码: root_pwd
[root@wkjhost ~]# mysql_secure_installation

centos7安装mariadb 10

添加 MariaDB 的YUM配置文件MariaDB.repo文件
[root@wkjhost ~]# vi /etc/yum.repos.d/MariaDB.repo

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

安装 MariaDB
[root@wkjhost ~]# yum install MariaDB-server -y

mariadb基础命令问题解决

数据库启动不了

查看数据库日志
[root@wkjhost ~]# vi /var/log/mariadb/mariadb.log

进入数据库的数据目录,清除logfile文件
[root@wkjhost ~]# rm -f /uar/lib/mysql/ib_logfile*

检查数据库端口是否被占用
[root@wkjhost ~]# netstat -tunpl | grep 3306

数据库进不去(密码不正确)

停止数据库服务
[root@wkjhost ~]# systemctl stop mariadb

跳过权限表进行启动(登录数据库就不用密码)
[root@wkjhost ~]# mysqld_safe --skip-grant-tables &

直接登录数据库(直接点击确定就行)
[root@wkjhost ~]# mysql -uroot -p

修改密码
MariaDB [(none)]> update mysql.user set password=password("root_pwd") where user="root";
MariaDB [(none)]> quit

杀死mysql进程,启动mysql服务
[root@wkjhost ~]# kill `netstat -tunpl | grep 3306 | awk -F' ' '{ print $7 }'|awk -F'/' '{print $1}'`
[root@wkjhost ~]# systemctl start mariadb

Mysql8密码问题

问题:发现登录不了,报错:navicat不支持caching_sha_password加密方式
原因:mysql8.0使用新的密码加密方式:caching_sha_password
解决方式:修改成旧的加密方式(mysql_native_password),并重置密码

select host,user,plugin from user;
alter user 'root'@'%' identified with mysql_native_password by 'root';

SQL语句收集

把table_name表中的key字段中的“table.”修改为“entity.”的sql语句

UPDATE `table_name` SET `key` = REPLACE(`key`, 'table.', 'entity.') WHERE `key` LIKE 'table.%';