linux日常小细节整理

3 篇文章 0 订阅

1、清理cache

仅清除页面缓存(PageCache)
sync; echo 1 > /proc/sys/vm/drop_caches

清除目录项和inode
sync; echo 2 > /proc/sys/vm/drop_caches

清除页面缓存,目录项和inode
sync; echo 3 > /proc/sys/vm/drop_caches

2、crontab定时任务取值范围
文件/etc/crontab中每行任务的描述格式如下:  
    minute hour day month dayofweek command
    minute - 从0到59的整数 
    hour - 从0到23的整数 
    day - 从1到31的整数 (必须是指定月份的有效日期)
    month - 从1到12的整数 (或如Jan或Feb简写的月份)
    dayofweek - 从0到7的整数,0或7用来描述周日 (或用Sun或Mon简写来表示)
    command - 需要执行的命令(可用as ls /proc >> /tmp/proc或 执行自定义脚本的命令)
前面五个*号代表五个数字,数字的取值范围和含义如下:
 
分钟 (0-59)
小時(0-23)
日期(1-31)
月份(1-12)
星期(0-6) //0代表星期天 

3、删除乱码文件
linux下删除乱码文件名:

1. ls -i 列出文件的节点ID, 如: 123456789 

2. find ./ -inum 123456789 -print -exec rm -rf {} \; 

批量删除: 

for n in 123456789 987654321;do find . -inum $n -exec rm -f {} \;;done 

4、shell中$参数含义
$# 是传给脚本的参数个数
$ 0   是脚本本身的名字
$ 1   是传递给该shell脚本的第一个参数
$ 2   是传递给该shell脚本的第二个参数
$@ 是传给脚本的所有参数的列表
$* 是以一个单字符串显示所有向脚本传递的参数,与位置变量不同,参数可超过 9
$$ 是脚本运行的当前进程ID号
$? 是显示最后命令的退出状态, 0 表示没有错误,其他表示有错误

5、查找
查找某类型文件下包含的字符块
[ root@qm app]# grep loading.gif  ./css/*.css
./css/index.css:.d-loading { height:32px; text-align:left; text-indent:-999em; overflow:hidden; background:url(http://img1.qmsdstatic.com/mres/res/base/images/loading.gif) no-repeat center center; }
./css/index.css:.loading {   width:100%;    height:56px;    position: fixed;    top:50%;  text-indent: 0px;       line-height:56px;    color:#fff;    padding-left:60px;    font-size:15px;    background: #000 url(http://img1.qmsdstatic.com/mres/res/base/images/loading.gif) no-repeat 40% 50%;  text-align: center;   opacity: 0.7;    z-index:9999;    -moz-border-radius:20px;    -webkit-border-radius:20px;    border-radius:20px;    filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);  }
./css/index.css:.lazy { background: url("http://img1.qmsdstatic.com/mres/res/base/images/loading.gif") no-repeat center center; display: block;}
[ root@qm app]# 

查找文件名称
find ./ -name "loading.gif"

6、linux系统的TimeZone

使用Centos,遇到本地时间对不上,直接敲命令:date -s "2014-12-25 15:15:15"是立即生效了,但是重启后,系统时间还是原来的。

后面经过查找资料,做个小结.

我的Centos是安装在虚拟机上。在虚拟机有分系统时间和硬件时间。修改了其一是没有办法奏效,必须两者都更改。

1.date {查看目前本地的时间}

2.hwclock --show {查看硬件的时间}

3.如果硬件的时间是对不上,那就对硬件的时间进行修改、

4.hwclock --set --date '014-12-15 15:15:15' {设置硬件时间}

5.hwclock --hctosys {设置系统时间和硬件时间同步}

6.clock -w {保存时钟}

7.最后在通过重启,init 6 快速重启后,查看系统时间是否真正生效!!!!


[root@qm-wap1 ~]# tzselect 
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
 1) Africa
 2) Americas
 3) Antarctica
 4) Arctic Ocean
 5) Asia
 6) Atlantic Ocean
 7) Australia
 8) Europe
 9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5
Please select a country.
 1) Afghanistan          18) Israel            35) Palestine
 2) Armenia          19) Japan            36) Philippines
 3) Azerbaijan          20) Jordan            37) Qatar
 4) Bahrain          21) Kazakhstan        38) Russia
 5) Bangladesh          22) Korea (North)        39) Saudi Arabia
 6) Bhutan          23) Korea (South)        40) Singapore
 7) Brunei          24) Kuwait            41) Sri Lanka
 8) Cambodia          25) Kyrgyzstan        42) Syria
 9) China          26) Laos            43) Taiwan
10) Cyprus          27) Lebanon            44) Tajikistan
11) East Timor          28) Macau            45) Thailand
12) Georgia          29) Malaysia            46) Turkmenistan
13) Hong Kong          30) Mongolia            47) United Arab Emirates
14) India          31) Myanmar (Burma)        48) Uzbekistan
15) Indonesia          32) Nepal            49) Vietnam
16) Iran          33) Oman            50) Yemen
17) Iraq          34) Pakistan
#? 9
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time
#? 1

The following information has been given:

    China
    Beijing Time

Therefore TZ='Asia/Shanghai' will be used.
Local time is now:    Thu Oct 20 20:34:58 CST 2016.
Universal Time is now:    Thu Oct 20 12:34:58 UTC 2016.
Is the above information OK?
1) Yes
2) No
#? 1

You can make this change permanent for yourself by appending the line
    TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai
[root@qm-wap1 ~]# 
[root@qm-wap1 ~]# vi /etc/profile    增加    export TZ='Asia/Shanghai' 
[root@qm-wap1 ~]# date -R Thu, 20 Oct 2016 12:41:17 +0000
[root@qm-wap1 ~]# . /etc/profile    使环境变量生效
[root@qm-wap1 ~]# date -R Thu, 20 Oct 2016 20:41:35 +0800

7、调整文件句柄数
--查看进程开发的文件句柄数量
lsof -n | awk '{print $2}' | sort | uniq -c | sort -nr | more

ps -aef | grep 进程号


--修改系统的文件句柄数
root登录服务器

vi /etc/security/limits.conf

* hard nofile 65535 或 * - nofile 65535

vi .profile  添加  ulimit -n 65535

. ~/.profile

-- 修改系统内核参数

查看TCP状态:netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
查看SOCKET状态:cat /proc/net/sockstat
TIME_WAIT状态的socket一般需要等到2msl时间后,socket才会被回收。
修改(添加)系统内核参数:/etc/sysctl.conf

#改系統默认的TIMEOUT时间
net.ipv4.tcp_fin_timeout=2

#启重用,允许将TIME-WAIT sockets重新用于新的TCP连接 默认为0表示关闭
net.ipv4.tcp_tw_reuse=1

#开启TCP连接中TIME-WAIT sockets的快速回收 默认为0 表示关闭
net.ipv4.tcp_tw_recycle=1

使新增参数生效:sysctl -p


9、监控参数
[ root@qm ~]# vmstat 2 10
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0 258952 17992080 309016 8748008    0    0     5     3    0    0  1  0 99  0  0    
 3  0 258952 17992072 309016 8747976    0    0     0    26 2895  710 17  0 83  0  0    
 2  0 258952 17992196 309016 8747976    0    0     0     0 2481  598 17  0 83  0  0    
 2  0 258952 17991824 309016 8747976    0    0     0    18 2916  684 18  0 81  0  0    
 2  0 258952 17992196 309016 8747976    0    0     0   132 2989  731 19  0 80  1  0    
 3  0 258952 17991948 309016 8747980    0    0     0    10 3630  905 22  0 78  0  0    
 3  0 258952 17991700 309016 8747980    0    0     0    38 3170  796 21  0 78  0  0    
 2  0 258952 17991204 309016 8747948    0    0     0   364 2576  685 17  0 82  1  0    
 2  0 258952 17991204 309016 8747948    0    0     0    16 2939  647 17  0 83  0  0    
 3  0 258952 17991328 309016 8747948    0    0     0     0 2768  651 17  0 83  0  0    
[ root@qm ~]#  iostat
Linux 2.6.32-358.el6.x86_64 (qm.web10)     2016年04月26日     _x86_64_    (12 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.91    0.00    0.03    0.06    0.00   99.00

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda               2.51       122.19        72.73 7081933849 4215403284
dm-0              0.58         1.76         4.39  101952970  254331472
dm-1              7.14       120.27        68.10 6970687410 3946930248

可以用iostat/iotop查看具体的io状况


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值