Linux发行版:centos 6.5
配置yum源
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -P /etc/yum.repos.d/
sed -i 's#$releasever#6#g' /etc/yum.repos.d/CentOS6-Base-163.repo
如果需要,也可以加上epel的源
yum install epel-release -y
sed -i 's#https#http#g' /etc/yum.repos.d/epel*
清理和重建缓存
yum clean all
yum makecache
中文支持
yum groupinstall chinese-support -y
修改系统编码,vi /etc/sysconfig/i18n(或者在/etc/profile中加入export LANG=zh_CN.UTF-8,然后source /etc/profile)
LANG="zh_CN.UTF-8"
执行下命令locale,结果应该是这样
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=
修改时区
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
修改后可能发现某些日志记录的时间还不正确,就需要重启对应的服务,比如/var/log/message中时间不是更新后的时区,就:
service rsyslog restart
安装编译工具
yum install gcc gcc-c++ make -y
vim的基本配置
让vi命令默认调用vim, vi ~/.bashrc
alias vi='vim'
需要重载环境变量使之生效
source ~/.bashrc
基本的vim配置,vi ~/.vimrc
syntax on
set number
set nobackup
set noswapfile
set ignorecase
set shiftwidth=
set tabstop=
set expandtab
set encoding=utf-
windows下gvim的额外配置
"解决console输出乱码
language messages zh_CN.utf-8
"解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
vim的配色方案,比较流行的solarized
"Linux模拟终端需要额外的下面四行配置(这里是xterm配色方案的xshell工具)
set background=dark
set t_Co=
let g:solarized_termtrans=
let g:solarized_termcolors=
"不喜欢配色中的斜体
let g:solarized_italic=0
"设定配色方案
colorscheme solarized
history显示时间和执行者
显示命令的执行时间和角色可以让history实用很多,vi /etc/bashrc
export HISTTIMEFORMAT="`whoami` : %F %T : "
使配置生效,命令
source /etc/bashrc
配置机器名
机器名为localhost或者在局域网内冲突可能会造成很多奇怪的问题,比如Java的Inetaddress.getlocalhost()
使用命令hostname,显示的如果是localhost.localdomain或类似名称,则需要修改
一般是根据用途命名,若暂时未明确用途,则可以用系统版本+ip后两段数字的方式防止重复
vi /etc/sysconfig/network
HOSTNAME=centos6.1.111
执行命令
hostname centos6.1.111
vi /etc/hosts(末尾加一行ip与机器名的映射)
192.168.1.111 centos6.1.111
测试一下
ping `hostname`
显示的是“ping 192.168.1.111”且响应无误即可
时间同步
配置一个ntp服务器,然后局域网内所有机器都从该服务器同步
选一台做ntp服务器,安装ntp和ntpdate
yum install ntp ntpdate -y
先同步下时间
ntpdate pool.ntp.org
修改ntp配置,vi /etc/ntp.conf,把默认的所有server配置注释或删除,添加下面的配置
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org
启动ntp,并配置其开机启动
/etc/init.d/ntpd start
chkconfig ntpd on
其他服务器,安装和配置定时同步(每6小时一次)
yum install ntpdate -y
ntpdate [ntp server ip]
crontab -e
0 */6 * * * /usr/sbin/ntpdate [ntp server ip] > /dev/null 2>&1
可用句柄和端口
修改系统所有进程可用句柄数,vi /etc/sysctl.conf
fs.file-max=655360
net.ipv4.ip_local_port_range = 1024 65000
使之生效
sysctl -p
修改单个会话可用句柄数,vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
加速ssh登录
vi /etc/ssh/sshd_config
UseDNS no
GSSAPIAuthentication no
/etc/init.d/sshd restart
关闭selinux
vi /etc/selinux/config
SELINUX=disabled
然后执行命令
setenforce