Linux安装常用软件(CentOS)

最近在公司云服务器搭建应用,需要安装常用的软件,这里简要收集一些常用软件的安装方法。


安装ftp服务

1.yum安装

yum install vsftpd

2.查看安装路径

[root@kingson-test-fser6 ~]# which vsftpd
/usr/sbin/vsftpd

3. 查看ftp 服务器状态     

#service vsftpd status

4. 启动ftp服务器     

#service vsftpd start

4. 重启ftp服务器 

#service vsftpd restart

5. 查看服务有没有启动

#netstat -an | grep 21

6. 添加ftp用户

下面是添加ftpuser用户,设置根目录为/home/wwwroot/ftpuser,禁止此用户登录SSH的权限,并限制其访问其它目录。

(1)修改/etc/vsftpd/vsftpd.conf

将底下三行

  1. #chroot_list_enable=YES
  2. # (default follows)
  3. #chroot_list_file=/etc/vsftpd.chroot_list

改为

  1. chroot_list_enable=YES
  2. # (default follows)
  3. chroot_list_file=/etc/vsftpd/chroot_list

(2)编辑文件chroot_list:

  1. vi /etc/vsftpd/chroot_list

内容为ftp用户名,每个用户占一行,如:

peter
john

(3)重新启动vsftpd

  1. service vsftpd restart
--

若出现的错误

1、500 OOPS: cannot change directory
解决方法:

在终端输入命令:

  1. setsebool -P ftpd_disable_trans 1
  2. service vsftpd restart

就OK了!
原因:这是因为服务器开启了selinux,这限制了FTP的登录。


例子:

C:\Users\Kunxin>ftp 10.199.144.198
连接到 10.199.144.198。
220 (vsFTPd 2.2.2)
用户(10.199.144.198:(none)): kingson
331 Please specify the password.
密码:
230 Login successful.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory send OK.
ftp> pwd
257 "/"
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory send OK.
ftp> cd /user
550 Failed to change directory.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
tempftp
226 Directory send OK.
ftp: 收到 12 字节,用时 0.00秒 12.00千字节/秒。
ftp> pwd
257 "/"
ftp> lcd g:\
目前的本地目录 G:\。
ftp> get tempftp
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for tempftp (0 bytes).
226 Transfer complete.
ftp> quit



安装JDK

tar -zxvf jdk-7-linux-x64.tar.gz

1.解压到指定安装路径

tar -zxvf /home/kingson/jdk-7u71-linux-x64.gz -C /apps/svr/jdk

2.配置环境变量

unset i
unset pathmunge
export LANG=en_US.UTF-8

export JAVA_HOME=/apps/svr/jdk/jdk1.7.0_71 
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

"/etc/profile" 84L, 1964C written


例子:

[root@kingson-test-fser6 jdk1.7.0_71]# java -version
-bash: java: command not found
[root@kingson-test-fser6 jdk1.7.0_71]# source /etc/profile
[root@kingson-test-fser6 jdk1.7.0_71]# java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
[root@kingson-test-fser6 jdk1.7.0_71]# which java
/apps/svr/jdk/jdk1.7.0_71/bin/java
参考: http://www.cnblogs.com/samcn/archive/2011/03/16/1986248.html


安装mysql

1.yum安装

yum install mysql-server mysql-devel mysql

例子:

[root@kingson-test-fser6 profile.d]# which mysql
/usr/bin/mysql
[root@kingson-test-fser6 profile.d]#  /etc/rc.d/init.d/mysqld status
mysqld is stopped
[root@kingson-test-fser6 profile.d]# service mysqld start
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK
。。。。
[root@kingson-test-fser6 profile.d]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
。。。

2.修改密码:

设置mysql帐号
           mysql安装后默认生成两个帐号:一个是root,未设置密码,可以从本机登录到mysql;另一个是匿名帐号,无帐号名、无密码,可以从本机登录,未提供用户名的连接都将假定为此帐号。这样的设置存在着安全隐患,按下面的步骤进行更改。
           以root帐号连接到mysql服务器:
           mysql -u root 
           如果提示找不到mysql文件,请尝试使用绝对路径,如本文示例为:
           /usr/local/mysql/bin/mysql -u root 
           命令成功执行后将进入到mysql命令提示符下:
           mysql>
           (以下命令均在mysql命令提示符下执行)
           改变当前数据库为mysql:
           use mysql
           设置从本地主机登录的root帐号密码:
           set password for root@localhost=password('your password');
           或:
           update user set password=password('your password') where user='root' and host='localhost';
           删除匿名帐号: 
           delete from user where user='' ;
           删除密码为空的帐号:
           delete from user where password='';
           删除允许非localhost主机登录的帐号:
           delete from user where host<>'localhost' ;
           执行下面的命令使更改生效:
           flush privileges ; 
           执行下面的命令退出mysql命令行:
           quit
           或:

           /q

例子:

[root@kingson-test-fser6 profile.d]# mysql -u root -p mysql
Enter password: 
Reading table information for completion of table and column names


3. 本地计算机连接远程 mysql服务器:

./mysql -h "192.168.1.244" -u root -p

4.MySQL本地可以连接,远程连接不上的解决

解决方法: 
(1) 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改成"%"

mysql -u root -pvmwaremysql>use mysql;mysql>update user set host = '%' where user = 'root';mysql>select host, user from user;

(2)授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。 

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

例如:
如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

 

这个时候就会往mysql的user表里面添加一条数据:

INSERT INTO `user` VALUES ('%', 'root', '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', '0', '0', '0', '0');

如上图所示


安装SVN

1.yum安装

yum -y install subversion


2.查看版本

svnserve --version

2.查看安装路径

[root@kingson-test-fser6 ~]# which svn
/usr/bin/svn

参考:

http://www.cnblogs.com/jiqing9006/p/3370627.html 




安装git

 1.yum安装

yum install git

2.查看版本和安装路径

[root@kingson-test-fser6 yum.repos.d]# git --version
git version 1.7.1
[root@kingson-test-fser6 yum.repos.d]# which git
/usr/bin/git
3. 使用git

ssh-keygen -t rsa -C "kingson.wu@vipshop.com" 
Your public key has been saved in /root/.ssh/id_rsa.pub.
vi /root/.ssh/id_rsa.pub


安装tomcat

1.安装解压
tar zxvf /home/kingson/apache-tomcat-7.0.57.tar.gz -C /apps/svr
 mv apache-tomcat-7.0.57 tomcat
chmod +x /apps/svr/tomcat

如果不想修改文件目录名也可以创建软链接 ln -s apache-tomcat-7.0.55 tomcat7
2.
配置环境变量

export TOMCAT_HOME=/apps/svr/tomcat
export CATALINA_HOME=/apps/svr/tomcat
source /etc/profile


3.启动tomcat


[root@kingson-test-fser6 tomcat]# sh /apps/svr/tomcat/bin/startup.sh
Using CATALINA_BASE:   /apps/svr/tomcat
Using CATALINA_HOME:   /apps/svr/tomcat
Using CATALINA_TMPDIR: /apps/svr/tomcat/temp
Using JRE_HOME:        /apps/svr/jdk/jdk1.7.0_71
Using CLASSPATH:       /apps/svr/tomcat/bin/bootstrap.jar:/apps/svr/tomcat/bin/tomcat-juli.jar
Tomcat started.


4.设置UTF-8编码

server.xml:

 <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" 
               URIEncoding="UTF-8"  />

参考:http://blog.sina.com.cn/s/blog_866c5a5d0101cn1l.html

安装

下载tomcat:执行命令 wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.55/bin/apache-tomcat-7.0.55.tar.gz

解压tomcat到当前目录: tar -xvf apache-tomcat-7.0.55.tar.gz

修改文件目录名 mv apache-tomcat-7.0.55 tomcat7 

如果不想修改文件目录名也可以创建软链接 ln -s apache-tomcat-7.0.55 tomcat7

