webssh日常笔记

说到webssh,第一个想到的是C9,可惜其耗费资源偏大,不适合轻型部署。

GateOne是一款后端Python前端 HTML5 技术编写的webssh终端模拟器。还自带录制回放,占用资源很小,用下来感觉良好。

安装依赖:

(1) Python 版本为2.6+和3.2+ 
(2) Tornado Framework 框架2.2+ 
(3) 如果Python是2.6版本的需要安装ordereddict module 
(4) tornado kerberos等模块

安装过程:

#安装tornado-2.4
wget https://pypi.python.org/packages/2d/9a/38e855094bd11cba89cd2a50a54c31019ef4a45785fe12be6aa9a7c633de/tornado-2.4.tar.gz#md5=c738af97c31dd70f41f6726cf0968941
tar zxvf tornado-2.4.tar.gz
cd tornado-2.4
python setup.py build
python setup.py install
python -c "import tornado; print(tornado.version)"   #查看tornado版本

pip install kerberos  #安全认证模块可以不用装

#安装GateOne-1.1
wget https://github.com/liftoff/GateOne/archive/v1.1.tar.gz
tar zxvf v1.1.tar.gz
cd GateOne-1.1
python setup.py install

启动:

python /opt/gateone/gateone.py

配置文件:

vim /opt/gateone/server.conf
#修改其中以下选项
port = 9999         #设定端口
disable_ssl = True  #关闭ssl
origins = "*"       #允许所有主机访问

接口自动化测试postman+newman

postman下载地址:

https://www.getpostman.com/apps

postman编写测试代码:

参考官方说明文档:https://www.getpostman.com/docs/testing_examples

TV4 json校验解析器:https://github.com/geraintluff/tv4

newman源码地址:

https://github.com/postmanlabs/newman

newman快速安装过程:

npm install -g newman

注:newman最新版需要nodejs4.x以上支持

查看版本:

newman --version

从postman导出collections,后缀为xxx.postman_test_run.json文件到安装newman的机器环境下。

newman测试:

newman run test.postman_collection.json

导出成html(使用环境变量):

newman run --reporters html test.postman_collection.json --reporter-html-export htmlOutput.html --export-environment svn.com.postman_environment.json

Nodejs

本文记录nvm、node、npm、yarn安装过程

Windows下安装

nvm-windowns下载 https://github.com/coreybutler/nvm-windows/releases

切换nvm安装源:

在 nvm 的安装路径下,找到 C:\Users\ml\AppData\Roaming\nvm\settings.txt,在后面加上这两行

node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/

如果报错:Get “https://npm.taobao.org/mirrors/node/index.json”: tls: failed to verify certificate: x509: certificate has expired or is not yet valid

则用http协议

node_mirror: http://npm.taobao.org/mirrors/node/
npm_mirror: http://npm.taobao.org/mirrors/npm/

切换npm安装源:

npm config set registry https://registry.npm.taobao.org

Linux下安装

官方地址:https://github.com/creationix/nvm

Linux下推荐使用nvm来安装nodejs

安装nvm

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

脚本会自动把以下执行环境写入.bashrc:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

安装nodejs

nvm install 10.8.0

国内使用淘宝node镜像,加速nodejs安装过程:

export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/
nvm install 10.11.0

或者:

NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/ nvm install 10.11.0

Linux使用淘宝NPM镜像:

编辑 ~/.npmrc,添加

registry=https://npm.taobao.org/mirrors/npm/

若不想将本源设置为默认源,只想使用本源安装某个软件包,可在安装包时采用以下用法:

npm --registry https://npm.taobao.org/mirrors/npm/ install <packagename>

windows下安装

直接去github下载msi安装包: https://github.com/coreybutler/nvm-windows/releases

windows使用淘宝node镜像:

nvm node_mirror https://npm.taobao.org/mirrors/node/

windows使用淘宝npm镜像:

nvm npm_mirror https://npm.taobao.org/mirrors/npm/

CNPM

安装方法:

npm install -g cnpm --registry=https://registry.npm.taobao.org

YARN

下载地址:https://github.com/yarnpkg/yarn/releases

使用文档:https://yarnpkg.com/zh-Hans/docs

升级自身yarn

npm install yarn -g

查看yarn版本

yarn -v

Yarn 设置淘宝镜像

1.查询当前配置的镜像

yarn config get registry

> https://registry.yarnpkg.com

2.设置成淘宝镜像

yarn config set registry http://registry.npm.taobao.org/

3.显示当前安装的全局yarn依赖库

yarn global list

npm与yarn CLI 命令比较

npm (v5) Yarn
npm install yarn install
(不适用) yarn install –flat
(不适用) yarn install –har
npm install –no-package-lock yarn install –no-lockfile
(不适用) yarn install –pure-lockfile
npm install [package] yarn add [package]
npm install [package] –save-dev yarn add [package] –dev
(不适用) yarn add [package] –peer
npm install [package] –save-optional yarn add [package] –optional
npm install [package] –save-exact yarn add [package] –exact
(不适用) yarn add [package] –tilde
npm install [package] –global yarn global add [package]
npm update –global yarn global upgrade
npm rebuild yarn install –force
npm uninstall [package] yarn remove [package]
npm cache clean yarn cache clean [package]
rm -rf node_modules && npm install yarn upgrade

异常处理: 使用yarn升级vue cli后显示 ‘vue’ 不是内部或外部命令,也不是可运行的程序

解决办法:把yarn的包执行目录添加到系统环境变量里。

处理方式:

1.执行yarn global dir 显示出yarn安装路径

2.定位到Yarn\bin目录,把该路径复制到系统环境变量Path里

nvm使用方法

列出全部可以安装的版本号

nvm ls-remote

(windows下为)

nvm list available

安装指定版本nodejs

nvm install 9.3.0

切换指定版本,切换效果是全局的

nvm use v8.0.0

查看当前使用的版本

nvm current

查看本地安装版本,这个命令也能看到当前使用的是哪个版本

nvm ls --depth 0

清空模块

rm -rf node_modules/ && npm cache clean && npm prune

npm的常用命令:

npm ci                #使用安装package.lock.json安装,锁定依赖版本

npm -v                #显示版本,检查npm 是否正确安装。
 
npm install express   #安装express模块
 
npm install -g express  #全局安装express模块
 
npm list              #列出已安装模块
 
npm show express      #显示模块详情
 
npm update            #升级当前目录下的项目的所有模块
 
npm update express    #升级当前目录下的项目的指定模块
 
npm update -g express  #升级全局安装的express模块
 
npm uninstall express  #删除指定的模块

npm start --prefix path/to/your/app     # start时指定路径

生成package.json文件

node init

其他安装方式 old

快速安装过程:

apt-get install -y nodejs npm
npm config set registry http://registry.npm.taobao.org  #使用淘宝源
npm install -g n     #安装n模块
n stable	#升级到nodejs最新稳定版

n后面也可以跟随版本号比如:

n v0.10.26
n 0.10.26

编译安装:

nodejs下载地址:https://nodejs.org/dist/

wget https://nodejs.org/download/rc/v4.0.0-rc.1/node-v4.0.0-rc.1.tar.gz
tar -zxvf node-v4.0.0-rc.1.tar.gz
cd node-v4.0.0-rc.1
./configure
make && make install
node -v

源码安装:

cd /tmp && \
wget http://nodejs.org/dist/node-latest.tar.gz && \
tar xvzf node-latest.tar.gz && \
rm -f node-latest.tar.gz && \
cd node-v* && \
./configure && \
CXX="g++ -Wno-unused-local-typedefs" make && \
CXX="g++ -Wno-unused-local-typedefs" make install && \
cd /tmp && \
rm -rf /tmp/node-v* && \
npm install -g npm && \
printf '\n# Node.js\nexport PATH="node_modules/.bin:$PATH"' >> /root/.bashrc

