构建最新的nodejs docker服务器
构建最新的nodejs docker服务器
新建一个目录作为我的dockerImages的目录,然后执行:
mkdir /Users/samhu/Public/dockerImages
新建package.json
新建server.js文件
新建Dockerfile
vi Dockerfile
内容为:
CMD内容 npm start 会执行 node server.js这个命令。。。。。
最后在dockerImage目录下,build成image:
docker build -t sam.hu/node-web-app .
启动一个nodejs应用服务器,端口号是40000:
docker run -p 40000:8080 --rm -it -v $(pwd):/usr/src/app sam.hu/node-web-app
不加 -it
是为容器启动
查看docker容器使用情况:
docker stats
安装Apache Bench(ab)作压力测试
三种方式:
源码安装
下载后解压,终端执行:
./configuare
二进制安装
命令行忘记了
命令行安装
yum install httpd
使用ab测试并发
ab -n 5000 -c 600 http://www.jinjiang.com/
如果出现错误:
enchmarking www.jinjiang.com (be patient)
socket: Too many open files (24)
则是因为服务器对并发文件连接有open files限制 ,登陆服务器执行:
ulimit -a
找到:
open files (-n) 1024
调整可以打开的文件数:
ulimit -n 65535
同时修改nginx.conf添加
worker_rlimit_nofile 65535;
但是在nginx服务器可以打开的文件数量受你操作系统的限制,所以编辑/etc/sysctl.conf
添加如下内容:
fs.file-max = 70000
保存退出,从新读取系统配置
sysctl -p
再编辑 /etc/security/limits.conf
添加内容:
soft nofile 10000
hard nofile 30000
此修改内容需要reboot系统才能生效,所以务必从新启动下服务器。
再次查看系统输出
ulimit -Hn
ulimit -Sn
输出:
30000 10000