fedora 服务管理(含简易优化脚本)

Fedora 20上面管理服务使用systemctl工具。以下是几条范例:

sudo systemctl list-unit-files    列出所有服务
sudo systemctl stop bluetooth.service    #停止蓝牙服务
sudo systemctl disable bluetooth.service    #禁用蓝牙服务

此外,Fedora还提供了一个图形化管理服务的工具,名为system-config-services

sudo yum install system-config-services

安装完成以后即可以在程序菜单中找到“服务”,然后在图形界面中管理服务。

以下是一些不常用的服务,可以禁止,对于加速fedora系统是很有帮助的

sudo systemctl stop bluetooth.service    #停止蓝牙服务
sudo systemctl disable bluetooth.service
sudo systemctl disable crond.service    #禁用定时计划任务
sudo systemctl disable atd.service    #禁用一次性计划任务
sudo systemctl disable cups.path    #禁用跟打印机相关的东西
sudo systemctl status cups.path
sudo systemctl stop cups.path
sudo systemctl status cups.path
sudo systemctl stop cups.socket
sudo systemctl disable cups.socket
sudo systemctl status cups.service
sudo systemctl disable cups.service
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service    #禁用防火墙
sudo systemctl stop vmtoolsd.service       #禁用VMware服务
sudo systemctl disable vmtoolsd.service
sudo systemctl stop multipathd.service     #多链路,基本无用
sudo systemctl disable multipathd.service

查看系统glibc版本

Linux系统中查看glibc的版本有三条命令:

ldd --version
getconf -a |grep glibc -i
/lib/libc.so.6      直接执行此文件,会有版本信息

/lib/libc.so.6是个软链接(非常重要),一般是指向/lib/libc-2.5.so,此软链接切不可移动或更名,否则系统将无法启动。

查看系统glibc支持的版本:

$ strings /lib64/libc.so.6 |grep GLIBC_

安装IBM Systems Director Console for AIX

安装IBM Systems Director Console for AIX的过程,简单记录一下。

依赖文件集

lwi.runtime
sysmgt.pconsole.rte
sysmgt.pconsole.apps.pda
sysmgt.pconsole.apps.wsmit
sysmgt.pconsole.apps.wdcem
sysmgt.pconsole.apps.wrbac
sysmgt.pconsole.apps.websm

可以使用 lslpp -l | grep name 来确定文件集安装与否。

安装

/usr/lib/instl/sm_inst installp_cmd -a -d /dev/cd0 -f sysmgt.pconsole -c -N -g -X

配置文件

/pconsole/lwi/conf/overrides/config.properties
/pconsole/lwi/conf/overrides/ports.properties
/pconsole/lwi/conf/overrides/*.properties
/pconsole/lwi/conf/webcontainer.properties 设置sslEnables=false

启用运行环境

查看:lssrc -a | grep pconsole 或者 lssrc -s pconsole
停止:stopsrc -s pconsole
开始:startsrc -s pconsole

继续阅读

Linux常用netstat命令详解

这是一个十分常用的命令,可以让你实时了解到云主机当前的状态,例如:常见的80连接数量,以及按一些排序,来检查是否被攻击?查看time_wait和syn连接数量等等。

1.查看所有80端口的连接数

netstat -nat|grep -i "80"|wc -l

2.对连接的IP按连接数量进行排序

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

3.查看TCP连接状态

netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}'
netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}'
netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}'
netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c

4.查看80端口连接数最多的20个IP

netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20

5.用tcpdump嗅探80端口的访问看看谁最高

tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20

继续阅读

Linux shell字符串截取

假设有变量 var=http://www.zhukun.net/123.htm

1,# 号截取,删除左边字符,保留右边字符。
echo ${var#*//}
其中 var 是变量名,# 号是运算符,*// 表示从左边开始删除第一个 // 号及左边的所有字符
即删除 http://
结果是 :www.zhukun.net/123.htm

