您的位置:首页 > 运维架构 > Linux

linux常用命令和操作笔记

2013-10-08 11:48 316 查看
1、通过程序名字统计当前机子共运行了多少个该程序实例,例如统计当前机子共有多个mosquitto_sub实例:
[root@SH-243 ~]# ps -ef | grep mosquitto_sub | wc
   7891  142029  883303

2、通过端口号统计当前机子 中共有多少个连接使用了该端口,例如统计当前机子中1883端口上有多少个连接:  
[root@SH-243 ~]#
netstat -apn | grep 1883 |wc
  31668  221676 3451812
3、停止指定名称的程序实例,例如停掉所有的 mosquitto_sub实例:

  killall -9 mosquitto_sub

4、永久解除 Linux 系统的最大进程数和最大文件打开数限制: 

        vi /etc/security/limits.conf 

        # 添加如下的行 

        * soft noproc 11000  #软连接  

        * hard noproc 11000  #硬连接 

        * soft nofile 4100   

        * hard nofile 4100 

       说明:* 代表针对所有用户,noproc 是代表最大进程数,nofile 是代表最大文件打开数

可参考:http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/

5、linux下修改ip地址等信息:
        #cd /etc/sysconfig/
        #ls
        ...
        #cd network-scripts
        ...
        #vi ifcfg-eth0(这里假设使用网卡是eth0)
        在这里就可以修改本机本网卡的ip地址和网关
        修改完之后需要重启网卡,命令为:
        #service network restart

6、防火墙相关操作命令

       开启指定端口

       /sbin/iptables -I INPUT -p tcp --dport 1883 -j ACCEPT #1883为指定端口

       查看防火墙信息

       /etc/init.d/iptables status

       /etc/rc.d/init.d/iptables save #将更改进行保存

       /etc/init.d/iptables restart #重启防火墙以便改动生效,

       其他防火墙的操作命令:

       查询防火墙状态:

       [root@localhost ~]# service   iptables status

       停止防火墙:

       [root@localhost ~]# service   iptables stop

       启动防火墙:

       [root@localhost ~]# service   iptables start

       重启防火墙:

       [root@localhost ~]# service   iptables restart

       永久关闭防火墙:

       [root@localhost ~]# chkconfig   iptables off

       永久关闭后启用:

       [root@localhost ~]# chkconfig   iptables on

 

7、查看动态库中是否导出了某个函数:
       readelf -s ./lib/libmosquitto.so.1 | grep join_handle_thread

 

8、查看指定进程的cpu利用率、内存利用率等等
(1)使用命令:
ps -ef | grep 程序名 查找程序对应进程的pid。


例如查看mosquitto程序的cpu利用率:
ps -ef | grep mosquitto

可以得到下列消息(其中第二列就是pid,第三列是ppid):

[root@cddserver1 pub_client-kn]# ps -ef | grep mosquitto

500      31475  1804  0 19:29 pts/2    00:00:00 ./mosquitto

root     31485  2352  0 19:45 pts/4    00:00:00 grep mosquitto
(2)使用命令:top -p PID,查看对应pid的利用率情况:
例如:top -p 31475

可以得到下列消息:
top - 19:48:18 up 6 days, 0 min,  3 users,  load average: 0.00, 0.00, 0.00

Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie

Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:   7950788k total,   253100k used,  7697688k free,     7708k buffers

Swap:  8093688k total,    10372k used,  8083316k free,    62028k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                   

31475 mosquitt  20   0 43076 3004 1820 S  0.0  0.0   0:00.18 mosquitto    

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: