首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

linux 务必命令

2012-11-01 
linux 必须命令xinetd????0:off????1:off????2:off????3:on????4:on????5:on????6:offvsftpd????0:off????

linux 必须命令
xinetd????0:off????1:off????2:off????3:on????4:on????5:on????6:off

vsftpd????0:off????1:off????2:off????3:off????4:off????5:off????6:off
xinetd based services:
????vsftpd:????on

defaults
{
????instances = 60
log_type = SYSLOG authpriv
log_on_success????????= HOST PID
log_on_failure????????= HOST
????cps????????????=50 10
}
includedir /etc/xinetd.d

servicevsftpd
{
socket_type = stream
wait = no
user = root
server = /usr/sbin/vsftpd
log_on_failure += USERID
????log_on_success +=DURATION USERID
????nice????????????=10
disable = no
}

事实上,在 Linux 系统中,要‘开或关某个 port ’,就是需要‘ 启动或关闭某个服务’啦!因此,你可以找出某个 port 对应的服务,程式对应的服务, 进而启动或关闭他,那么那个经由该服务而启动的 port ,自然就会关掉了!

/dev/null

由xinetd管理的服务会立即被 chkconfig影响。譬如,如果 xinetd在运行,finger被禁用,那么执行了 chkconfig finger on命令后, finger就不必手工地重新启动 xinetd来立即被启用。对其它服务的改变在使用chkconfig之后不会立即生效。你必须使用 service daemon stop 命令来停止个别服务。在前面的例子中,把 daemon换成你想停止的服务名称,如 httpd。把 stop 换成 start 或 restart来启动或重新启动该服务。

?

chown

当我们要改变一个文件的属组,我们所使用的用户必须是该文件的属主而且同时是目标属组成员,或超级用户。只有超级用户的才能改变文件的属主。

举例:将example.txt文件的属主改为linuxsirorg用户;

[root@localhost ~]# ls -l example.txt
-rw-r--r-- 1 root root 0 04-24 22:37 example.txt

[root@localhost ~]# ls -l example.txt
-rw-r--r-- 1 linuxsirorg root 0 04-24 22:37 example.txt

[root@localhost ~]# chown beinan:root example.txt
[root@localhost ~]# ls -l example.txt
-rw-r--r-- 1 beinan root 0 04-24 22:37 example.txt

chown 也提供了-R参数,这个参数对目录改变属主和属组极为有用,我们可以通过加-R参数来改变某个目录下的所有文件到新的属主或属组;

cpdatedf –hduexit(退出当前shell)fdisk

findpathname -options [-print -exec -ok ...]

find命令的参数;

pathname:find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。
-print: find命令将匹配的文件输出到标准输出。
-exec: find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'command' {} \;,注意{}和\;之间的空格。
-ok: 和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。

find命令选项

-name
按照文件名查找文件。
-perm
按照文件权限来查找文件。
-prune
使用这一选项可以使find命令不在当前指定的目录中查找,如果同时使用-depth选项,那么-prune将被find命令忽略。
-user
按照文件属主来查找文件。
-group
按照文件所属的组来查找文件。

-mtime -n +n
按照文件的更改时间来查找文件, - n表示文件更改时间距现在n天以内,+n表示文件更改时间距现在n天以前。find命令还有-atime和-ctime 选项,但它们都和-m time选项。
-nogroup
查找无有效所属组的文件,即该文件所属的组在/etc/groups中不存在。
-nouser
查找无有效属主的文件,即该文件的属主在/etc/passwd中不存在。
-newer file1! file2
查找更改时间比文件file1新但比文件file2旧的文件。
-type
查找某一类型的文件,诸如:
b - 块设备文件。
d - 目录。
c - 字符设备文件。
p - 管道文件。
l - 符号链接文件。
f - 普通文件。
-size n:[c] 查找文件长度为n块的文件,带有c时表示文件长度以字节计。
-depth:在查找文件时,首先查找当前目录中的文件,然后再在其子目录中查找。
-fstype:查找位于某一类型文件系统中的文件,这些文件系统类型通常可以在配置文件/etc/fstab中找到,该配置文件中包含了本系统中有关文件系统的信息。
-mount:在查找文件时不跨越文件系统mount点。
-follow:如果find命令遇到符号链接文件,就跟踪至链接所指向的文件。
-cpio:对匹配的文件使用cpio命令,将这些文件备份到磁带设备中。

另外,下面三个的区别:

?? -amin n
  查找系统中最后N分钟访问的文件
  -atime n
  查找系统中最后n*24小时访问的文件
  -cmin n
  查找系统中最后N分钟被改变文件状态的文件
  -ctime n
  查找系统中最后n*24小时被改变文件状态的文件
