CentOS7系统初始化设置
# 镜像地址
# 官方镜像:http://isoredirect.centos.org/centos/
# 官方镜像:http://isoredirect.centos.org/centos/7/isos/x86_64/
wget http://mirrors.163.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso
1
2
3
2
3
# 网络设置
静态IP地址:192.16.18.100
[root@hub ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
#BOOTPROTO=dhcp
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=b3d1393d-059d-49ea-a12b-9aa9e4c9bc2c
DEVICE=ens33
ONBOOT=yes
NM_CONTROLLED=no
IPADDR=192.16.18.100
NETMASK=255.255.255.0
GATEWAY=192.16.18.2
DNS1=114.114.114.114
DNS2=8.8.8.8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 系统参数调整
# 关闭SELINUX 临时关闭
setenforce 0
# 关闭SELINUX 永久关闭需要修改SELINUX的配置文件
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# 打开文件数调整 (按需调整)
echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "* hard nofile 65536" >> /etc/security/limits.conf
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 更改YUM源
yum install -y vim wget
1
## 备份
# 备份全部
mkdir -p /etc/yum.repos.d/bak && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
# 或者只备份 CentOS-Base.repo 文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
## 下载新的CentOS-Base.repo 到/etc/yum.repos.d/
# CentOS 7 (二选一)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# CentOS 6 (二选一)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
# CentOS 5 (二选一)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
## 配置epel源
# epel(RHEL 7)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# epel(RHEL 6)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
# epel(RHEL 5)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo
## 运行yum makecache生成缓存
yum clean all && yum makecache && yum repolist && yum update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 基本软件工具安装
# jp:json格式的工具 | bash-completion: tab键补全命令
yum install -y vim curl wget telnet lrzsz git unzip jq gcc tree sysstat libseccomp bash-completion yum-utils bzip2
yum install -y policycoreutils-python openssh-server openssh-clients cronie
yum install -y iptables conntrack ipvsadm ipset net-tools lsof iproute bridge-utils bind-utils
yum install -y epel-release xorg-x11-xauth htop dstat glances lftp
yum install -y ntpdate ntp
1
2
3
4
5
6
2
3
4
5
6
# 升级Linux内核版本
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
# 安装内核
yum --enablerepo=elrepo-kernel install -y kernel-lt
# 查询已安装的内核
rpm -qa | grep kernel
# 查看默认启动项
awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
# 设置开机从新内核启动
#grub2-set-default 'CentOS Linux (4.4.189-1.el7.elrepo.x86_64) 7 (Core)'
# 上述命令不生效,可执行下面的命令设置默认启动
# 默认启动的顺序是从0开始(CentOS Linux (3.10.0-1127.el7.x86_64) 7),新内核是从头插入,所以需要选择0
grub2-set-default 0
# 注意:设置完内核后,需要重启服务器才会生效。
reboot
# 查询内核 4.4.249-1.el7.elrepo.x86_64
uname -r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
## 通过 yum remove 命令
# 查看系统安装了哪些内核包
rpm -qa | grep kernel
# 使用yum remove 或rpm -e 删除无用内核
yum remove kernel-tools-libs-3.10.0-1127.el7.x86_64
## 通过 yum-utils 工具
# 如果安装的内核不多于 3 个,yum-utils 工具不会删除任何一个。只有在安装的内核大于 3 个时,才会自动删除旧内核。
yum install yum-utils
package-cleanup --oldkernels
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 修改hostname
# 查看机器的hostname
hostname
# 设置hostname
hostnamectl set-hostname dev.alot.pw
# 设置hosts文件
echo '192.16.18.100 dev.alot.pw' >> /etc/hosts
1
2
3
4
5
6
2
3
4
5
6
# 扩展安装
# axel安装:多线程下载工具
wget http://downloadib01.fedoraproject.org/pub/epel/7/x86_64/Packages/a/axel-2.4-9.el7.x86_64.rpm
rpm -ivh axel-2.4-9.el7.x86_64.rpm
1
2
3
2
3
# 全局环境变量
vi /etc/profile
# 添加如下内容, 注意修改自己的安装路径
export NODE_HOME=/usr/local/lib/nodejs
export JAVA_HOME=/usr/local/lib/jdk1.8.0_261
export MAVEN_HOME=/usr/local/lib/maven-3.6.3
export PATH=$JAVA_HOME/bin:$NODE_HOME/bin:$MAVEN_HOME/bin:$PATH
export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/toos.jar
# 配置生效
source /etc/profile
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 卸载CentOS7系统自带mariadb
# 查看系统自带的Mariadb (mariadb-libs-5.5.68-1.el7.x86_64)
rpm -qa|grep -i mariadb
# 卸载系统自带的Mariadb
rpm -qa | grep mariadb | xargs rpm -e --nodeps
# 删除etc目录下的my.cnf
rm /etc/my.cnf
1
2
3
4
5
6
2
3
4
5
6
编辑此页 (opens new window)
上次更新: 2022/02/18 07:42:40