ERROR

MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。

解决方法:npm install –global –production windows-build-tools (全局安装windows构建工具)

Module build failed: Error: ENOENT: no such file or directory, scandir node-sass

解决办法:npm rebuild node-sass

PHP提权

php运行环境本身有权限限制,有些命令即使关闭安全模式也无法运行,下面通过C来实现提权:

/*
 PHP提权
 Mail : malu#malu.me
*/
#include <stdio.h>

#include <stdlib.h>

#include <sys/types.h>

#include <unistd.h>


int main(int argc, void **argv){
        if(argc<2){
                return 0;
        }
        uid_t uid ,euid,i;
        uid = 0;
        euid = geteuid();
        char execname[10240];
        //printf("my uid :%u\n",getuid());

        //printf("my euid :%u\n",geteuid());

        if(setreuid(euid, uid)){
                perror("setreuid");
        }else{
                //printf("after uid :%u\n",getuid()); 

                //printf("after euid :%u\n",geteuid()); 

                sprintf(execname, "%s",argv[1]);
                for(i=2;i<argc;i++){
                        sprintf(execname, "%s %s",execname,argv[i]);
                }
                system(execname);
                return 0;
        }
}

把以上C代码编译,并赋予s权限:

gcc a.c
chmod 4777 a.out

接下来就可以通过a.out来提权执行任何命令了。

jenkins日常笔记

关联项目 到 Slave 上

在项目 配置 中勾选 Restrict where this project can be run ,在 Label Expression 输入节点的名称。

SVN更新用的插件名称

Subversion Plug-in

安装完插件记得重启jenkins

构建触发器

Poll SCM:定时检查源码变更(根据SCM软件的版本号),如果有更新就checkout最新code下来,然后执行构建动作。

列如(每1分钟检查一次源码变化):

*/1 * * * *

Build periodically:周期进行项目构建(它不care源码是否发生变化)

例如(每天3:00 必须build一次源码):

0 3 * * *

节点连接不上主服务器

默认情况下,Jenkins通过JNLP方式和从节点建立TCP连接时,使用的是随机端口。某些情况下(例如防火墙等安全限制),需要固定连接使用的端口。这时,如果使用随机端口的话,会导致从节点无法建立与Jenkins主控服务器的连接。

Jenkins提供了“使用固定端口”的方式来解决这个问题,具体操作是:

依次点击“系统管理”->“Configure Global Security”,选中“JNLP节点代理的TCP端口”的“固定端口(Fixed)”项,并输入端口号(例如12345),保存退出即可。

Docker jenkins

项目地址:https://github.com/pingmalu/docker_jenkins

虚拟机日常笔记

VMware下Linux磁盘扩容

今天需要对VMware12下对虚拟机Ubuntu14.04系统所在分区sda1进行磁盘扩容,会用到Gparted。

Gparted简介

GParted (Gnome Partition Editor)是一种非常小巧自启动运行光盘,采用X org,轻量级的Fluxbox窗口管理器,以及最新的2.6 Linux内核建构。其中包含的GParted硬盘分区工具,作为系统维护盘非常有用。

GParted是一款Linux下的功能非常强大的分区工具,和windows下的‘分区魔术师’类似,操作和显示上也很相似。GParted可以方便的创建、删除分区,也可以调整分区的大小和移动分区的位置。

GParted支持多种Linux下常见的分区格式,包括ext2、ext4、fat、hfs、jfs、reiser4、reiserfs、xfs,甚至ntfs。另外官方还提供了 LiveCD 和 LiveUSB 版本的 GParted,方便在没有主系统的情况下对硬盘进行分区!

下载地址:https://sourceforge.net/projects/gparted/files/gparted-live-stable/

具体操作参考:http://www.linuxidc.com/Linux/2015-08/121674.htm

