Centos Mini

Centos mini版镜像缺少很多常用工具

更新系统
yum -y install epel-release && yum update

epel源

# CentOS/RHEL 6 :
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
# CentOS/RHEL 7 :
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

常用库、软件包

yum install gcc glibc gcc-c++ make automake cmake libtool bison flex perl git subversion mercurial -y 

yum install readline-devel bzip2-devel zlib-devel libxml2-devel libxslt-devel openssl-devel kernel-devel pcre-devel boost-devel python-devel python-setuptools libpcap-devel -y 

yum install wget htop vim lsof lrzsz tcpdump net-tools lsof screen mtr nc nmap zip dos2unix sysstat dstat setuptool system-config-* ntsysv mlocate telnet tree -y

删除Centos 7自带的virtbr0虚拟网卡

virsh net-destroy default
virsh net-undefine default 
systemctl restart libvirtd

防火墙打开需要的端口

iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT 
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT  #激活用ACCEPT ,关闭用DROP

保存配置
/etc/init.d/iptables save
重启
service iptables restart

安装桌面环境

# 必须在root用户下执行一下命令
yum check-update
yum groupinstall "X Window System" -y
yum install gnome-classic-session gnome-terminal \
nautilus-open-terminal control-center liberation-mono-fonts -y

# 设置默认启动图形界面
unlink /etc/systemd/system/default.target
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

# 重启生效
reboot

centos(6.X及以下版本)

网卡配置

多网卡多IP的情况,其中一个网卡配置DNS就行了,配多个会导致无法解析。

vi /etc/sysconfig/network-scripts/ifcfg-eth0 编辑配置文件,添加修改以下内容
双网不要配内网网关
例:

#联通公网:
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=221.4.XXX.XXX
NETMASK=255.255.XXX.224  
GATEWAY=221.4.xxx.xxx
DNS1=221.5.XX.88
DNS2=8.8.8.8
#内网:
vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.0.114
NETMASK=255.255.252.0  
GATEWAY=192.168.0.1
#DNS1=221.5.XX.88
#DNS2=8.8.8.8   (公网配了DNS和网关了)

#修改DNS也可以
vim /etc/resolv.conf
nameserver 221.5.XX.88
nameserver 8.8.8.8
IPV6INIT=no                 #禁止IPV6

service ip6tables stop      #停止IPV6服务
chkconfig ip6tables off     #禁止IPV6开机启动
service yum-updatesd stop   #关闭系统自动更新
chkconfig yum-updatesd off  #禁止开启启动
service network restart     #重启网络连接
ifconfig                    #查看IP地址

防火墙

iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT 
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT  #激活用ACCEPT ,关闭用DROP

保存配置
/etc/init.d/iptables save
重启
service iptables restart

设置主机名

修改主机名有一个通用的方法:hostnamectl --static set-hostname XXXXX

vi /etc/sysconfig/network
vi /etc/hosts
hostname newname   #newname就是你要改的主机名

service network restart  或  /etc/network restart
yum install wget lrzsz -y
service sshd start
chkconfig sshd on
shutdown -r now #重启系统

Ubuntu(14.04及以上版本)

安装常用软件

新安装的Ubuntu如果没有root用户密码,用sudo passwd root设置root密码。

apt-get install wget lrzsz openssh-server vim -y
/etc/init.d/ssh start

允许root登录shell

Ubuntu超级用户root用户是默认被禁用的,这就是为什么我们登陆时只能以普通用户登陆,而且switch user时没有root选项。
必须使用命令启动root。即输入:sudo passwd root。然后输入密码即可启动root。

vim /etc/ssh/sshd_config
将PermitRootLogin 的值改为yes
sudo service sshd restart

网卡地址配置

多网卡多IP的情况,其中一个网卡配置DNS就行了,配多个会导致无法解析。

配置静态IP地址sudo vi /etc/network/interfaces

ifconfig   #可以看到eth0用作公网
#双网不要配内网网关
auto lo
iface lo inet loopback

auto eth0   (有的可能是eno0或eno1)
iface eth0 inet static
address 221.4.xxx.xxx
gateway 221.4.xxx.xxx
netmask 255.255.255.xxx
dns-nameservers 8.8.8.8
dns-nameservers 8.8.4.4
auto eth1
iface eth1 inet static
address 192.168.0.254
netmask 255.255.252.0
#gateway 192.168.0.1

保存退出,重启服务

/etc/init.d/networking restart

以DHCP 方式配置网卡

sudo vi /etc/network/interfaces
   auto eth0
   iface eth0 inet dhcp

/etc/init.d/networking restart命令使网络设置生效

修改DNS服务器

法一

vi /etc/network/interfaces
增加
dns-nameservers 8.8.8.8
dns-nameservers 8.8.4.4

法二

vi /etc/resolvconf/resolv.conf.d/head
增加
dns-nameservers 8.8.8.8
dns-nameservers 8.8.4.4

重启后生效,重启不失效

法三

vim /etc/resolv.conf
增加
nameservers 8.8.8.8
nameservers 8.8.4.4

vim /etc/resolvconf/resolv.conf.d/base
增加
nameservers 8.8.8.8
nameservers 8.8.4.4

重启后生效,重启不失效

防火墙

resolvconf -u
iptables -A INPUT -p tcp -i eth0 --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT 
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT  #激活用ACCEPT ,关闭用DROP

保存配置
/etc/init.d/iptables save
重启
service iptables restart

修改主机名

vi /etc/hostname
vi /etc/hosts
hostname newname  #newname就是你要改的主机名
或:hostnamectl --static set-hostname xxx

/etc/init.d/networking restart
shutdown -r now   #重启系统

Ubuntu 系统版本升级(如从16.04升到16.10)

Canonical 已经提供了一个直接升级的方法,非常快捷容易。适用于:Kubuntu、 Xubuntu、 Lubuntu、 Ubuntu GNOME、 Ubuntu Mate。
首先更新一下系统

sudo apt-get update
sudo apt-get dist-upgrade

接下来,需要安装更新管理器的核心

sudo apt-get install update-manager-core  
sudo do-release-upgrade -d  或  sudo update-manager -d

注:d-release-upgrade 命令是帮助我们寻找最新的稳定版本,而 -d 参数意思是包括非稳定版本。


文章作者: Leo
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 LeoLan的小站
环境搭建 重装服务器系统基本配置
喜欢就支持一下吧