调整tomat运行内存,修改 tomcat7/bin/catalina.sh 文件,在脚本的最前边(不包括注释部分)增加一行:JAVA_OPTS='-Xms1024M -Xmx2048M -XX:PermSize=64M -XX:MaxPermSize=512M'

授予启动脚本执行权限:在tomcat7/bin目录执行chmod +x *.sh

启动tomcat:tomcat7/bin/startup.sh,在浏览器中访问http://server:port/ 查看tomcat是否启动成功。

查看tomcat运行日志: tail -f logs/catalina.sh

停止tomcat:./bin/shutdown.sh

修改绑定端口

修改conf/server.xml文件,修改冲突的端口,如果在同一台机器上运行多个tomcat一定要修改端口,注意修改所有端口,除了8080还有8009,8443

 

监控tomcat jvm

修改bin/catalina.sh文件,在脚本的最前边增加一行:

CATALINA_OPTS="$JAVA_OPTS -Djava.rmi.server.hostname=192.168.52.183 -Dcom.sun.management.jmxremote.port=9530 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

注意修改ip(tomcat所在机器)和端口(避免端口冲突),然后启动jvisualvm.exe(位于jdk的bin目录下),添加一个远程主机,主机名就填写上边配置的ip,就可以远程监控tomcat的jvm了

 

$ cat catalina.sh 
#!/bin/sh


CATALINA_OPTS=" -Djava.rmi.server.hostname=`/sbin/ifconfig bond0|grep -oE '([0-9]{1,3}\.?){4}'|head -n 1` -Dcom.sun.management.jmxremote.port=8060  -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"



、安装memcached

1.检查是否安装了libevent

rpm -q libevent  (首先检查系统是否安装了Libevent) 


2.yum自动安装:
yum info libevent libevent-devel
yum -y  install libevent libevent-devel
3.安装memcached
 
 
  1. # tar -zxvf memcached-1.4.5.tar.gz

  2. # cd memcached-1.4.5

  3. # ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/

  4. # make

  5. # make install

./configure --prefix=/apps/svr/memcached --with-libevent=/usr/make && make install

4.配置Memcached

(1)启动Memcached

 
 
  1. # cd /usr/local/memcached/bin/

  2. # ./memcached -u root -d

(2)将Memcached加入系统自动启动

 
 
  1. # vim /etc/rc.local

  2. # /usr/local/memcached/bin/memcached -u root -d

(3)查看Memcached

 
 
  1. # ps -ef |grep memcached

参考:http://www.centoscn.com/image-text/config/2013/0827/1459.html

5.查看状态:

[root@LinuxAS6-iCloud xinetd.d]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats
STAT pid 22362    //memcache服务器的进程ID  www.2cto.com  
STAT uptime 1469315    //服务器已经运行


、安装gcc

yum install gcc


安装gdb

yum install gdb


安装g++

yum install gcc-c++





、安装telnet


1、yum install telnet-server 服务端
2、yum install telnet 客户端
3、vi /etc/xinetd.d/telnet
service telnet
 
{
 
       flags              = REUSE
 
       socket_type     = stream       
 
       wait        = no
 
       user        = root
 
       server             = /usr/sbin/in.telnetd
 
       log_on_failure       += USERID
 
       disable           = yes
 
}
 
将disable项由yes改成no。

4、/etc/init.d/xinetd restart




、安装maven

1.解压到安装目录

tar -zvxf /home/kingson/apache-maven-3.2.5-bin.tar.gz -C  /apps/svr
mv apache-maven-3.2.5 maven

2.配置环境变量

export M2_HOME=/apps/svr/maven  

export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin

[root@kingson-test-fser6 maven]# source /etc/profile
[root@kingson-test-fser6 maven]# mvn -v

3. 查看 .m2目录


(1) #cd /home/apaduser/.m2  

(2) 如果没有.m2目录,则可以手动添加一个  

(3) #mkdir .m2  



十一、安装locate

