---
title: "CentOS安装和一些基础配置"
author: "pluto418"
date: "2013-07-13T11:33:43Z"
tags: []
categories: ["企业架构"]
slug: "centos"
draft: false
lastmod: "2013-09-01T15:36:23Z"
id: 1905402
url: "https://pluto418.iteye.com/blog/1905402"
---

**1. 修改主机名**  
切换到root用户。  
vi /etc/sysconfig/network  
HOSTNAME=localhost.centos-1

vi /etc/hosts  
127.0.0.1 localhost localhost.centos-1

**2. 设置自动连接网络**  
虚拟机设置选择NAT模式，默认情况下，CentOS不是自动连接上网的，要点击右上角有个电脑图标，选择system eth0进行连接，

vi /etc/sysconfig/network-scripts/ifcfg-eth0  
把ONBOOT="no"改为yes

**3. yum代理配置**  
vi /etc/yum.conf  
proxy=http://192.168.x.x:3128  
proxy\_username=yum-user  
proxy\_password=qwerty

**4. 防火墙**  
开启端口（以80端口为例）  
vi /etc/sysconfig/iptables  打开配置文件加入如下语句:  
\-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT   重启防火墙，修改完成  
service iptables restart    重启防火墙，修改生效

关闭端口  
vi /etc/sysconfig/iptables  打开配置文件加入如下语句:  
\-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j DROP   重启防火墙，修改完成  
service iptables restart    重启防火墙，修改生效

查看端口状态  
/etc/init.d/iptables status  
关闭防火墙  
/etc/rc.d/init.d/iptables stop

**5. 更改DNS解析**  
vi /etc/resovl.conf

**6. 修改Linux文件打开数**  
如果你的机器为Linux/Unix，请：  
调整Linux/Unix系统允许打开的最大文件数，系统默认一般为1024。  
我们可以执行ulimit -n可查看这个数值。  
通过vi /etc/security/limits.conf加入以下两行：  
\* soft nofile 300000  
\* hard nofile 300000  
重新系统后通过ulimit -a可以查看结果。