CentOS 7开启BBR

最近把所有服务器整理了个遍,顺便记录下开启BBR的过程。
环境是Oracle Cloud的CentOS 7。

首先安装最新的Linux kernel, 可以使用ELRepo源:http://elrepo.org/tiki/HomePage

第一步,安装key:

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

二,导入源:

yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm

三,安装kernel:

yum --enablerepo=elrepo-kernel install kernel-ml -y

四,设置最新kernel为启动项:

grub2-set-default 0  

重启后用uname -a查看kernel版本号,我安装的是5.10版本。

五,开启BBR

写入net.core.default_qdisc参数:

echo 'net.core.default_qdisc=fq' >> /etc/sysctl.conf

写入net.ipv4.tcp_congestion_control参数:

echo 'net.ipv4.tcp_congestion_control=bbr' >> /etc/sysctl.conf

再使用以下命令另设置生效:

sysctl -p

六,检查是否成功开启:

sysctl net.ipv4.tcp_congestion_control

应返回结果:

net.ipv4.tcp_congestion_control = bbr

如果已经有web服务,可以创建以下临时文件然后进行下载测试:

dd if=/dev/zero of=500mb.zip bs=1024k count=500

END.

参考:
https://www.jianshu.com/p/62c9b9570c05
https://blog.csdn.net/qq_43550613/article/details/83512518

数据迁移记

嗯~
终于又出山了,为数据迁移了一个好地方。

迁移后网站一直中转不了,nginx配置最后改为以下后终于OK:

server {
    listen 80;
    server_name  127.0.0.1; # 改为自己的域名,没域名修改为127.0.0.1
    charset utf-8;
    client_max_body_size  50000m;
    location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
}

然后伪静态规则修改为以下:

location ~ .*\.php(\/.*)*$
{
    fastcgi_pass  unix:/tmp/网站.sock;
    fastcgi_index index.php;
     fastcgi_split_path_info ^(.+\.php)(/.*)$;
     fastcgi_param PATH_INFO $fastcgi_path_info;
    include fcgi.conf;
    fastcgi_param DOCUMENT_ROOT  网站目录/web$subdomain;
    fastcgi_param SCRIPT_FILENAME  网站目录/web$subdomain$fastcgi_script_name;
}

参考:
https://blog.csdn.net/Bobdragery/article/details/104473712

API测试框架研究

公司有项目的API是使用json格式的,因此研究使用nodejs类别的测试框架看是否可以提高API测试效率。

网上使用supertest + Mocha 两个组件搭配进行测试的案例比如多,因此考虑使用这个。

首先需要安装nodejs。
官网: https://nodejs.org/en/
安装版本:v6.9.2
安装后支持npm包安装命令。

新建一个目录,例如project
安装两个组件,命令如下:

npm install supertest --save-dev
npm install mocha --save-dev

--save-dev参数是将组件安装到该目录,而不是全局系统目录。
两个组件版本:
"mocha": "^3.2.0",
"supertest": "^2.0.1"

supertest测试代码:

var serurl = 'http://IP/server/';
var request = require('supertest')(serurl);  

var userId = 'abc'
var password = '123456'

//创建登录请求
request
  .post('login/')
  .set('Content-Type', 'application/json')
  .send({userId: userId})
  .send({password: password})
  //发送请求
  .end(function(err, res){
  //原结果是text,将其转成json格式方便获取里面的数据
  var content = JSON.parse(res.text);
  //获取contact里面的error项的例子
  console.log(content.error);
    if(err) throw err;
  }
);

保存成test.js,然后执行node test.js就能看到结果了。

$node login.js
10000

使用Mocha生成报告,使用chai做断言库。用assert一直有问题,不知道原因。
先安装chai, npm install chai --save-dev

var serurl = 'http://IP/server/'
var request = require('supertest')(serurl)
var expect = require('chai').expect;

var userId = 'abc'
var password = '123456'

// Login
describe('Check errorCode', function() {
    it('check code return 10000', function(done) {
    request
    .post('login/')
    .set('Content-Type', 'application/json')
    .send({userId: userId})
    .send({password: password})
    .end(function(err,res){
        //将结果转成json格式
        content = JSON.parse(res.text)0
        //如果error返回10000就断定是pass
        expect(contact.error).to.be.equal('10000');
        done()
        })
    })
})

将以上保存成login.js后,用mocha login.js就可以看到测试结果。成功的结果:

$mocha login.js

Check error
✓ check it is 10000

1 passing (45ms)

模拟返回error不对等时的错误:

$mocha mocha_chai.js

Check errorCode
1) check it is 10000

0 passing (49ms)
1 failing

1) Check errorCode check it is 10000:

 Uncaught AssertionError: expected '10000' to equal '10001'
 + expected - actual

 -10000
 +10001

 at Test.<anonymous> (mocha_chai.js:25:35)
 at Test.assert (node_modules/supertest/lib/test.js:179:6)
 at assert (node_modules/supertest/lib/test.js:131:12)
 at node_modules/supertest/lib/test.js:128:5
 at Test.Request.callback (node_modules/superagent/lib/node/index.js:619:12)
 at IncomingMessage.<anonymous> (node_modules/superagent/lib/node/index.js:795:18)
 at endReadableNT (_stream_readable.js:974:12)
 at _combinedTickCallback (internal/process/next_tick.js:74:11)
 at process._tickCallback (internal/process/next_tick.js:98:9)

expect断言的一些例子:

// 相等或不相等
expect(4 + 5).to.be.equal(9);
expect(4 + 5).to.be.not.equal(10);
expect(foo).to.be.deep.equal({ bar: 'baz' });

// 布尔值为true
expect('everthing').to.be.ok;
expect(false).to.not.be.ok;

// typeof
expect('test').to.be.a('string');
expect({ foo: 'bar' }).to.be.an('object');
expect(foo).to.be.an.instanceof(Foo);

// include
expect([1,2,3]).to.include(2);
expect('foobar').to.contain('foo');
expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');

// empty
expect([]).to.be.empty;
expect('').to.be.empty;
expect({}).to.be.empty;

// match
expect('foobar').to.match(/^foo/);

参考:
http://www.jianshu.com/p/9c78548caffa
https://visionmedia.github.io/superagent/#test-documentation
https://github.com/visionmedia/supertest
http://wetest.qq.com/lab/view/145.html
http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html