1.yum安

yum install mlocate

2.
updatedb




十二、安装evil


[root@kingson-test-fser6 bin]# ll
total 28
-rw-r--r-- 1 root root  1827 Jan 19 14:09 config.sh
-rw-r--r-- 1 root root 23287 Jan 19 14:08 evil
[root@kingson-test-fser6 bin]# evil
-bash: /usr/local/bin/evil: Permission denied
[root@kingson-test-fser6 bin]# chmod u+x evil
[root@kingson-test-fser6 bin]# evil

/etc/profile


 rsync -avz root@10.199.144.198:/usr/local/bin/evil /usr/local/bin/evil




十三、中文乱码


yum groupinstall chinese-support

vi  /etc/sysconfig/i18n 

#LANG=en_US.UTF-8
LANG=zh_CN.UTF-8

参考:http://jingyan.baidu.com/article/ab69b270de8b4f2ca7189f1d.html




十四、安装证书

 keytool -import -trustcacerts -alias casserver -keystore "%JAVA_HOME%/jre/lib/security/cacerts" -file /apps/cas.oa.vipshop.com.cer -storepass changeit



十五 、安装lftp

lftp介绍:
lftp 是一个功能强大的下载工具,它支持访问文件的协议: ftp, ftps, http, https, hftp, fish.(其中ftps和https需要在编译的时候包含openssl库)。llftp的界面非常像一个shell: 有命令补全,历史记录,允许多个后台任务执行等功能,使用起来非常方便。它还有书签、排队、镜像、断点续传、多进程下载等功能。

lftp 安装:

yum -y install lftp

装好后看一下
# lftp -v

# man lftp


十六、安装tcpdump

yum install -y tcpdump

[root@kingson-test-fser6 conf]# tcpdump -i eth0 src host 192.168.33.174 and dst host 10.199.144.198 and dst port 8080
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
16:23:29.490545 IP 192.168.33.174.15352 > sort-mm.vip.vip.com.webcache: Flags [S], seq 1496287834, win 8192, options [mss 1460,nop,wscale 8,sackOK,TS val 71335404 ecr 0], length 0
16:23:29.490978 IP 192.168.33.174.15353 > sort-mm.vip.vip.com.webcache: Flags [S], seq 3562821585, win 8192, options [mss 1460,nop,wscale 8,sackOK,TS val 71335404 ecr 0], length 0
16:23:29.491452 IP 192.168.33.174.15352 > sort-mm.vip.vip.com.webcache: Flags [.], ack 71541349, win 260, options [nop,nop,TS val 71335404 ecr 894080840], length 0
16:23:29.491709 IP 192.168.33.174.15353 > sort-mm.vip.vip.com.webcache: Flags [.], ack 2803099819, win 260, options [nop,nop,TS val 71335404 ecr 894080840], length 0
16:23:29.503136 IP 192.168.33.174.15352 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 0:584, ack 1, win 260, options [nop,nop,TS val 71335405 ecr 894080840], length 584
16:23:29.538418 IP 192.168.33.174.15352 > sort-mm.vip.vip.com.webcache: Flags [.], ack 2681, win 260, options [nop,nop,TS val 71335409 ecr 894080886], length 0
16:23:41.503447 IP 192.168.33.174.15353 > sort-mm.vip.vip.com.webcache: Flags [F.], seq 0, ack 1, win 260, options [nop,nop,TS val 71336605 ecr 894080840], length 0
16:23:41.504519 IP 192.168.33.174.15353 > sort-mm.vip.vip.com.webcache: Flags [.], ack 2, win 260, options [nop,nop,TS val 71336605 ecr 894092853], length 0
16:23:49.542165 IP 192.168.33.174.15352 > sort-mm.vip.vip.com.webcache: Flags [.], ack 2682, win 260, options [nop,nop,TS val 71337409 ecr 894100890], length 0
16:23:51.504095 IP 192.168.33.174.15352 > sort-mm.vip.vip.com.webcache: Flags [F.], seq 584, ack 2682, win 260, options [nop,nop,TS val 71337605 ecr 894100890], length 0

连续多次访问:
[root@kingson-test-fser6 conf]# tcpdump -i eth0 src host 192.168.33.174 and dst host 10.199.144.198 and dst port 8080
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
16:28:25.496898 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [S], seq 859752711, win 8192, options [mss 1460,nop,wscale 8,sackOK,TS val 71365005 ecr 0], length 0
16:28:25.497114 IP 192.168.33.174.15506 > sort-mm.vip.vip.com.webcache: Flags [S], seq 4289592733, win 8192, options [mss 1460,nop,wscale 8,sackOK,TS val 71365005 ecr 0], length 0
16:28:25.497846 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 2026421015, win 260, options [nop,nop,TS val 71365005 ecr 894376846], length 0
16:28:25.498080 IP 192.168.33.174.15506 > sort-mm.vip.vip.com.webcache: Flags [.], ack 2924316261, win 260, options [nop,nop,TS val 71365005 ecr 894376846], length 0
16:28:25.498143 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 0:610, ack 1, win 260, options [nop,nop,TS val 71365005 ecr 894376846], length 610
16:28:25.533777 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 2681, win 260, options [nop,nop,TS val 71365008 ecr 894376882], length 0
16:28:26.393288 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 610:1220, ack 2681, win 260, options [nop,nop,TS val 71365094 ecr 894376882], length 610
16:28:26.420909 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 5361, win 260, options [nop,nop,TS val 71365097 ecr 894377769], length 0
16:28:26.944954 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 1220:1830, ack 5361, win 260, options [nop,nop,TS val 71365150 ecr 894377769], length 610
16:28:26.970914 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 8041, win 260, options [nop,nop,TS val 71365152 ecr 894378319], length 0
16:28:27.104821 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 1830:2440, ack 8041, win 260, options [nop,nop,TS val 71365166 ecr 894378319], length 610
16:28:27.136785 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 10721, win 260, options [nop,nop,TS val 71365169 ecr 894378485], length 0
16:28:27.256948 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 2440:3050, ack 10721, win 260, options [nop,nop,TS val 71365181 ecr 894378485], length 610
16:28:27.280253 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 13401, win 260, options [nop,nop,TS val 71365183 ecr 894378629], length 0
16:28:27.378350 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 3050:3660, ack 13401, win 260, options [nop,nop,TS val 71365193 ecr 894378629], length 610
16:28:27.401381 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 16081, win 260, options [nop,nop,TS val 71365195 ecr 894378750], length 0
16:28:27.528576 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 3660:4270, ack 16081, win 260, options [nop,nop,TS val 71365208 ecr 894378750], length 610
16:28:27.553433 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 18761, win 260, options [nop,nop,TS val 71365210 ecr 894378902], length 0
16:28:27.664100 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 4270:4880, ack 18761, win 260, options [nop,nop,TS val 71365221 ecr 894378902], length 610
16:28:27.686192 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 21441, win 260, options [nop,nop,TS val 71365224 ecr 894379035], length 0
16:28:27.800404 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 4880:5490, ack 21441, win 260, options [nop,nop,TS val 71365235 ecr 894379035], length 610
16:28:27.824704 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 24121, win 260, options [nop,nop,TS val 71365237 ecr 894379173], length 0
16:28:27.944948 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 5490:6100, ack 24121, win 260, options [nop,nop,TS val 71365250 ecr 894379173], length 610
16:28:27.976856 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 26801, win 260, options [nop,nop,TS val 71365253 ecr 894379325], length 0
16:28:28.060154 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 6100:6710, ack 26801, win 260, options [nop,nop,TS val 71365261 ecr 894379325], length 610
16:28:28.082877 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 29481, win 260, options [nop,nop,TS val 71365263 ecr 894379431], length 0
16:28:28.192432 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 6710:7320, ack 29481, win 260, options [nop,nop,TS val 71365274 ecr 894379431], length 610
16:28:28.212560 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 32161, win 260, options [nop,nop,TS val 71365276 ecr 894379561], length 0
16:28:28.328419 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 7320:7930, ack 32161, win 260, options [nop,nop,TS val 71365288 ecr 894379561], length 610
16:28:28.372468 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 34841, win 260, options [nop,nop,TS val 71365292 ecr 894379721], length 0
16:28:28.462140 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 7930:8540, ack 34841, win 260, options [nop,nop,TS val 71365301 ecr 894379721], length 610
16:28:28.491756 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 37521, win 260, options [nop,nop,TS val 71365304 ecr 894379840], length 0
16:28:28.594887 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 8540:9150, ack 37521, win 260, options [nop,nop,TS val 71365315 ecr 894379840], length 610
16:28:28.615595 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 40201, win 260, options [nop,nop,TS val 71365317 ecr 894379964], length 0
16:28:28.865390 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 9150:9760, ack 40201, win 260, options [nop,nop,TS val 71365342 ecr 894379964], length 610
16:28:28.889874 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 42881, win 260, options [nop,nop,TS val 71365344 ecr 894380238], length 0
16:28:29.033569 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [P.], seq 9760:10370, ack 42881, win 260, options [nop,nop,TS val 71365358 ecr 894380238], length 610
16:28:29.054905 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 45561, win 260, options [nop,nop,TS val 71365361 ecr 894380403], length 0
16:28:36.512546 IP 192.168.33.174.15506 > sort-mm.vip.vip.com.webcache: Flags [F.], seq 0, ack 1, win 260, options [nop,nop,TS val 71366106 ecr 894376846], length 0
16:28:36.515284 IP 192.168.33.174.15506 > sort-mm.vip.vip.com.webcache: Flags [.], ack 2, win 260, options [nop,nop,TS val 71366107 ecr 894387862], length 0
16:28:49.075345 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [.], ack 45562, win 260, options [nop,nop,TS val 71367363 ecr 894400424], length 0
16:28:56.514579 IP 192.168.33.174.15505 > sort-mm.vip.vip.com.webcache: Flags [F.], seq 10370, ack 45562, win 260, options [nop,nop,TS val 71368107 ecr 894400424], length 0

tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'

(nt: 可理解为, ip[2:2]表示整个ip数据包的长度, (ip[0]&0xf)<<2)表示ip数据包包头的长度(ip[0]&0xf代表包中的IHL域, 而此域的单位为32bit, 要换算

成字节数需要乘以4, 即左移2. (tcp[12]&0xf0)>>4 表示tcp头的长度, 此域的单位也是32bit, 换算成比特数为 ((tcp[12]&0xf0) >> 4) << 2, 
即 ((tcp[12]&0xf0)>>2). ((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0 表示: 整个ip数据包的长度减去ip头的长度,再减去
tcp头的长度不为0, 这就意味着, ip数据包中确实是有数据.对于ipv6版本只需考虑ipv6头中的'Payload Length' 与 'tcp头的长度'的差值, 并且其中表达方式'ip[]'需换成'ip6[]'.)

--


 sudo tcpdump -i any -Xnpls0 port 8888


-X    当分析和打印时, tcpdump 会打印每个包的头部数据, 同时会以16进制和ASCII码形式打印出每个包的数据(但不包括连接层的


头部).这对于分析一些新协议的数据包很方便.


-n  不对地址(比如, 主机地址, 端口号)进行数字表示到名字表示的转换.


-p  一般情况下, 把网络接口设置为非'混杂'模式. 但必须注意 , 在特殊情况下此网络接口还是会以'混杂'模式来工作; 从而, 


'-p' 的设与不设, 不能当做以下选现的代名词:'ether host {local-hw-add}' 或  'ether broadcast'(nt: 前者表示只匹配以太网


地址为host 的包, 后者表示匹配以太网地址为广播地址的数据包).


-l  对标准输出进行行缓冲(nt: 使标准输出设备遇到一个换行符就马上把这行的内容打印出来).在需要同时观察抓包打印以及保存


抓包记录的时候很有用. 比如, 可通过以下命令组合来达到此目的:
    ``tcpdump  -l  |  tee dat'' 或者 ``tcpdump  -l   > dat  &  tail  -f  dat''.(nt: 前者使用tee来把tcpdump 的输出同


时放到文件dat和标准输出中, 而后者通过重定向操作'>', 把tcpdump的输出放到dat 文件中, 同时通过tail把dat文件中的内容放到


标准输出中)


-s  snaplen
    设置tcpdump的数据包抓取长度为snaplen, 如果不设置默认将会是68字节(而支持网络接口分接头(nt: NIT, 上文已有描述,可搜


索'网络接口分接头'关键字找到那里)的SunOS系列操作系统中默认的也是最小值是96).68字节对于IP, ICMP(nt: Internet Control 


Message Protocol,因特网控制报文协议), TCP 以及 UDP 协议的报文已足够, 但对于名称服务(nt: 可理解为dns, nis等服务), NFS


服务相关的数据包会产生包截短. 如果产生包截短这种情况, tcpdump的相应打印输出行中会出现''[|proto]''的标志(proto 实际


会显示为被截短的数据包的相关协议层次). 需要注意的是, 采用长的抓取长度(nt: snaplen比较大), 会增加包的处理时间, 并且会


减少tcpdump 可缓存的数据包的数量, 从而会导致数据包的丢失. 所以, 在能抓取我们想要的包的前提下, 抓取长度越小越好.把


snaplen 设置为0 意味着让tcpdump自动选择合适的长度来抓取数据包.




-i  interface


    指定tcpdump 需要监听的接口.  如果没有指定, tcpdump 会从系统接口列表中搜寻编号最小的已配置好的接口(不包括 


loopback 接口).一但找到第一个符合条件的接口, 搜寻马上结束.


    在采用2.2版本或之后版本内核的Linux 操作系统上, 'any' 这个虚拟网络接口可被用来接收所有网络接口上的数据包(nt: 这会


包括目的是该网络接口的, 也包括目的不是该网络接口的). 需要注意的是如果真实网络接口不能工作在'混杂'模式(promiscuous)下


,则无法在'any'这个虚拟的网络接口上抓取其数据包.




[S]连接,[.]ack,[P.]对话,[F.]断开

十七 、安装tshark
yum install -y wireshark
实时打印当前http请求的url(包括域名)
# tshark -s 512 -i eth0 -n -f 'tcp dst port 8080' -R 'http.host and http.request.uri' -T fields -e http.host -e http.request.uri -l | tr -d '\t'

下面介绍参数含义:
-s 512 :只抓取前512个字节数据
-i eth0 :捕获eth0网卡
-n :禁止网络对象名称解析
-f 'tcp dst port 80' :只捕捉协议为tcp,目的端口为80的数据包
-R 'http.host and http.request.uri' :过滤出http.host和http.request.uri
-T fields -e http.host -e http.request.uri :打印http.host和http.request.uri
-l :输出到标准输出
3、实时打印当前mysql查询语句
tshark -s 512 -i eth0 -n -f 'tcp dst port 3306' -R 'mysql.query' -T fields -e mysql.query
下面介绍参数含义:
-s 512 :只抓取前512个字节数据
-i eth0 :捕获eth0网卡
-n :禁止网络对象名称解析
-f 'tcp dst port 3306' :只捕捉协议为tcp,目的端口为3306的数据包
-R 'mysql.query' :过滤出mysql.query
-T fields -e mysql.query :打印mysql查询语句
tshark使用-f来指定捕捉包过滤规则,规则与tcpdump一样,可以通过命令man pcap-filter来查得。
tshark使用-R来过滤已捕捉到的包,与界面板wireshark的左上角Filter一致。

参考:http://www.111cn.net/sys/linux/64057.htm 


tshark -s 512 -i eth0 -n -f 'tcp dst port 8080' -R 'http.host and http.request.uri andip.src' -T fields -e http.host -e http.request.uri -e ip.src -l | tr -d '\t'

参考:http://www.packetlevel.ch/html/tshark/tsharkfilt.html 


tshark 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -R'http.request.method == "POST" || http.request.method == "HEAD"||http.response' -V

十七、安装rz

yum install lrzsz -y 


wget http://download.redis.io/redis-stable.tar.gz

tar xvzf redis-stable.tar.gz

cd redis-stable

make

 

前面3步应该没有问题,主要的问题是执行make的时候,出现了异常。

异常一:

make[2]: cc: Command not found

异常原因:没有安装gcc

解决方案:yum install gcc-c++

 

异常二:

zmalloc.h:51:31: error: jemalloc/jemalloc.h: No such file or directory

异常原因:一些编译依赖或原来编译遗留出现的问题

解决方案:make distclean。清理一下,然后再make。

 

 

在make成功以后,需要make test。在make test出现异常。

异常一:

couldn't execute "tclsh8.5": no such file or directory

异常原因:没有安装tcl

解决方案:yum install -y tcl。

 

在make成功以后,会在src目录下多出一些可执行文件:redis-server,redis-cli等等。

方便期间用cp命令复制到usr目录下运行。

cp redis-server /usr/local/bin/

cp redis-cli /usr/local/bin/

然后新建目录,存放配置文件

mkdir /etc/redis

mkdir /var/redis

mkdir /var/redis/log

mkdir /var/redis/run

mkdir /var/redis/6379

 

在redis解压根目录中找到配置文件模板,复制到如下位置。

cp redis.conf /etc/redis/6379.conf

通过vim命令修改

daemonize yes

pidfile /var/redis/run/redis_6379.pid

logfile /var/redis/log/redis_6379.log

dir /var/redis/6379

最后运行redis:

$ redis-server /etc/redis/6379.conf


--
yum install nginx



----

使用htop查看和管理进程

你用哪个命令找出电脑上正在运行的进程的呢?我敢打赌是‘ps’并在其后加不同的参数来得到你所想要的不同输出。

安装‘htop’吧!绝对让你相见恨晚。

htop在终端中将进程以列表的方式呈现,有点类似于Windows中的任务管理器。你可以使用功能键的组合来切换排列的方式和展示出来的项。你也可以在htop中直接杀死进程。

在终端中简单的输入htop即可运行。

  
  
  1. htop

8. 使用ranger浏览文件系统

如果说htop是命令行进程控制的好帮手,那么ranger就是命令行浏览文件系统的好帮手。

你在用之前可能需要先安装,不过一旦安装了以后就可以在命令行输入以下命令启动她:

  
  
  1. ranger

在命令行窗口中ranger和一些别的文件管理器很像,但是相比上下结构布局,她是左右结构的,这意味着你按左方向键你将前进到上一个文件夹,而右方向键则会切换到下一个。

在使用前ranger的man手册还是值得一读的,这样你就可以用快捷键操作ranger了。


---

杀死挂起进程的简单方法

想象一下,你正在运行的应用程序不明原因的僵死了。

你可以使用‘ps -ef’来找到该进程后杀掉或者使用‘htop’。

有一个更快、更容易的命令叫做xkill。

简单的在终端中输入以下命令并在窗口中点击你想杀死的应用程序。

  
  
  1. xkill


---------

下载Youtube视频

一般来说我们大多数人都喜欢看Youtube的视频,也会通过钟爱的播放器播放Youtube的流媒体。

如果你需要离线一段时间(比如:从苏格兰南部坐飞机到英格兰南部旅游的这段时间)那么你可能希望下载一些视频到存储设备中,到闲暇时观看。

你所要做的就是从包管理器中安装youtube-dl。

你可以用以下命令使用youtube-dl:

   
   
  1. youtube-dl url-to-video

你可以在Youtubu视频页面点击分享链接得到视频的url。只要简单的复制链接在粘帖到命令行就行了(要用shift + insert快捷键哟)。



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值