Centos下关闭防火墙
#Centos7版本以下
>>>service iptables stop
#Centos7
>>>systemctl stop firewalld
#原因:Centos7下,firewlld被引入到管理的iptables。、
#firewalld更适合工作站,个人服务器上还是建议使用iptables的设置
#第一步,停止和掩盖firewalld
>>>systemctl stop firewalld
>>>systemctl mask firewalld
#第二步,安装iptables
>>>yum install iptables-services
#第三步,开机自启动
>>>systemctl enable iptables
#P.S.
#管理iptables
>>>systemctl [stop|start|restart] iptables
#保留设置
>>>service iptables save
Centos6.5下中文编码问题
#查看支持字符集
>>>locale -a
#字符集配置文件
>>>vim /etc/sysconfig/i18n
#修改为如下图(前提支持如下字符集)
LANG="zh_CN.GBK"
SUPPORTED="zh_CN.UTF-8:zh_CN:zh"
SYSFONT="latarcyrheb-sun16"
#保存退出
#使文件生效
>>>source /etc/sysconfig/i18n
#P.S.
#貌似不能直接生效。若不能生效,重启即可
Centos6网络配置
#Centos6默认安装完没有激活网卡,需要手动修改配置文件激活
>>>vi /etc/sysconfig/network-scripts/ifcfg-eth0
#内容大致如下,结合具体情况更改
DEVICE=eth0
HWADDR=00:0C:29:79:DA:11
TYPE=Ethernet
U1D=59d78d32-9a9e-4cb8-b695-086f3edb2b52
INBOOT=yes
MM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.21
ETMASX=255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.1
DNS2=8.8.8.8
#保存退出
#重启网络服务
>>>/etc/init.d/network restart
配置文件/etc/profile和.bashfile的区别
/etc/profile
这个文件是每个用户登录时都会运行的环境变量设置搜索
.bashfile
是单用户登录时运行的 例如:root会运行的
P.S.
前面有/etc/**的是系统级的配置文件
前面无/etc/**的是用户级别的
即说明
/etc/profile代表所有用户的配置文件,一旦修改,所有用户的配置文件都依此进行
.bashfile代表个人用户的配置文件,修改之后,不影响其他用户的配置
给虚拟机ubuntu挂载硬盘
先在VMware中给Ubuntu添加硬盘,在此不赘述
# 查看硬盘情况
>>>sudo lshw -C disk
# 查看硬盘信息
>>>sudo fdisk -l
# 正式开始分区
>>>sudo fdisk /dev/sdb
# 创建新分区
>>>n
# 选择为“主分区”
>>>p
# 给主分区序号
>>>1
# 分区大小,使用默认值,直接回车即可(全使用默认值,所以回车不止一下)
# 查看是否创建成功,如果有新的Device Boot出现,则表示创建成功
>>>p
# 创建成功之后,退出
>>>w
# 格式化分区
>>>sudo mkfs -t ext4 /dev/sdb1
# 挂载分区,xx表示当前主机用户名,挂载位置也可自定义
>>>sudo mount /dev/sdb1 /home/xx/
# 查看是否成功挂载,若最后一行出现/dev/sdb1设备则代表挂载成功
>>>df -h
# 开启自动挂载
>>>sudo vim /etc/fstab
# 最后一行加入
>>>/dev/sdb1 /home/xx/ ext4 defaults 0 0
# 大功告成,可重启继续用df -h 命令查看是否能自动挂载
# 如果系统重启不能进入登陆界面,并提示不能正确挂载硬盘,可以按C或S键,取消挂载硬盘
手贱安装Ubuntu为英文之后
# 打开终端
>>>sudo apt-get install language-pack-zh-hans
>>>locale-gen zh_CN.UTF-8
# 编辑文件
>>>vim /etc/default/locale
# 将配置项更改为"zh_CN.utf8"
LANG="zh_CN.uft8"
LANGUAGE="zh_CN.utf8"
# 保存退出后,修改全部语言设置
>>>export LC_ALL='zh_CN.utf8'
# 重启即可更新设置
Centos7更改系统更新源(可将下面代码复制重命名为”CentOS-Base.repo”)
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# 首先,备份源文件(Centos7)
>>>mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
# 然后,上传刚刚的文件到刚刚那个目录/etc/yum.repos.d下
# 最后,生成缓存
>>>yum clean all
>>>yum makecache
修改python的pip源
# 主目录下创建.pip文件夹
>>>cd
>>>mkdir ~/.pip
# 新建pip.conf
>>>vim pip.conf
# 编辑文件
[global]
trusted-host = pypi.douban.com
index-url = http://pypi.douban.com/simple
# 保存退出即可
Linux 查看CPU等使用率问题
top
使用权限:所有使用者
使用方式:top [-] [d delay] [q] [c] [S] [s] [i] [n] [b]
说明:即时显示process的动态
- d :改变显示的更新速度,或是在交谈式指令列( interactive command)按
- sq :没有任何延迟的显示速度,如果使用者是有superuser的权限,则top将会以最高的优先序执行
- c :切换显示模式,共有两种模式,一是只显示执行档的名称,另一种是显示完整的路径与名称
- S :累积模式,会将己完成或消失的子行程( dead child process )的CPU time累积起来
- s :安全模式,将交谈式指令取消,避免潜在的危机
- i :不显示任何闲置(idle)或无用(zombie)的行程
- n :更新的次数,完成后将会退出top
- b :批次档模式,搭配”n”参数一起使用,可以用来将top的结果输出到档案内
范例:
显示更新十次后退出;
top -n 10
使用者将不能利用交谈式指令来对行程下命令:
top -s
将更新显示二次的结果输入到名称为top.log的档案里:
top -n 2 -b < top.log
另附一个命令简介linux traceroutewindows tracert两个命令相当,跟踪网络路由
vmstat
正如我们之前讨论的任何系统的性能比较都是基于基线的,并且监控CPU的性能就是以上3点,运行队列、CPU使用率和上下文切换。以下是一些对于CPU很普遍的性能要求:
如果CPU在满负荷运行,应该符合下列分布,
a) User Time:65%~70%
b) System Time:30%~35%
c) Idle:0%~5%
mpstat
对于上下文切换要结合CPU使用率来看,如果CPU使用满足上述分布,大量的上下文切换也是可以接受的。
常用的监视工具有:vmstat, top,dstat和mpstat.
vmstat 1
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 104300 16800 95328 72200 0 0 5 26 7 14 4 1 95 0
0 0 104300 16800 95328 72200 0 0 0 24 1021 64 1 1 98 0
0 0 104300 16800 95328 72200 0 0 0 0 1009 59 1 1 98 0
- r表示运行队列的大小,
- b表示由于IO等待而block的线程数量,
- in表示中断的数量,
- cs表示上下文切换的数量,
- us表示用户CPU时间,
- sys表示系统CPU时间,
- wa表示由于IO等待而是CPU处于idle状态的时间,
- id表示CPU处于idle状态的总时间。
- dstat可以给出每一个设备产生的中断数:
dstat -cip 1
----total-cpu-usage---- ----interrupts--- ---procs---
usr sys idl wai hiq siq| 15 169 185 |run blk new
6 1 91 2 0 0| 12 0 13 | 0 0 0
1 0 99 0 0 0| 0 0 6 | 0 0 0
0 0 100 0 0 0| 18 0 2 | 0 0 0
0 0 100 0 0 0| 0 0 3 | 0 0 0
我们可以看到这里有3个设备号15,169和185.设备名和设备号的关系我们可以参考文件/proc/interrupts,这里185代表网卡eth1.
cat /proc/interrupts
CPU0
0: 1277238713 IO-APIC-edge timer
6: 5 IO-APIC-edge floppy
7: 0 IO-APIC-edge parport0
8: 1 IO-APIC-edge rtc
9: 1 IO-APIC-level acpi
14: 6011913 IO-APIC-edge ide0
15: 15761438 IO-APIC-edge ide1
169: 26 IO-APIC-level Intel 82801BA-ICH2
185: 16785489 IO-APIC-level eth1
193: 0 IO-APIC-level uhci_hcd:usb1
mpstat可以显示每个CPU的运行状况,比如系统有4个CPU。我们可以看到:
mpstat –P ALL 1
Linux 2.4.21-20.ELsmp (localhost.localdomain) 05/23/2006
05:17:31 PM CPU %user %nice %system %idle intr/s
05:17:32 PM all 0.00 0.00 3.19 96.53 13.27
05:17:32 PM 0 0.00 0.00 0.00 100.00 0.00
05:17:32 PM 1 1.12 0.00 12.73 86.15 13.27
05:17:32 PM 2 0.00 0.00 0.00 100.00 0.00
05:17:32 PM 3 0.00 0.00 0.00 100.00 0.00
总结的说,CPU性能监控包含以下方面:
检查系统的运行队列,确保每一个CPU的运行队列不大于3.
确保CPU使用分布满足70/30原则(用户70%,系统30%)。
如果系统时间过长,可能是因为频繁的调度和改变优先级。
CPU Bound进程总是会被惩罚(降低优先级)而IO Bound进程总会被奖励(提高优先级)。
prstat命令
要显示系统上当前运行的进程和项目的各种统计信息,请使用带有-J选项的prstat命令:
要显示系统上当前运行的进程和任务的各种统计信息,请使用带有-T选项的prstat命令:
-J和-T选项不能一起使用。
开启某服务的两种命令
在这里演示开启sshd服务
#service
>>>service sshd start
#/etc/init.d
>>>/etc/init.d/sshd start

5789

被折叠的 条评论
为什么被折叠?



