惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
有赞技术团队
有赞技术团队
宝玉的分享
宝玉的分享
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
大猫的无限游戏
大猫的无限游戏
博客园 - 司徒正美
D
Docker
T
The Blog of Author Tim Ferriss
罗磊的独立博客
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
J
Java Code Geeks
Jina AI
Jina AI
博客园 - 【当耐特】
C
Check Point Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
Last Week in AI
Last Week in AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog

陈少文的网站

巨变与机遇的未来十年 Kubernetes 平台管理软件压力测试方案 使用镜像部署 Hexo 静态页面 终于等到你 - GitHub 镜像仓库服务(ghcr.io) 一起来学 Go --(6)Interface 一起来学 Go --(5)Goroutine 和 Channel 什么是函数式编程 如何在 Kubernetes 集群集成 Kata 柯里化与偏函数 使用 PyGithub 自动创建 Label 软件产品是团队能力的输出 Helm 2 、Helm 3 比较 IoT 变现 Kubernetes 中的 DNS 服务 国内的 Helm 镜像源 Harbor 使用自签证书支持 Https 访问 DevOps 工具链之 Prow 如何使用 kfctl 安装 Kubeflow VS Code 无法下载 Go 插件的工具包 工程师更应具有服务精神 你不知道的 Docker 使用技巧 使用 Docker 运行 Tensorflow 论中国 什么是左移 如何清空 Git 仓库全部历史记录 一禅小和尚 有风吹过厨房 时间的玫瑰 如何在 CentOS 安装 GPU 驱动 开发 Tips(19)
CentOS 服务器运维实践
微信公众号 · 2018-11-11 · via 陈少文的网站

整理自「开发 Tips」系列,汇总 CentOS 服务器运维中的常见问题与解决方法。

1. 升级 Docker 版本

  1. 卸载旧版本的 Docker
1
2
3
4
5
6
$yum remove docker \
            docker-common \
            container-selinux \
            docker-selinux \
            docker-engine \
            docker-engine-selinux

保存在 /var/lib/docker/ 的镜像、容器、数据、网络都会被保留。

  1. 安装依赖
1
yum install -y yum-utils device-mapper-persistent-data lvm2
  1. 安装 Docker
1
2
3
yum-config-manager \
  --add-repo \
  https://download.docker.com/linux/centos/docker-ce.repo

2. 新增交换分区文件

查看当前分区情况:

增加 swap 大小,2G 左右:

1
dd if=/dev/zero of=/var/swap bs=1024 count=2048000

设置交换文件:

立即激活启用交换分区:

添加系统引导时自启动运行,编辑 /etc/fstab,添加一行:

1
/var/swap       swap      swap     defaults   0   0

收回 swap 空间:

1
2
swapoff /var/swap
rm /var/swap

3. 安装 minikube

新增安装源:

1
2
3
4
5
6
7
8
9
cat <<'EOF' > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

开始安装:

1
2
3
4
yum -y install kubectl
wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 -O minikube
chmod +x minikube
mv minikube  /usr/local/bin/

Linux 下 minikube 支持两种虚拟机 VirtualBox 和 KVM。但如果使用的是云服务器,无法开启 CPU 的虚拟化功能,可以使用宿主机的 Docker 环境:

1
minikube start --vm-driver=none

参考文章

4. 安装指定版本的 Docker

新增 Aliyun 的 docker-ce 源:

1
2
yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

查看可选的 docker-ce 版本:

1
2
3
4
5
6
yum list docker-ce --showduplicates

docker-ce.x86_64                                                                                                           17.03.3.ce-1.el7                                                                                                                   docker-ce-stable
docker-ce.x86_64                                                                                                           18.06.3.ce-3.el7                                                                                                                   docker-ce-stable
docker-ce.x86_64                                                                                                           3:18.09.9-3.el7                                                                                                                    docker-ce-stable
docker-ce.x86_64                                                                                                           3:19.03.8-3.el7                                                                                                                    docker-ce-stable

安装指定版本的 docker-ce:

1
yum install  -y docker-ce-19.03.8-3.el7

启动:

1
2
systemctl start docker
systemctl enable docker

5. 编译安装 Python 3.7

安装依赖:

1
yum install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils libffi-devel

下载源码包:

1
2
cd /usr/src
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz

开始安装:

1
2
3
4
tar xzf Python-3.7.0.tgz
cd Python-3.7.0
./configure --enable-optimizations
make altinstall

查看版本信息:

安装 pip:

1
2
wget https://bootstrap.pypa.io/get-pip.py -O - | python3.7
pip3 -V

6. 升级安装 Git2

  1. 移除旧版本:
  1. 安装 epel-release repository:
1
yum install epel-release
  1. 安装 IUS repository:
1
yum install https://centos7.iuscommunity.org/ius-release.rpm
  1. 安装 git2u:

7. /etc/rc.local 开机不自动运行

查看 /etc/rc.local 内容发现:

1
2
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

CentOS 7 建议创建 systemd 用于开机自启动。

如果需要使用旧的方式,则需要添加到 /etc/rc.d/rc.local。同时,执行 chmod +x /etc/rc.d/rc.local,赋予可执行权限。

8. 查看端口占用

  • 使用 lsof
1
2
yum install -y lsof
lsof -i:30948
  • 使用 netstat
1
2
yum install -y net-tools
netstat -apn | grep 30948

9. tcpdump 查看指定端口、指定 IP 来源数据

1
2
yum install -y tcpdump
tcpdump -i eth0 -nnA 'port 30948 and src host 192.168.10.3' -vv

10. 安装 GLIBC 2.18

查看已经安装的 GLIBC 版本:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
strings /lib64/libc.so.6 |grep GLIBC_*

GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_2.15
GLIBC_2.16
GLIBC_2.17

安装 GLIBC 2.18:

1
2
3
4
5
6
7
wget http://ftp.gnu.org/gnu/glibc/glibc-2.XX.tar.gz
tar -xvf glibc-2.18.tar.gz
cd glibc-2.18
mkdir build && cd build
../configure --prefix=/usr
make -j4
make install