SWAP分区为0解决办法

根据上文操作后,会发现swap分区没有生效:

root@ubuntu:~# free -h
             total       used       free     shared    buffers     cached
Mem:          1.9G       880M       1.1G       896K        37M       191M
-/+ buffers/cache:       651M       1.3G
Swap:           0B         0B         0B

处理办法:

root@ubuntu:~# fdisk -l
Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders, total 251658240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007ef3a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   246624255   123311104   83  Linux
/dev/sda2       246624256   251658239     2516992    5  Extended
/dev/sda5       246626304   251658239     2515968   82  Linux swap / Solaris

root@ubuntu:~# blkid /dev/sda5
/dev/sda5: UUID="b140a7b0-4986-4df1-a799-8be7ea6bd694" TYPE="swap" 

把获取到swap分区的UUID写入/etc/fstab:

root@ubuntu:~# vim /etc/fstab
UUID=b140a7b0-4986-4df1-a799-8be7ea6bd694 none            swap    sw              0       0

vmware修改bios等待时间:

找到虚拟机配置文件(以.vmx为后缀的文件)在里面加上一句:

bios.bootDelay = "5000"  #单位是毫秒

Fiddler日常笔记

代理不能抓包问题处理

1.如果关闭防火墙,可以访问

进入Windows安全中心,点击“防火墙和网络保护”

在页面点击“允许应用通过防火墙”

点击“更改设置”->勾选“Fiddler”->点击“确定”,Fiddler可以通过防火墙通讯也能正常抓包了

filter 过滤 css 图片 IP

过滤css、图片:

设置步骤: 1.勾选 Request Headers 中的 Hide if url contains 过滤项

贴入:

REGEX:(?insx)/[^\?/]*\.(css|ico|jpg|png|gif|bmp|wav)(\?.*)?$

EGEX: 表示启用正则表达式

(?insx) 设置正则解释的规则, 忽略大小写等.

过滤IP

选择host -> hide the follow host 填入IP

192.168.1.1;

防火墙

windows防火墙

查看所有防火墙规则:

netsh advfirewall firewall show rule name=all

查看特定名称的防火墙规则:

netsh advfirewall firewall show rule name=1ml

查看入站防火墙规则:

netsh advfirewall firewall show rule direction=inbound

查看出站防火墙规则:

netsh advfirewall firewall show rule direction=outbound

设置规则

netsh advfirewall firewall add rule name="1ml" protocol=tcp localport=22 action=allow dir=in

UFW

UFW,或称Uncomplicated Firewall,是iptables的一个接口,为不熟悉防火墙概念的初学者提供了易于使用的界面,同时支持IPv4和IPv6,广受欢迎。

检查UFW的状态

ufw status 

禁用UFW防火墙

ufw disable

启用UFW防火墙

ufw enable

重新开始,则可以使用reset命令

ufw reset

开启特定端口

ufw allow 22

特定的IP地址

ufw allow from 192.168.0.1
ufw deny from 192.168.0.2

参考文章:https://zhuanlan.zhihu.com/p/98880088

Iptables

查看规则

iptables -L -n

查看每个链的默认规则

iptables -S

查看NAT规则

iptables -nL -t nat

清空规则:

iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F

允许现有的IP连接:

iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

开放端口:

iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp --dport 5900 -j ACCEPT
iptables -A INPUT -p tcp --dport 5901 -j ACCEPT
iptables -A INPUT -p tcp --dport 5902 -j ACCEPT
iptables -A INPUT -p tcp --dport 5903 -j ACCEPT
iptables -A INPUT -p tcp --dport 5904 -j ACCEPT

拒绝其余的:

iptables -P INPUT DROP

封IP:

iptables -I INPUT -s 59.151.119.180 -j DROP

封IP段:

iptables -I INPUT -s 61.37.80.0/24 -j DROP

保存

iptables-save > /etc/iptables.test.rules

导入配置

iptables-restore < /etc/iptables.test.rules

构建ELK+Redis日志分析系统

安装Logstash+ElasticSearch5+Kibana5

JDK

最新版elasticsearch-5.0.0-alpha4需要java-1.8,

首先下载jdk-1.8,下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

解压安装:

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"  http://download.oracle.com/otn-pub/java/jdk/8u92-b14/jdk-8u92-linux-x64.tar.gz
tar -zxvf jdk-8u92-linux-x64.tar.gz
mkdir /usr/local/java
mv jdk1.8.0_92 /usr/local/java/

设置环境变量:

vim ~/.bashrc 追加:

export JAVA_HOME=/usr/local/java/jdk1.8.0_92
export JRE_HOME=${JAVA_HOME}/jre  
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib  
export PATH=${JAVA_HOME}/bin:$PATH

验证安装版本:

root@ubuntu:~# java -version
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

ElasticSearch5

ElasticSearch官方下载:https://www.elastic.co/downloads/elasticsearch

官方提供deb包,那就偷懒下 elasticsearch-5.0.0-alpha4.deb

安装:

dpkg -i elasticsearch-5.0.0-alpha4.deb

默认安装在/usr/share/elasticsearch 目录

启动:

cd /usr/share/elasticsearch/
mkdir config
cd bin/
./elasticsearch

错误:

如果报错:

Exception in thread "main" java.lang.RuntimeException: can not run elasticsearch as root

那么切换到普通用户

如果还报错:

Exception in thread "main" java.lang.IllegalStateException: Unable to access 'path.conf' (/usr/share/elasticsearch/config)

是因为访问权限不够:

chown malu /usr/share/elasticsearch -R

中文文档:http://learnes.net/

https://www.gitbook.com/book/looly/elasticsearch-the-definitive-guide-cn/details

Kibana5

Kibana官方下载: https://www.elastic.co/downloads/kibana

deb包下载: kibana-5.0.0-alpha4-amd64.deb

安装:

dpkg -i kibana-5.0.0-alpha4-amd64.deb

默认安装在/usr/share/kibana

启动:

cd /usr/share/kibana/bin
./kibana

中文文档:http://www.code123.cc/docs/kibana-logstash/

logstash5

官方下载:https://www.elastic.co/downloads/logstash

deb下载:logstash-5.0.0-alpha4.deb

安装:

dpkg -i logstash-5.0.0-alpha4.deb

默认安装在/usr/share/logstash

启动:

首先需要配置运行文件:

vim /etc/logstatsh/conf.d/first-pipeline.conf

input {
    file {
        path => "/var/log/nginx/access.log"
        start_position => beginning
        ignore_older => 0
    }
}
filter {
    grok {
        match => { "message" => "%{COMBINEDAPACHELOG}"}
    }
    geoip {
        source => "clientip"
    }
}
output {
    elasticsearch {
        hosts => [ "localhost:9200","server-2.malu.me:9200" ]
        user => "username"
        password => "pass"
        index => "%{module}-%{+YYYY.MM.dd}"
        document_type => "%{msgtype}"
    }
}

启动前可以用命令检查一下参数是否正确:

bin/logstash -f first-pipeline.conf --config.test_and_exit

然后执行:

/usr/share/logstash/bin/logstash

此时会读取logstash默认配置文件 /usr/share/logstash/config/logstash.yml

如果不存在,请从/etc/logstash/logstash.yml复制

logstash 2.3.4

下载安装环境:

wget https://download.elastic.co/logstash/logstash/packages/debian/logstash_2.3.4-1_all.deb
dpkg -i logstash_2.3.4-1_all.deb
apt-get update && apt-get install -y openjdk-7-jre-headless

vim /etc/logstash/conf.d/logstash.conf