2,## 号截取,删除左边字符,保留右边字符。
echo ${var##*/}
##*/ 表示从左边开始删除最后(最右边)一个 / 号及左边的所有字符
即删除 http://www.zhukun.net/
结果是 123.htm

3,%号截取,删除右边字符,保留左边字符
echo ${var%/*}
%/* 表示从右边开始,删除第一个 / 号及右边的字符
结果是:http://www.zhukun.net 继续阅读

Linux shell之seq用法

$ seq 1000   #起始默认是 1,间隔默认也是1
$ seq 2 1000  #间隔默认是1
$ seq 1 3 10    #从1到10,间隔为3,结果是:1 4 7 10
#!/bin/bash
for i in `seq 1 10`
do
  echo eth$i does not have a 1000 card!!
done

Linux循环遍历文件写法:

for file in `ls /etc/sysconfig/network-scripts/ifcfg-*`
do
  echo $file
done

以下是本人写的某脚本:

#!/bin/bash
for file in `ls /etc/sysconfig/network-scripts/ifcfg-*`
do
  i=${file##*-}
  #echo now checking $i
  if [ `ifconfig $i | grep 10000base | wc -l` -ge 1 ]; then
    id = `cat /proc/interrupts | grep $i | grep -v $i- | awk '{print $1}'`
    echo 'ff' > /proc/irq/${id%:*}/smp_affinity
    echo $i optimized.
  fi
done

参考文章:linux shell 动态生成 数组系列 seq使用技巧

Linux系统查看PCI/USB设备信息

Linux系统查看PCI设备信息,基本是使用lspci命令,如果找不到该命令,那么需要先安装pciutils软件包。

列出系统的PCI设备:

[root@os2 ~]# lspci
00:00.0 Host bridge: Intel Corporation Xeon E5/Core i7 DMI2 (rev 07)
00:01.0 PCI bridge: Intel Corporation Xeon E5/Core i7 IIO PCI Express Root Port 1a (rev 07)
00:03.0 PCI bridge: Intel Corporation Xeon E5/Core i7 IIO PCI Express Root Port 3a in PCI Express Mode (rev 07)
00:05.0 System peripheral: Intel Corporation Xeon E5/Core i7 Address Map, VTd_Misc, System Management (rev 07)
00:05.2 System peripheral: Intel Corporation Xeon E5/Core i7 Control Status and Global Errors (rev 07)
00:05.4 PIC: Intel Corporation Xeon E5/Core i7 I/O APIC (rev 07)
00:11.0 PCI bridge: Intel Corporation C600/X79 series chipset PCI Express Virtual Root Port (rev 06)
00:16.0 Communication controller: Intel Corporation C600/X79 series chipset MEI Controller #1 (rev 05)
00:16.1 Communication controller: Intel Corporation C600/X79 series chipset MEI Controller #2 (rev 05)
00:1a.0 USB controller: Intel Corporation C600/X79 series chipset USB2 Enhanced Host Controller #2 (rev 06)
00:1c.0 PCI bridge: Intel Corporation C600/X79 series chipset PCI Express Root Port 1 (rev b6)
00:1c.7 PCI bridge: Intel Corporation C600/X79 series chipset PCI Express Root Port 8 (rev b6)
00:1d.0 USB controller: Intel Corporation C600/X79 series chipset USB2 Enhanced Host Controller #1 (rev 06)
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev a6)
00:1f.0 ISA bridge: Intel Corporation C600/X79 series chipset LPC Controller (rev 06)
00:1f.2 IDE interface: Intel Corporation C600/X79 series chipset 4-Port SATA IDE Controller (rev 06)
00:1f.3 SMBus: Intel Corporation C600/X79 series chipset SMBus Host Controller (rev 06)
00:1f.5 IDE interface: Intel Corporation C600/X79 series chipset 2-Port SATA IDE Controller (rev 06)
05:00.0 RAID bus controller: Adaptec Series 6 - 6G SAS/PCIe 2 (rev 01)
06:00.0 Serial Attached SCSI controller: Intel Corporation C602 chipset 4-Port SATA Storage Control Unit (rev 06)
06:00.3 SMBus: Intel Corporation C600/X79 series chipset SMBus Controller 0 (rev 06)
07:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
09:00.0 PCI bridge: ASPEED Technology, Inc. AST1150 PCI-to-PCI Bridge (rev 02)
0a:00.0 VGA compatible controller: ASPEED Technology, Inc. ASPEED Graphics Family (rev 21)
7f:08.0 System peripheral: Intel Corporation Xeon E5/Core i7 QPI Link 0 (rev 07)
7f:08.3 System peripheral: Intel Corporation Xeon E5/Core i7 QPI Link Reut 0 (rev 07)

注意:如果有显示unknown device,说明/usr/share/hwdata/pci.ids文件太旧,没有及时更新。 继续阅读