?? -mmin n
  查找系统中最后N分钟被改变文件数据的文件
  -mtime n
  查找系统中最后n*24小时被改变文件数据的文件

-exec –ok说明

-exec 参数后面跟的是 command命令,注意点如下:

command命令的终止,使用 ';' (分号)来判定,在后面必须有一个 ';'

'{}',使用{}来表示文件名,也就是find前面处理过程中过滤出来的文件,用于command命令进行处理

特别强调,对于不同的系统,直接使用分号可能会有不同的意义, 使用转义符 '\'在分号前明确说明

例子找出某目录下jsp文件中有203关键字的

find /usr/local/tomcat/webapps-name '*.jsp' -exec grep 203 {} \;

find /usr/local/tomcat/webapps-name '*.jsp' -print |xargs grep 203

查找系统中所有文件长度为0的普通文件,并列出它们的完整路径

find / -type f -size 0 -exec ls -l {} \;

查找当前文件系统中的所有目录并排序

find . -type d | sort

查找系统中的每一个普通文件,然后使用xargs命令来测试它们分别属于哪类文件

find . -type f -print | xargs file

free -mftp

ps –aux |grep XXX

pwdreboot 重新开机rm –fr 递归强制删除rmdirrpm

linux下的图形管理工具

?

侦测一个进程所需要的时间加上其他处理的时间的总和。不要和上面提到的date命令混淆。比如,我可以使用命令“time ls”来判断显示一个目录需要多长时间;或者我可以使用命令“time sleep10”来测试time命令(睡眠10秒钟,什么也不做)。

v?????开始标记文本。然后,移动光标

y?????复制被标记的文本

x?????剪切被标记的文本

p?????粘贴被剪切或复制的文本

在每个用户的主目录下,都有一个vi的配置文件".vimrc"(如果没有的话,可以手动创建)。用户可以编辑它,使对其的设置在每次启动vi时都成为有效的参数。如以下几个:

  setnu ----显示行号

  setnonu ? ----不显示行号

  setic ----查找时不考虑大小写

  setnoic ? ----查找时考虑大小写

  setsmartindent ? ----自动缩进

w命令也用于显示登录到系统的用户情况,但是与who不同的是,w命令功能更加强大,它不但可以显示有谁登录到系统,还可以显示出这些用户当前正在进行的工作,感觉比较实用

w 显示目前登入系统的用户信息wc(word count)whereis

whereis 是来寻找命令的二进制文件,同时也会找到其帮助文件;

比如我们不知道fdisk工具放在哪里,我们就可以用whereisfdisk 来查找;

[root@localhost ~]# whereis fdisk
fdisk: /sbin/fdisk /usr/share/man/man8/fdisk.8.gz

显示系统中有那些使用者正在上面,显示的资料包含了使用者 ID,使用的终端机,从那边连上来的,上线时间,呆滞时间,CPU使用量,动作等等。

whois

whois指令会去查找并显示指定帐号的用户相关信息,因为它是到Network?Solutions的WHOIS数据库去查找,所以该帐号名称必须在上面注册方能寻获,且名称没有大小写的差别。

yum

1.使用YUM查找软件包
命令:yumsearch <keyword>

例子同步时间

hwclock --systohc

按照硬件时钟设置系统时钟

date;hwclock;hwclock -s;date

删除所有符合要求文件

updatedb

locate–r ‘.*properties2.*’|grep tomcat|xargs rm

当复制1.1.txt到test文件夹失败时写入failure到2.txt

配置telnet

rpm –ivhtelnet-server-0.17-39.el5.i386.rpm

vi /etc/xinetd.d/telnet#启动

service xinetd restart

客户端访问时,不能使用root用户

开机进入文本模式

vi? /etc/inittab ,修改id:5:initdefault:为id:3:initdefault:,reboot就ok了

查看cpu使用情况,并输出到一个文本

top -n 1 |grep Cpu >cpu.log

查看cpu硬件情况

cat /proc/cpuinfo

配置sshd

vi /etc/ssh/sshd_config,修改以下内容

protocol ?2

permitRootLogin yes #启用ssh root登陆

PasswordAuthentication yes? #设置是否允许口令验证

PermitEmptyPasswords no #设置是否允许用口令为空的帐号登录。

如果想做到最大化安全链接,可以考虑在配置有双网卡的服务器上设置只允许内网链接SSH,方法很简单,在/etc/hosts.deny文件最后一行添加 一句sshd: ALL 然后在/etc/hosts.allow的最后一行加上一句sshd: 192.168.10. 然后保存退出。

#cd /etc/yum.repos.d/

#cp -a CentOS-Base.repoCentOS-Base.repo.bak

#vim CentOS-Base.repo

代码:

#CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
#baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

?

yum速度很快!大家可以试试。

查看系统中所有项目的hibernate配置文件中的连接字符串

??? <Connector port="8080"maxHttpHeaderSize="8192"

???????? maxThreads="150"minSpareThreads="25" maxSpareThreads="75"

?????? enableLookups="false"redirectPort="8443" acceptCount="100"

?????? connectionTimeout="20000"disableUploadTimeout="true"

?compression="on"compressionMinSize="2048"

???????? noCompressionUserAgents="gozilla,traviata"?compressableMimeType="text/html,text/xml"/>

加上后面几句红色的

重启tomcat

/usr/local/tomcat/bin/shutdown.sh

/usr/local/tomcat/bin/startup.sh

tomcat启动访问日志

?vi /usr/local/tomcat/conf/server.xml

启用以下内容,日志在logs目录

<ValveclassName="org.apache.catalina.valves.FastCommonAccessLogValve"

????????????????directory="logs"?prefix="localhost_access_log." suffix=".txt"

????????????????pattern="combined" resolveHosts="false"/>

?

配置vncserver

启动vncserver服务

?[root@zdtech init.d]# vncserver
New 'zdtech:2 (root)' desktop is zdtech:2

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/zdtech:2.log

在Windows使用VNC viewer登录了

输入服务器地址:192.168.10.22:2就可以登陆了,但是现在还不是进入的桌面系统修改配置文件/root/.vnc/xstartup,使之与下面内容相同

?[root@zdtech init.d]# vi /root/.vnc/xstartup

#!/bin/sh

# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &

修改后再次运行vncserver命令

[linuxzgf@linuxzgf~]$ vncserver

New'localhost.localdomain:1 (test)' desktop is localhost.localdomain:2

Startingapplications specified in /home/test/.vnc/xstartup

Logfile is /home/test/.vnc/localhost.localdomain:2.log

如果要杀掉vncserver 进程,可执行vncserver :1 kill ,1表示display的ID号

配置apache awstats

Awstats是一个非常方便的web统计访问工具,它分析apache或者tomcat产生的日志,得出访问统计信息。

下载awstats并安装

wget http://prdownloads.sourceforge.net/awstats/awstats-6.9-1.noarch.rpm

rpm -ivh awstats-6.9-1.noarch.rpm

cd /usr/local/awstats/tools

配置1

在执行perl awstats_configure.pl的过程中会出现一个错误,

Error: Failed to open'/usr/share/doc/awstats/examples/wwwroot/cgi-bin/awstats.model.conf' for read.

可以再执行命令前把awstats.model.conf文件,在安装包中找出此文件并复制到/etc/awstats目录下

perl awstats_configure.pl #开始配置

?

?

-----> Need to create a new config file ?

Do you want me to build a new AWStats config/profile

file (required if first install) [y/N] ? y

-----> Define config file name to create

What is the name of your web site or profile analysis ?

Example: www.mysite.com

Example: demo

Your web site, virtual server or profile name:

> cqmc

-----> Define config file path

In which directory do you plan to store your config file(s) ?

Default: /etc/awstats

Directory path to store config file(s) (Enter for default):

>

-----> Create config file '/etc/awstats/awstats.cqmc.conf'

?Config file/etc/awstats/awstats.cqmc.conf created.

-----> Add update process inside a scheduler#添加一个定时任务,比如每日更新日志

Sorry, configure.pl does not support automatic add to cron yet.

You can do it manually by adding the following command to your cron:

/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=cqmc

Or if you have several config files and prefer having only one command:

/usr/local/awstats/tools/awstats_updateall.pl now

Press ENTER to continue...

?

A SIMPLE config file has been created: /etc/awstats/awstats.cqmc.conf

You should have a look inside to check and change manually mainparameters.

You can then manually update your statistics for 'cqmc' with command:

> perl awstats.pl -update -config=cqmc

You can also read your statistics for 'cqmc' with URL:

> http://localhost/awstats/awstats.pl?config=cqmc

Press ENTER to finish...

执行完毕。

查看新日志是否生效

cd /usr/local/apache/

rm –rf logs/access_log#删除访问日志,以前的日志不符合awstats分析日志要求

cd bin

./ apachectl -k restart#重启apache

more ../logs/access_log#查看新日志是否生效,可以自己用浏览器访问看看

配置2

vi /etc/awstats/ awstats.cqmc.conf

- LogFile????????? 指定web server紀錄檔存放的位置。/usr/local/apache/logs/access_log

- LogFormat? 檢查參數值是否為 "1" 。