input {
    file {
        path => "/var/log/apache/access.log"
        start_position => beginning
        ignore_older => 0
    }
}
filter {
    grok {
        match => { "message" => "%{COMBINEDAPACHELOG}"}
    }
    geoip {
        source => "clientip"
    }
}
output {
    elasticsearch {
         hosts => "es.malu.me:6585"
         user => "malu"
         password => "elk"
    }
}

启动:

/opt/logstash/bin/logstash -f /etc/logstash/conf.d/logstash.conf

离线日志采集

离线日志文件对应的默认的 $HOME/.sincedb_*文件删掉再用logstash采集

文档:

Logstash 最佳实践 http://udn.yyuap.com/doc/logstash-best-practice-cn/index.html

redis

可以用redis来实现分布式日志管理

参考这篇文章:http://git.malu.me/Redis客户端常用命令/

配置redis_index.conf文件,直接与elasticsearch通讯:

root@ubuntu:/etc/logstash/conf.d# cat redis_index.conf
input {
        redis {
                host => "localhost"
                port => 6379
                password => "redispassword"
                data_type => "list"
                key => "logstash:redis"
                type => "redis-input"
        }
}
filter {
    grok {
        match => { "message" => "%{COMBINEDAPACHELOG}"}
    }
    geoip {
        source => "clientip"
    }
}
output {
    elasticsearch {
        hosts => [ "localhost:9200" ]
    }
}

配置redis_cli.conf用于读取日志:

root@ubuntu:/etc/logstash/conf.d# cat redis_cli.conf 
input {
    file {
        path => "/var/log/nginx/access.log"
        start_position => beginning
        ignore_older => 0
    }
}
output {
        redis {
                host => "localhost:6379"
                password => "redispassword"
                data_type => "list"
                key => "logstash:redis"
        }
}

然后启动:

./logstash -f /etc/logstash/conf.d/redis_index.conf
./logstash -f /etc/logstash/conf.d/redis_cli.conf --http.port 9601   #启动第二个进程会提示9600端口占用,指定其他端口就可以了

中文文档:ELKstack 中文指南

ElasticSearch5监听外网端口

一般不建议把ElasticSearch监听放外网,但本人在终端环境下,用curl实在不爽。

首先拷贝配置文件:

cp /etc/elasticsearch/elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml

vim /usr/share/elasticsearch/config/elasticsearch.yml

network.host: 192.168.1.222
http.port: 9200
discovery.zen.minimum_master_nodes: 1    #这里设为1, 设3的话会导致Kibana报错

如果直接启动ElasticSearch会报错:

initial heap size [33554432] not equal to maximum heap size [522190848]; this can cause resize pauses and prevents mlockall from locking the entire heap
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
please set [discovery.zen.minimum_master_nodes] to a majority of the number of master eligible nodes in your cluster
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

有4个错误,我们一个个来解决:

initial heap size [33554432] not equal to maximum heap size [522190848]; this can cause resize pauses and prevents mlockall from locking the entire heap

这个错误是关于jvm内存分配的问题,需要设置的jvm配置:

cp /etc/elasticsearch/jvm.options /usr/share/elasticsearch/config/jvm.options

vim /usr/share/elasticsearch/config/jvm.options

-Xmx2g 改成 -Xmx256m ,也就是heap size [268435456] /1024/1024的值

第二个错误:

max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]

最大文件打开句柄数太少了,需要设置成65536:

cp /etc/security/limits.conf /etc/security/limits.conf.bak

vim /etc/security/limits.conf

malu hard nofile 65536
malu soft nofile 65536

其中malu是启动ElasticSearch的用户名

修改后重新登录malu用户,使用如下命令查看是否修改成功

[malu@localhost ~]$ ulimit -Hn 65536

第三个错误:

please set [discovery.zen.minimum_master_nodes] to a majority of the number of master eligible nodes in your cluster

配置文件elasticsearch.yml里设置:

discovery.zen.minimum_master_nodes: 1 

第四个错误:

max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

最大线程数设置过小,需要root用户来设置:

sysctl -w vm.max_map_count=262144

查看:

[root@localhost ~]# sysctl -a|grep vm.max_map_count
vm.max_map_count = 262144

下次启动这个设置会丢失,我们把它写入配置文件:

vim /etc/sysctl.conf

vm.max_map_count=262144  #添加这一行

以上文件解决后,elasticsearch就可以正常启动了。不过由于修改了监听地址,Kibana与它的通讯地址也得对应修改:

vim /etc/kibana/kibana.yml

elasticsearch.url: "http://192.168.1.222:9200"  #添加这一行

如果logstash配置了Redis与之通讯,那么同样也得修改:

output {
    elasticsearch {
        hosts => [ "192.168.1.222:9200" ]
    }
}

文档:

elasticsearch 集群传输端口配置官方文档

ELKstack 中文指南 : https://www.gitbook.com/book/chenryn/kibana-guide-cn/details

Elasticsearch 权威指南(中文版)

官网 : https://www.elastic.co

国内几个ELK相关博客:

http://chenlinux.com/

http://xiaorui.cc/category/elasticsearch/

http://bigbo.github.io/category/technology.html

Other

高性能的PHP日志系统—SeasLog

使用 Grafana、collectd 和 InfluxDB 打造现代监控系统

压力测试工具

JMeter

下载地址:https://jmeter.apache.org/download_jmeter.cgi

启动前需要配置Java环境:把JDK的bin路径加入系统PATH环境变量

如果需全局使用jmeter命令,把jmeter的bin路径加入系统PATH环境变量

命令参数说明:

    --?
            打印命令行选项并退出
    -h, --help
            打印使用信息并退出
    -v, --版本
            打印版本信息并退出
    -p, --propfile <参数>。
            要使用的jmeter属性文件
    -q, --addprop <参数>。
            附加的JMeter属性文件
    -t, --testfile <参数>。
            要运行的jmeter test(.jmx)文件。"-t LAST "将加载最后一个
            旧文件
    -l, --logfile <参数>。
            要记录样本的文件
    -i, --jmeterlogconf <参数>。
            jmeter日志配置文件(log4j2.xml)
    -j, --jmeterlogfile <参数>。
            jmeter运行日志文件(jmeter.log)
    -n,-nongui
            在非gui模式下运行JMeter
    -s, -server
            运行JMeter服务器
    -E, --proxyScheme <参数>。
            设置代理服务器要使用的代理方案。
    -H, --proxyHost <参数>。
            为JMeter设置一个代理服务器,以便使用
    -P, --proxyPort <参数>。
            设置JMeter使用的代理服务器端口
    -N, --nonProxyHosts <参数>。
            设置非代理主机列表(如*.apache.org|localhost)
    -u, --username <参数>。
            设置JMeter要使用的代理服务器的用户名。
    -a, --password <参数>。
            设置JMeter要使用的代理服务器的密码。
    -J, --jmeterproperty <argument>=<value>。
            定义其他JMeter属性
    -G, --globalproperty <argument>=<value>。
            定义全局属性(发送至服务器
            例如:-Gport=123
             或-Gglobal.properties
    -D, --systemproperty <argument>=<value>。
            定义额外的系统属性
    -S, --systemPropertyFile <参数>。
            附加的系统属性文件
    -f, --forceDeleteResultFile。
            强行删除现有的结果文件和网络报告文件夹,如果
             临阵磨枪
    -L, --loglevel <参数>=<值>。
            [category=]级别,如jorphan=INFO,jmeter.util=DEBUG或com.meter.util=DEBUG。
            .example.foo=WARN
    -r, --runremote
            启动远程服务器(定义在 remote_hosts 中)。
    -R, --remotestart <参数>。
            启动这些远程服务器(覆盖 remote_hosts)。
    -d, --homedir <参数>。
            使用jmeter主目录
    -X, --remoteexit
            测试结束后退出远程服务器(非GUI)。
    -g, --reportonly <参数>。
            只从测试结果文件中生成报告仪表板。
    -e, --reportatendofloadtests.
            负载测试后生成报告仪表板
    -o, --reportoutputfolder <参数>。
            报告仪表盘的输出文件夹 命令行测试,并生成报告:
jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]

