1。SSH登录提示:** !! ILLEGAL HOST KEY FOR
172.16.25.3 !! **
Remove /root/.ssh2/hostkeys/key_36000_172.16.25.3.pub and try
again if you think that this is normal.
Disconnected; host key not verifiable (Illegal host key.).
处理办法: rm
/root/.ssh2/hostkeys/key_36000_172.16.25.3.pub
然后ssh登录上去
2。DB查询:
select * from host, hostgroup where
host.host_name=hostgroup.host_name and
hostgroup.group_name='host_qqdisK';
select * from host_serveroa where business='QQDisk';
左连接查询:仅仅在表service的记录
select host_serveroa.host_ip from
host_serveroa left join service on
service.host_name=host_serveroa.host_ip where
service_name like "%disk%";
3。DB恢复:
有索引的表导入数据要慢,innodb类型的表导入数据要慢。
mysql> load data infile '/home/freeluo/number'
into table dbtest.host;
Query OK, 20000 rows affected (0.14 sec)
Records: 20000 Deleted: 0 Skipped: 0 Warnings: 0
./mysqladmin -h 127.0.0.1 -uroot --port=3333 flush-tables
myisamchk -rq /home/freeluo/mysql/var/dbtest/host
myisamchk --keys-used=0 -rq
/home/freeluo/mysql/var/dbtest/host
system("mysql -uroot -e "load data infile '$db_dir/$txt[$cnt]'
into table $db_name.$table" ");
system("cd $db_dir
2>>db_recover.elog; mysqlimport -f
$db_name $txt[$cnt]
2>>db_recover.elog");
mysqlimport --socket=/tmp/freeluo.sock --port=3333
-uroot -f dbtest host.txt;
4.db检查和修复:
mysql> repair table t_pay_water_2;
mysqlcheck -A --auto-repair
myisamchk
mysqladmin flush-tables
检查:./myisamchk -c
/usr/local/mysql/data/index_db0/t_china_mobile_oil_history_6
修复:./myisamchk -r
/usr/local/mysql/data/index_db0/t_china_mobile_oil_history_6
5。文件修复:
例如:分区/dev/sda1上的文件系统坏了,先
umount /dev/sda1
fsck -y /dev/sda1
6.快速挂载nfs文件系统:
rpc.portmap;
mount -a -t nfs;
7.产生core文件以及察看core文件:
ulimit -c unlimited
file core得到导致core的文件名
gdb -core core 文件名
where 查到具体的位置。
8.程序性能分析:
有两个工具:
Time progame_name;
gprof . gprof要求在编译的时候添加-pg选项
9.shell文本处理:
文本最后要多一行!
1)批量替换目录文件中的某个字符串:
perl -pi -e 's/index.html/index.jsp/g' $(find . -name "*.html")
2)递归查询当前目录和子目录文件中特定的字符串:
grep -r test .
10.解决局域网内盗用IP:
捆绑IP和MAC地址:ARP -s 192.168.10.59 00
-50-ff-6c-08-75
解除网卡的IP与MAC地址的绑定: arp
-d 网卡IP
11.查看 Linux
启动时的信息:
dmesg,用dmesg |more可能看的更仔细
12.处理文件名内含有特殊字符的文件
如果有一个文件名叫 -file 如果想删除它,键入 rm -file 会显示 invalid option
,原来由于文件名的第一个字符为 - , Linux 把文件名当作选项了,可以加 -- 解决 这个问题, 如 rm -- -file
。如果是其他特殊字符的话可 以在特殊字符前加一个,或者用双引号把整个文件名括起来。
13.ip配置:
1. ifconfig eth0 219.133.38.151 netmask 255.255.255.0
2. 设置默认网关 route add default gw
208.164.186.1
3. 修改/etc/rc.d/rc.inet1
14.在线安装卸载一块新硬盘:
echo "scsi add-single-device 1 0 1 0" >
/proc/scsi/scsi
fdisk /dev/sdb;
mke2fs -j /dev/sdb1
mkdir /data1;
mount -t ext3 /dev/sdb1 /data1
卸载:echo "scsi remove-single-device 1 0 1 0" >
/proc/scsi/scsi
15.在线对数据分区设置noatime:
修改/etc/fstab , 把数据分区的mount参数 "defaults" ->
"noatime"
例如:/dev/cciss/c0d0p4 /data ext3 noatime 1 2
在线修改数据分区mount参数:
mount -o noatime,remount /data
16.路由设置:
route del -net 172.30.0.0/20
route add -net 172.30.0.0/16 gw gw_ip
/etc/rc.d/rc.inet1 /sbin/route add -net
172.30.0.0/16 gw gw_ip eth1
17.关于nfs
server端的配置:
1. mount磁盘的时候加noatime,mount nfs的时候不需要
2. 删除updatedb/slocate
3. NFS线程数设到client的数以上。修改 /etc/rc.d/rc.nfsd 文件
18.Mysql和apache绑定ip
My.cnf [mysqld]下面新增一行:
bind_address = 172.16.25.65
Httpd.conf
BindAddress 172.16.25.38
19.正则表达式匹配:
在文件中查找 *.*.*.*:*
egrep
"[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[:][0-9]"
text
递归查询内容: grep -r test *
20.查询当前目录大小:
du -m --max-depth=1
21.编译内核:
make mrproper用于清楚原来编译过的信息
make
menuconfig用于进行编译前的内核配置,生成一个.config文件,我们也可以拷贝别人生成的.config文件,这样不用自己配置
make dep用于生成依赖文件
#make all 编译
make bzImage
cp bzImage到/boot下
修改/etc/lilo.conf文件
运行lilo
22.iptables使用:
服务器上丢弃来自172.30.21.176上的任何包:
iptables -A INPUT -s 172.30.21.176 -j DROP
iptables -A INPUT -s 172.30.21.176 -p tcp --dport 56000 -j
DROP
保存&恢复规则
iptables-save
> iptables-script
iptables-restore
iptables-script
smbmount //172.30.20.21/vss -U vss
super block 是可以修复的,用fsck -b
23.如何看当前的系统是否带epoll:
cat /proc/filesystems|grep eventpollfs
结果中有上面这行就代表已经有epoll了。
24.获取特定的时间:
三天前的时间:date +%Y%m%d -d'-3 day'
格式:09/Aug/2010: date +%d/%b/%Y
25。搭建rsync Server:
mkdir -p /data/update
chown nobody:users /data/update
chmod 774 /data/update
mkdir /data/rsyncd_log
rsync 172.16.27.91::update/freeluo/rsync_conf/* /etc
rsync --daemon --address=
26.定时重启并广播消息:
shutdown -r +10 'reboot
after 10 minutes'
(-f -F)确认是否重启时自检
shutdown -h +1 'shutdown
after 1 minute'
27.单用户模式登陆系统:
boot:linux -s
28.windows强行终止进程:
ntsd -c q -p pid号
29.静态编译源文件的包:
make LDFLAGS="-static"
jxvf .bz2
LDFLAGS="-static"
DESTDIR=/foo
export LDFLAGS DESTDIR
./configure
make
make install
30.一网卡绑定多个ip:
ifconfig eth1:5 192.168.66.189
31.ext2转换到ext3:
tune2fs -j /dev/sdd1
32.清理ARP
cache:
Arp -d 网关
33.df和du查看的容量差异很大,解决办法:
要查查看是什么问题应起了?
1. 文件系统问题,导致df数据不对,需要fsck
2. 大日志文件被删除,但文件没有关闭空间没有释放,重起服务
大日志文件被删除,这个怎么确定呢?
这个比较难确定。你用 lsof -n | grep deleted看看。这个命令很耗资源,如果系统忙就不要用。
34.时区调整:
找到相应的时区文件 /usr/share/zoneinfo/Asia/Shanghai
用这个文件替换当前的/etc/localtime文件。
35.使用exec或ok来执行find命令:
为了用ls -l命令列出所匹配到的普通文件
find . -type f -exec ls -l {} ;
在当前目录中查找所有文件名以.logG结尾、更改时间在5日以上的文件,并删除它们,只不过在删除之前先给出提示。
find . -name "*.log" -mtime +5 -ok rm {} ;
find . -name "*.html" -mtime
+1 -exec ls -l {} ;
36.怎样把子shell中的变量传回父shell?
A: 例如(echo "$a") | read b不能工作,如何找到一个替代方案?下面给出一些可能的方案:
1.使用临时文件
...
#in subshell
a=100
echo "$a">tmpfile
...
#in parent
read b
2.使用命名管道
mkfifo pipef
(...
echo "$a" > pipef
...)
read b
3.使用coprocess(ksh)
( echo "$a" |&)
read -p b
4.使用命令替换
b=`echo "$a"`
5.使用命令
`echo "b=$a"`
6.使用here document
read b <
`echo "$a"`
END
37.定时启动任务
crontab -e
min hour day week month ~/shellname.sh
38.squid缓存清理:
在线:
squidclient
-m PURGE -p 80
URL
/usr/local/bin/clear_squid_cache.sh jpg
/usr/local/bin/clear_squid_cache.sh
music.ovi.com.cn
显示当前缓存
/usr/sbin/purge -p localhost:80 -c /etc/squid/squid.conf -e
.
清除当前所有缓存
/usr/sbin/purge -p localhost:80 -c
/etc/squid/squid.conf
-P 1 -e .
/usr/sbin/purge -p
localhost:80 -c /etc/squid/squid.conf -P 1 -e
jpg.
离线:
关闭squid后清除缓存目录
39.squid命中率查询
*取得squid运行状态信息:
squidclient -p 80 mgr:info
*取得squid内存使用情况: squidclient -p 80 mgr:mem
*取得squid已经缓存的列表: squidclient -p 80 mgrbjects. use it carefully,it
may crash
*取得squid的磁盘使用情况: squidclient -p 80 mgr:diskd
*强制更新某个url:squidclient -p 80 -m PURGE http://www.yejr.com/static.php
*更多的请查看:squidclient
-h
或者 squidclient -p 80 mgr:
40.建立SSH的信任关系:
目标:
HostA 访问HostB,hostC不需要键入密码,以root用户为例:
第一步 在HostA上生成key:
HostA# ssh-keygen
-d
全部回车
产生id_dsa 和id_dsa.pub
第二步 将生成的id_dsa.pub传到B,C的/root/.ssh目录下,并且重命名为authorized_keys
HostA# scp -P 22
/var/log/nagios/.ssh/id_rsa.pub
ip:/var/log/nagios/.ssh/authorized_keys
第三步,从A登录B and C
41.memcached命中率查询:
memcached-tool localhost:11211 stats
一、缓存命中率 = get_hits/cmd_get * 100%
二、get_misses的数字加上get_hits应该等于cmd_get
三、total_items == cmd_set ==
get_misses,当可用最大内存用光时,memcached就会删掉一些内容,等式就会不成立
42.linux版本查询:
lsb_release
-a
43.何在虚拟机linux下挂载windows分区?
执行下面命令即可:
mount -t cifs //server/share /mnt/point -o
user=me,password=mine
注:server-----为要挂载PC的IP
share------为windows下的分区(或共享文件名)
point-------为挂载点
user,password------为linux下的用户及密码
例:#mount -t cifs //10.0.0.127/kinder /mnt/hdc7 -o
user=root,password=88888888