> For the complete documentation index, see [llms.txt](https://bohans.gitbook.io/devops/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bohans.gitbook.io/devops/kubernetes/ji-chu-zhi-shi/an-zhuang/ji-qun/dan-ji-pei-zhi-zhun-bei-gong-zuo/ji-ben-huan-jing-pei-zhi.md).

# 基本环境配置

### 1. 配置主机名：

```properties
hostnamectl set-hostname k8s-master01
hostname
```

### 2. 修改 hosts 文件

```bash
echo '192.168.10.121 k8s-master01
192.168.10.122 k8s-node01
192.168.10.123 k8s-node02
192.168.10.124 k8s-master02
192.168.10.125 k8s-master03' >> /etc/hosts
```

```bash
cat /etc/hosts
```

### 3. 配置默认 yum 源：

{% code overflow="wrap" %}

```bash
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
```

{% endcode %}

```bash
yum install -y yum-utils device-mapper device-mapper-persistent-data lvm2
```

{% code overflow="wrap" %}

```bash
sed -i -e '/mirrors.aliyuncs.com/d' -e '/mirrors.cloud.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
```

{% endcode %}

检查 /etc/yum.repos.d/CentOS-Base.repo 内容：

```bash
cat /etc/yum.repos.d/CentOS-Base.repo
```

### 4. 安装一些常用的工具

```bash
yum install -y wget jq psmisc vim net-tools telnet git
```

### 5.  关闭防火墙、SELinux、DNSmasq

```bash
systemctl disable --now firewalld
systemctl disable --now dnsmasq
systemctl disable --now NetworkManager

setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
```

检查防火墙是否关闭：

```properties
systemctl status firewalld
```

### 6. 关闭Swap分区

```bash
swapoff -a && sysctl -w vm.swappiness=0
sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab
```

### 7. 配置时间同步

安装 ntpdate：

```bash
rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
yum install ntpdate -y
```

同步时间：

```bash
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo 'Asia/Shanghai' > /etc/timezone
ntpdate time2.aliyun.com
```

```properties
# crontab -e
*/5 * * * * /usr/sbin/ntpdate time2.aliyun.com
```

检查定时任务是否配置成功：

```properties
# crontab -l
*/5 * * * * /usr/sbin/ntpdate time2.aliyun.com
```

### 8. 配置limit

```bash
ulimit -SHn 65535
echo '# 末尾添加如下内容
* soft nofile 65536
* hard nofile 131072
* soft nproc 65535
* hard nproc 655350
* soft memlock unlimited
* hard memlock unlimited' >> /etc/security/limits.conf
```

### 9. 升级系统并重启

```bash
yum update -y  && reboot
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bohans.gitbook.io/devops/kubernetes/ji-chu-zhi-shi/an-zhuang/ji-qun/dan-ji-pei-zhi-zhun-bei-gong-zuo/ji-ben-huan-jing-pei-zhi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