例:

jmeter -n -t 测试计划.jmx -l results.log -e -o out

如何双击直接打开jmx文件?

双击 jmx 文件后, 选择bin下的文件 jmeter-t.cmd

webbench

webbench是Linux下的一个网站压力测试工具,最多可以模拟3万个并发连接去测试网站的负载能力。

下载地址:http://soft.vpser.net/test/webbench/webbench-1.5.tar.gz 解压后不到50K

安装

#tar zxvf webbench-1.5.tar.gz
#cd webbench-1.5
#make && make install

会在当前目录生成webbench可执行文件,直接可以使用了

用法:

webbench -c 并发数 -t 运行测试时间 URL

如:

webbench -c 5000 -t 120 http://www.163.com

AB

1.安装

apt-get install apache2-utils

2.使用

ab -n10000 -c9000 http://malu.me/

说明:

-n 代表请求数,-c 代表并发数

返回结果说明:

This is ApacheBench, Version 2.3 <$Revision: 1528965 $>       #apache的版本信息 
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests

​ ​ Server Software:
​ Server Hostname: 127.0.0.1 ​ Server Port: 80 ​ Document Path: / Document Length: 0 bytes #页面长度

Concurrency Level:      1000      #并发数 
Time taken for tests:   37.545 seconds   #共使用了多少时间 
Complete requests:      100000           #请求数 
Failed requests:        100000           #失败请求 
   (Connect: 0, Receive: 0, Length: 99712, Exceptions: 288)
Non-2xx responses:      99712
Total transferred:      33403520 bytes   #总共传输字节数,包含http的头信息等 
HTML transferred:       17649024 bytes   #html字节数,实际的页面传递字节数 
Requests per second:    2663.46 [#/sec] (mean)  #每秒多少请求,这个是非常重要的参数数值,服务器的吞吐量 
Time per request:       375.451 [ms] (mean)     #用户平均请求等待时间 
Time per request:       0.375 [ms] (mean, across all concurrent requests) #服务器平均处理时间,也就是服务器吞吐量的倒数 
Transfer rate:          868.84 [Kbytes/sec] received  #每秒获取的数据长度

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       12  178 109.6    184    1185
Processing:    21  196  44.4    196     315
Waiting:        0  146  41.9    136     274
Total:         87  374 116.6    382    1448

Percentage of the requests served within a certain time (ms)
  50%    382    # 50%的请求在382ms内返回 
  66%    388    # 66%的请求在388ms内返回 
  75%    395
  80%    400
  90%    409
  95%    452
  98%    474
  99%   1187
 100%   1448 (longest request)

3.参数使用说明

Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make at a time
    -t timelimit    Seconds to max. to spend on benchmarking
                    This implies -n 50000
    -s timeout      Seconds to max. wait for each response
                    Default is 30 seconds
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -B address      Address to bind to when making outgoing connections
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    -T content-type Content-type header to use for POST/PUT data, eg.
                    'application/x-www-form-urlencoded'
                    Default is 'text/plain'
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234'. (repeatable)
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                    Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                    are a colon separated username and password.
    -P attribute    Add Basic Proxy Authentication, the attributes
                    are a colon separated username and password.
    -X proxy:port   Proxyserver and port number to use
    -V              Print version number and exit
    -k              Use HTTP KeepAlive feature
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -q              Do not show progress when doing more than 150 requests
    -l              Accept variable document length (use this for dynamic pages)
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -r              Don't exit on socket receive errors.
    -h              Display usage information (this message)
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol
                    (SSL3, TLS1, TLS1.1, TLS1.2 or ALL)