用sed合并行
tr -d '\n' <file
cat file | xargs echo
echo $(<file)
cat file | paste -s -d ""
删除空格
tr -d ' '
Submitted by admin on 2010, February 25, 8:37 PM
用sed合并行
tr -d '\n' <file
cat file | xargs echo
echo $(<file)
cat file | paste -s -d ""
删除空格
tr -d ' '
Submitted by admin on 2009, November 23, 2:58 PM
在考虑添加内存的时候,经常需要清楚服务器最大支持多少内存,已经有多少内存。有多少插槽,已经用了几个插槽,但这原来一般都需要打开机箱查看同时参考原厂资料,非常麻烦。偶经过一段时间琢磨、试验,发现通过dmidecode的信息可以搞定以上的事情。
l 内存的插槽数,已经使用多少插槽.每条内存多大,已使用内存多大
dmidecode |grep -P -A 5 "Memory/s+Device"|grep Size:|grep -v Range
例:
#dmidecode |grep -P -A 5 "Memory/s+Device"|grep Size:|grep -v Range
Size: 512 MB
Size: 512 MB
Size: No Module Installed
Size: No Module Installed
说明该服务器:
有4个内存插槽
已经使用2个内存插槽
每条内存容量512M
还有2个内存插槽可用
2 支持的最大内存容量
dmidecode |grep -P "Maximum/s+Capacity"
例:
# dmidecode |grep -P "Maximum/s+Capacity"
Maximum Capacity: 4 GB
说明该服务器支持的最大内存容量是4GB
同时由此可以得出该服务器支持的单条内存最大容量是1G
Submitted by admin on 2009, September 21, 1:38 PM
Linux下如何查看CPU信息, 包括位数和多核信息
# uname -a
Linux euis1 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux
(查看当前操作系统内核信息)
# cat /etc/issue | grep Linux
Red Hat Enterprise Linux AS release 4 (Nahant Update 5)
(查看当前操作系统发行版信息)
# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
8 Intel(R) Xeon(R) CPU E5410 @ 2.33GHz
(看到有8个逻辑CPU, 也知道了CPU型号)
# cat /proc/cpuinfo | grep physical | uniq -c
4 physical id : 0
4 physical id : 1
(说明实际上是两颗4核的CPU)
# getconf LONG_BIT
32
(说明当前CPU运行在32bit模式下, 但不代表CPU不支持64bit)
# cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l
8
(结果大于0, 说明支持64bit计算. lm指long mode, 支持lm则是64bit)
最后再完整看cpu物理信息, 不过大部分我们都不关心而已.
# dmidecode | grep -A48 'Processor Information$'
Submitted by admin on 2009, August 25, 1:22 PM
从 七猫的藏经阁 作者:Diviner
To support over 500k users, you *need*
- A 64 bits hardware/kernel (AMD64, Opterons)
- At least 8GB of ram
- A recent linux kernel (2.6.x)
About tuning, I prefer to not fully disclose them because servers are targets of many attacks, so it's better not help hackers.
The most touchy thing is the IP route cache : You have to tune it or else the machine drops many connections
(hint : rhash_entries=... in the boot append string)
hints :
echo 1 > /proc/sys/net/ipv4/route/gc_interval
echo 150 >/proc/sys/net/ipv4/route/gc_timeout
echo 2 >/proc/sys/net/ipv4/route/gc_elasticity
- Use of hugeTLB pages
hint :
echo xxx >/proc/sys/vm/nr_hugepages
Tune tcp :
echo "4096 49152 131072" >/proc/sys/net/ipv4/tcp_wmem
echo xxxx >/proc/sys/net/ipv4/tcp_max_syn_backlog
echo xxxx >/proc/sys/net/core/somaxconn
echo 1200000 > /proc/sys/net/ipv4/tcp_max_tw_buckets
echo 7 >/proc/sys/net/ipv4/tcp_retries2
echo "600000 650000 700000" >/proc/sys/net/ipv4/tcp_mem
echo 0 >/proc/sys/net/ipv4/tcp_timestamps
echo 0 >/proc/sys/net/ipv4/tcp_window_scaling
echo 0 >/proc/sys/net/ipv4/tcp_sack
echo 330000 >/proc/sys/net/ipv4/tcp_max_orphans
echo "10000 62000" >/proc/sys/net/ipv4/ip_local_port_range
others :
echo 1300000 >/proc/sys/fs/file-max
相关网址
http://hi.baidu.com/linux_kernel/blog/item/8cedeaf81c3c150fd8f9fd7d.html
Submitted by admin on 2009, August 11, 3:41 PM
1. 自动ssh/scp方法==
A为本地主机(即用于控制其他主机的机器) ;
B为远程主机(即被控制的机器Server), 假如ip为192.168.60.110;
A和B的系统都是Linux
在A上运行命令:
# ssh-keygen -t rsa (连续三次回车,即在本地生成了公钥和私钥,不设置密码)
# ssh root@192.168.60.110 "mkdir .ssh" (需要输入密码)
# scp ~/.ssh/id_rsa.pub root@192.168.60.110:.ssh/id_rsa.pub (需要输入密码)
在B上的命令:
# touch /root/.ssh/authorized_keys (如果已经存在这个文件, 跳过这条)
# cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys (将id_rsa.pub的内容追加到authorized_keys 中)
回到A机器:
# ssh root@192.168.60.110 (不需要密码, 登录成功)
2. 控制n个机器如上所述自动登录
那就需要n对钥匙(密钥和公钥), ssh-keygen 命令可以随意更改钥匙对的名字, 比如:
# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa_192.168.60.110
这样私钥和公钥的名字分别就是: id_rsa_192.168.60.110和 id_rsa_192.168.60.110.pub;然后将 id_rsa_192.168.60.110.pub 文件的内容, 追加到sever的 ~/.ssh/authorized_keys文件中,最后, 在本地用ssh命令的 -i 参数指定本地密钥, 并登录:
# ssh -i /root/.ssh/id_rsa_192.168.60.110 someone@192.168.60.110
scp也是一样的
# scp -i /root/.ssh/id_rsa_192.168.60.110 filename someone@192.168.60.110:/home/someone
在文件.bashrc中加下两行,每次做同样的操作就不用敲入这样长的命令了:
alias sshcell='ssh -i /root/.ssh/id_rsa_192.168.60.110 someone@192.168.60.110'
alias scpcell='scp -i /root/.ssh/id_rsa_192.168.60.110 filename someone@192.168.60.110:/home/someone'
这样,直接键入一下指令实现ssh和scp自动登录:
# sshcell
# scpcell
3. 自动ssh/scp脚本
如果需要从A,到B,然后才能够到C,那么需要ssh和scp两次,是比较麻烦的。
ssh自动登录:
#!/usr/bin/expect -f
set timeout 30
spawn ssh weiqiong@B
expect "password:"
send "pppppp\r"
expect "]*"
send "ssh weiqiong@C\r"
expect "password:"
send "pppppp\r"
interact
scp从A拷贝文件到C:
#!/usr/bin/expect -f
set timeout 300
set file [lindex $argv 0]
spawn scp $file weiqiong@B:/home/weiqiong
expect "password:"
send "pppppp\r"
expect "]*"
spawn ssh weiqiong@B
expect "password:"
send "pppppp\r"
expect "]*"
send "scp $file weiqiong@C:/home/weiqiong\r"
expect "password:"
send "pppppp\r"
expect "]*"
exit
interact
scp从C拷贝文件到A:
#!/usr/bin/expect -f
set timeout 300
set file [lindex $argv 0]
spawn ssh weiqiong@B
expect "password:"
send "pppppp\r"
expect "]*"
send "scp weiqiong@C:/home/weiqiong/$file .\r"
expect "password:"
send "pppppp\r"
expect "]*"
send "exit\r"
expect "]*"
spawn scp weiqiong@B:/home/weiqiong/$file .
expect "password:"
send "pppppp\r"
interact
4. 建立ssh/scp通道
比如说我的机器是A,中间服务器为B,目标服务器是C<br>
从A可以ssh到B,从B可以ssh到C,但是A不能直接ssh到C<br>
现在展示利用ssh通道技术从A直接传输文件到C<br>
1. ssh -L1234:C:22 userid@B<br>
input B's password<br>
(1234是本机A的空闲端口,该指令需要A机器上的root用户权限,实际上是在本机1234端口建立了一个通道)<br>
2. 打开一个新的console,键入:<br>
scp -P1234 filename userid@localhost:<br>
input C's password
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/netzsm/archive/2007/09/13/1783055.aspx
Submitted by admin on 2009, July 9, 6:02 PM
1.删除0字节文件
find -type f -size 0 -exec rm -rf {} \;
2.查看进程
按内存从大到小排列
ps -e
Submitted by admin on 2009, April 24, 5:49 PM
redhat 4
http://mirror.centos.org/centos-4/4.7/os/i386/CentOS/RPMS/yum-2.4.3-4.el4.centos.noarch.rpm
rpm -ivh yum-2.4.3-4.el4.centos.noarch.rpm
warning: yum-2.4.3-4.el4.centos.noarch.rpm: V3 DSA signature: NOKEY, key ID 443e1821
error: Failed dependencies:
python-elementtree is needed by yum-2.4.3-4.el4.centos.noarch
python-sqlite is needed by yum-2.4.3-4.el4.centos.noarch
urlgrabber is needed by yum-2.4.3-4.el4.centos.noarch
yum-metadata-parser is needed by yum-2.4.3-4.el4.centos.noarch
yumconf is needed by yum-2.4.3-4.el4.centos.noarch
http://mirror.centos.org/centos-4/4.7/os/i386/CentOS/RPMS/yum-metadata-parser-1.0-8.el4.centos.i386.rpm
rpm -ivh yum-metadata-parser-1.0-8.el4.centos.i386.rpm
warning: yum-metadata-parser-1.0-8.el4.centos.i386.rpm: V3 DSA signature: NOKEY, key ID 443e1821
error: Failed dependencies:
libsqlite3.so.0 is needed by yum-metadata-parser-1.0-8.el4.centos.i386
http://mirror.centos.org/centos-4/4.7/os/i386/CentOS/RPMS/sqlite-3.3.6-2.i386.rpm
rpm -ivh sqlite-3.3.6-2.i386.rpm
warning: sqlite-3.3.6-2.i386.rpm: V3 DSA signature: NOKEY, key ID 443e1821
Preparing... ########################################### [100%]
1:sqlite ########################################### [100%]
http://mirror.centos.org/centos-4/4.7/os/i386/CentOS/RPMS/python-sqlite-1.1.7-1.2.1.i386.rpm
http://mirror.centos.org/centos-4/4.7/os/i386/CentOS/RPMS/python-elementtree-1.2.6-5.el4.centos.i386.rpm
http://mirror.centos.org/centos-4/4.7/os/i386/CentOS/RPMS/python-urlgrabber-2.9.8-2.noarch.rpm
rpm -ivh python-*
warning: python-elementtree-1.2.6-5.el4.centos.i386.rpm: V3 DSA signature: NOKEY, key ID 443e1821
Preparing... ########################################### [100%]
1:python-urlgrabber ########################################### [ 33%]
2:python-elementtree ########################################### [ 67%]
3:python-sqlite ########################################### [100%]
ftp://ftp.isu.edu.tw/pub/Linux/CentOS/4.7/os/ia64/CentOS/RPMS/centos-yumconf-4-4.5.noarch.rpm
http://rpm.pbone.net/index.php3/stat/4/idpl/2665731/com/centos-yumconf-4-4.5.noarch.rpm.html
rpm -ivh
配置
vi /etc/yum.repos.d/CentOS-Base.repo
[base]
name=Red Hat Enterprise As release 4 base
baseurl=http://mirror.centos.org/centos-4/4.7/os/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos-4/4.7/os/i386/RPM-GPG-KEY-centos4
[update]
name=Red Hat Enterprise As release 4 updates
baseurl=http://mirror.centos.org/centos-4/4.7/updates/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos-4/4.7/os/i386/RPM-GPG-KEY-centos4
[extras]
name=Red Hat Enterprise As release 4 extras
baseurl=http://mirror.centos.org/centos-4/4.7/extras/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos-4/4.7/os/i386/RPM-GPG-KEY-centos4
rhel 5
rhel 5 系统上已有支持并安装yum,但是要用到rh本身的更新服务,如果没买就用不了。
只需要把 /etc/yum.repos.d/rhel-debuginfo.repo 里的内容,替换为centos 5 的就可以了。
把上面的4.7替换为 5.3即可
如果在装系统时没有装上yum,则另外安装
如下,根据依赖关系,安装所有的包
rpm -ivh yum-3.2.19-18.el5.centos.noarch.rpm
warning: yum-3.2.19-18.el5.centos.noarch.rpm: Header V3 DSA signature: NOKEY, key ID e8562897
error: Failed dependencies:
yum-rhn-plugin < 0.5.2-1.el5 conflicts with yum-3.2.19-18.el5.centos.noarch
此包可以不安装,加个--nodeps参数直接安装yum
一样可以正常使用yum更新,但都是用centos的源
---------------------
mkdir yum;cd yum;wget http://...198/rhel_yum_soft.tar.gz;tar zxvf rhel_yum_soft.tar.gz;rpm -ivh *.rpm;cp CentOS-Base.repo
/etc/yum.repos.d/;cd ..;rm -fr yum;yum update -y udev;
Submitted by admin on 2009, April 15, 11:43 AM
关于ulimit命令的一些用法,其中有
ulimit -n 4096
也就是限制用户的最大文件打开数为4096个
在网上查了关于怎么查看文件打开数的文章大致有两种说法
/proc/sys/fs/file-nr
该文件与 file-max 相关,它有三个值:
已分配文件句柄的数目
已使用文件句柄的数目
文件句柄的最大数目
该文件是只读的,仅用于显示信息。
查看所有进程的文件打开数
lsof |wc -l
查看某个进程打开的文件数
lsof -p pid |wc -l