linux小记
CentOS设置系统时间、硬件时间、以及定时较对时间
[ 2010/04/07 20:17 | by birdsky ]
CentOS设置系统时间和时区
一、设置时区
方法一:使用setup工具
setup
选择Timezone configuration
选择Asia/Shanghai
空格键勾选上System clock uses UTC
就OK了。
方法二:使用tzselect工具
tzselect
选择亚洲Asia
5
选择国家China
9
选择地区central China
3
确认选择Yes
1
设置好tzselect后,一定要重写/etc/localtime
rm /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
方法三:直接修改/etc/sysconfig/clock文件
vi /etc/sysconfig/clock
ZONE="Asia/Shanghai"
UTC=true
ARC=false
重写/etc/localtime
rm /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
二、重启系统使时区生效
reboot
三、更新时间
更新系统时间
ntpdate cn.pool.ntp.org
更新硬件时间
hwclock --systohc
四、crontab定时较对时间
设置crontab定时较对时间
crontab -e
30 1 * * * ntpdate cn.pool.ntp.org ;hwclock --systohc
PS:
ntpdate命令安装
yum -y install ntp
setup工具安装
yum -y install setuptool
crontabs安装
yum -y install gcc gcc-c++ autoconf vixie-cron crontabs
一、设置时区
方法一:使用setup工具
setup
选择Timezone configuration
选择Asia/Shanghai
空格键勾选上System clock uses UTC
就OK了。
方法二:使用tzselect工具
tzselect
选择亚洲Asia
5
选择国家China
9
选择地区central China
3
确认选择Yes
1
设置好tzselect后,一定要重写/etc/localtime
rm /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
方法三:直接修改/etc/sysconfig/clock文件
vi /etc/sysconfig/clock
ZONE="Asia/Shanghai"
UTC=true
ARC=false
重写/etc/localtime
rm /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
二、重启系统使时区生效
reboot
三、更新时间
更新系统时间
ntpdate cn.pool.ntp.org
更新硬件时间
hwclock --systohc
四、crontab定时较对时间
设置crontab定时较对时间
crontab -e
30 1 * * * ntpdate cn.pool.ntp.org ;hwclock --systohc
PS:
ntpdate命令安装
yum -y install ntp
setup工具安装
yum -y install setuptool
crontabs安装
yum -y install gcc gcc-c++ autoconf vixie-cron crontabs
解决yum更新或者安装慢的小技巧
[ 2010/04/07 18:21 | by birdsky ]
使用yum更新或者安装软件时,有时下载速度会很慢,这时可以安装自动选择最快源的插件yum-fastestmirror。
yum install yum-fastestmirror
装上之后,在yum更新或者安装时,它会自动选择最快的源来下载,如果你对它选择的源不满意,只要Ctrl+c一下,它就会自动更换一个源来下载了,如果新换的源还是慢,就再Ctrl+c一下,接着换,直到换到快的为止。
注意:千万别一次连着按几下Ctrl+c,那样会直接退出yum安装了。
yum install yum-fastestmirror
装上之后,在yum更新或者安装时,它会自动选择最快的源来下载,如果你对它选择的源不满意,只要Ctrl+c一下,它就会自动更换一个源来下载了,如果新换的源还是慢,就再Ctrl+c一下,接着换,直到换到快的为止。
注意:千万别一次连着按几下Ctrl+c,那样会直接退出yum安装了。
修改yum源为国内源
[ 2010/04/07 18:04 | by birdsky ]
yum虽然很好用,但却有一个小问题,那就是更新速度。对于国内用户,尤其是你的网速还不够快的时候,使用yum意味着漫长的等待。我搜集了几个速度不错的国内源,大家可以自己选择、测试、修改。需要修改的文件是/etc/yum.repos.d/CentOS-Base.repo,记得备份!
首先,备份原yum源
cd /etc/yum.repos.d/
cp CentOS-Base.repo CentOS-Base.repo.bak
然后在下面的源中选择一个来用
vi CentOS-Base.repo
最后更新缓存
yum makecache
以下为收集到的源
1.默认的CentOS-Base.repo文件:
CentOS-Base.repo
# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# 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://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
#baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
#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://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=2
2.USTC源
该源由中国科学技术大学提供,合肥电信,每小时更新,CentOS官方镜像。编辑CentOS-Base.repo内容如下,下同。
USTC
[base]
name=CentOS-$releasever - Base
baseurl=http://centos.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
[updates]
name=CentOS-$releasever - Updates
baseurl=http://centos.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
[addons]
name=CentOS-$releasever - Addons
baseurl=http://centos.ustc.edu.cn/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
[extras]
name=CentOS-$releasever - Extras
baseurl=http://centos.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://centos.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
3.mirror.centos.net.cn源
该源同样为CentOS官方镜像,属于北京网通,北方网通用户推荐。
mirror.centos.net.cn
[base]
name=CentOS-$releasever - Base
baseurl=http://mirror.centos.net.cn/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.net.cn/RPM-GPG-KEY-CentOS-5
[update]
name=CentOS-$releasever - Updates
baseurl=http://mirror.centos.net.cn/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.net.cn/RPM-GPG-KEY-CentOS-5
[addons]
name=CentOS-$releasever - Addons
baseurl=http://mirror.centos.net.cn/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.net.cn/RPM-GPG-KEY-CentOS-5
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirror.centos.net.cn/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.net.cn/RPM-GPG-KEY-CentOS-5
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirror.centos.net.cn/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.net.cn/RPM-GPG-KEY-CentOS-5
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://mirror.centos.net.cn/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.net.cn/RPM-GPG-KEY-CentOS-5
4.网易源
http://mirrors.163.com, 该源由网易提供,杭州电信。下载CentOS-Base-163.repo, 放入/etc/yum.repos.d/,然后运行yum makecache生成缓存。
NETEASE:mirrors.163.com
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
[update]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
[addons]
name=CentOS-$releasever - Addons
baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://mirrors.163.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
5.搜狐源
http://mirrors.sohu.com ,该源由搜狐提供,山东联通。下载CentOS-Base-sohu.repo, 放入/etc/yum.repos.d/,然后运行yum makecache生成缓存。
SOHU:mirrors.sohu.com
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.sohu.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
[update]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.sohu.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
[addons]
name=CentOS-$releasever - Addons
baseurl=http://mirrors.sohu.com/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.sohu.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.sohu.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://mirrors.sohu.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
首先,备份原yum源
cd /etc/yum.repos.d/
cp CentOS-Base.repo CentOS-Base.repo.bak
然后在下面的源中选择一个来用
vi CentOS-Base.repo
最后更新缓存
yum makecache
以下为收集到的源
1.默认的CentOS-Base.repo文件:
CentOS-Base.repo
# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# 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://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
#baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
#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://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=2
2.USTC源
该源由中国科学技术大学提供,合肥电信,每小时更新,CentOS官方镜像。编辑CentOS-Base.repo内容如下,下同。
USTC
[base]
name=CentOS-$releasever - Base
baseurl=http://centos.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
[updates]
name=CentOS-$releasever - Updates
baseurl=http://centos.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
[addons]
name=CentOS-$releasever - Addons
baseurl=http://centos.ustc.edu.cn/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
[extras]
name=CentOS-$releasever - Extras
baseurl=http://centos.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://centos.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
3.mirror.centos.net.cn源
该源同样为CentOS官方镜像,属于北京网通,北方网通用户推荐。
mirror.centos.net.cn
[base]
name=CentOS-$releasever - Base
baseurl=http://mirror.centos.net.cn/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.net.cn/RPM-GPG-KEY-CentOS-5
[update]
name=CentOS-$releasever - Updates
baseurl=http://mirror.centos.net.cn/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.net.cn/RPM-GPG-KEY-CentOS-5
[addons]
name=CentOS-$releasever - Addons
baseurl=http://mirror.centos.net.cn/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.net.cn/RPM-GPG-KEY-CentOS-5
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirror.centos.net.cn/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.net.cn/RPM-GPG-KEY-CentOS-5
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirror.centos.net.cn/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.net.cn/RPM-GPG-KEY-CentOS-5
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://mirror.centos.net.cn/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.net.cn/RPM-GPG-KEY-CentOS-5
4.网易源
http://mirrors.163.com, 该源由网易提供,杭州电信。下载CentOS-Base-163.repo, 放入/etc/yum.repos.d/,然后运行yum makecache生成缓存。
NETEASE:mirrors.163.com
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
[update]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
[addons]
name=CentOS-$releasever - Addons
baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://mirrors.163.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
5.搜狐源
http://mirrors.sohu.com ,该源由搜狐提供,山东联通。下载CentOS-Base-sohu.repo, 放入/etc/yum.repos.d/,然后运行yum makecache生成缓存。
SOHU:mirrors.sohu.com
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.sohu.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
[update]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.sohu.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
[addons]
name=CentOS-$releasever - Addons
baseurl=http://mirrors.sohu.com/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.sohu.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.sohu.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://mirrors.sohu.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
linux系统让history加上命令操作时间
[ 2010/04/03 19:50 | by birdsky ]
让history加上时间,加在/etc/bashrc文件上
vi /etc/bashrc
加入下面语句,然后重新登录就可生效
# add history time
export HISTTIMEFORMAT="%F %T "
vi /etc/bashrc
加入下面语句,然后重新登录就可生效
# add history time
export HISTTIMEFORMAT="%F %T "
linux系统版本检查
[ 2010/04/03 19:35 | by birdsky ]
linux系统的版本检查命令有:
cat /etc/issue
cat /etc/redhat-release
uname -a
uname -a 还可以看出系统是32位的还是64位的
64位的系统有x86_64字样,如下:
Linux qy 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009 x86_64 x86_64 x86_64 GNU/Linux
32位的系统有i686 i386字样
Linux localhost.localdomain 2.6.18-128.el5 #1 SMP Wed Jan 21 10:44:23 EST 2009 i686 i686 i386 GNU/Linux
cat /etc/issue
cat /etc/redhat-release
uname -a
uname -a 还可以看出系统是32位的还是64位的
64位的系统有x86_64字样,如下:
Linux qy 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009 x86_64 x86_64 x86_64 GNU/Linux
32位的系统有i686 i386字样
Linux localhost.localdomain 2.6.18-128.el5 #1 SMP Wed Jan 21 10:44:23 EST 2009 i686 i686 i386 GNU/Linux