- DNSLookup????????? 將參數值設定為 “1” 。

- DirData????????????????? 指定存放統計資料的位置。/usr/local/apache/logs

- DirCgi??????????? 指定CGI程式所在的位置。/usr/local/apache/cgi-bin

- DirIcons??????? 指定小圖示所在的位置。

/usr/local/apache/icons

- SiteDomain 網站主機名稱。cqmc

-HostAliases? 设定主机别名

更新awstats分析日志数据

cd /usr/local/awstats/wwwroot/cgi-bin

perl awstats.pl -update -config=cqmc

访问awstats分析数据

http://localhost/awstats/awstats.pl?config=cqmc

定时自动更新统计数据

vi /etc/crontab

#加入如下代码

00 2 * * * root /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update-config=cqmc

#每天2:00更新统计数据

service crond restart#重启crond服务

?

配置访问权限

htpasswd -c /usr/local/apache/passwd/passwords rbowen

?

# htpasswd -c /usr/local/apache/passwd/passwords rbowen

New password: mypassword

Re-type new password: mypassword

Adding password for user rbowen

?

AuthType Basic

AuthName "Restricted Files"

AuthUserFile /usr/local/apache/passwd/passwords

Require user rbowen

wget http://www.it-adv.net/fetion/fetion_linux_20080402.tar.gz

tar xvf fetion_linux_20080402.tar.gz

ldd sms

cp *.* /lib/

cp *.* /usr/lib/

飞信使用

./sms -f 13594745404 -p 520167qb-t 13594745404 -m hello

./sms -f 13594745404 -p 520167qb-t 13594745404 -i 1.txt

mknod?/tmp/mypipe?p
exp?userid=scott/tiger?file=/tmp/mypipe?&
gzip?<?/tmp/mypipe?>?exp.dat.gz
rm?/tmp/mypipe

mknod?/tmp/mypipe?p
imp?userid=scott/tiger?file=/tmp/mypipe?&
gunzip?<?exp.dat.gz?>?/tmp/mypipe
rm?/tmp/mypipe

查看操作系统位数

wget http://prdownloads.sourceforge.net/webadmin/webmin-1.470-1.noarch.rpm

rpm -ivh webmin-1.470-1.noarch.rpm

/etc/init.d/crond restart

service crond restart

chkconfig--levels 35 crond on

?

1 * * * * root run-parts/etc/cron.hourly? 注:表示每个小时的第一分钟,开始执行/etc/hourly目录下的可执行程序或脚本;
2 4 * * * root run-parts /etc/cron.daily? 注:表示每天的4点2分,开始执行/etc/cron.daily目录下的可执行程序或脚本;
22 4 * * 7 root run-parts /etc/cron.weekly 注:每年第7个周4点我22分,开始执行 /etc/cron.weekly目录下的可执行程序或脚本;
42 4 1 * * root run-parts /etc/cron.monthly 注:每月第1天的4点42分,开始执行/etc/cron.monthly目录下的可执行程序或脚本;

?

分钟 小时 日? 月? 周?? [用户名]? 命令

sysstat的主要用途就是观察服务负载,比如CPU和内存的占用率、网络的使用率以及磁盘写入和读取速度等。

这个包一但安装下去,一般包括如下的几个命令可以使用。

Sar、iostat、sa1、sa2、sadf、mpstat、sadc、sysstat

安装

wget http://pagesperso-orange.fr/sebastien.godard/sysstat-9.0.5.tar.gz

tar -zxvfsysstat-9.0.5.tar.gz

cd sysstat-9.0.5

./configure

make

make install

?

lambda probe

cd /usr/local/tomcat/webapps

wget http://www.lambdaprobe.org/downloads/1.7/probe.1.7b.zip

unzip probe.1.7b.zip

vi /usr/local/tomcat/conf/tomcat-users.xm

#添加如下行,probe的用户名和登陆密码

<user username="admin" password="admin1234"roles="manager"/>

#在catalina.sh中加入,启用jmx

JAVA_OPTS? -Dcom.sun.management.jmxremote

?

安装groovy

wget http://dist.groovy.codehaus.org/distributions/groovy-binary-1.7.0.zip

cp groovy-binary-1.7.0.zip /usr/local/

unzip groovy-binary-1.7.0.zip

vi /etc/profile

export GROOVY_HOME=/usr/local/groovy-1.7.0

export PATH=$GROOVY_HOME/bin:$PATH

使环境变量生效

. /etc/profile

[root@cqmc-web1 groovy-1.7.0]# groovy -version

Groovy Version: 1.7.0 JVM: 1.5.0_21

vi? test.groovy

#!/bin/env groovy

println 'hello'

热点排行