centos开发环境配置

Posted jiangxiaoju

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos开发环境配置相关的知识,希望对你有一定的参考价值。

文章目录

一、更新yum源

# 对于 CentOS 7
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \\
         -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \\
         -i.bak \\
         /etc/yum.repos.d/CentOS-*.repo

# 对于 CentOS 8
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \\
         -e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos|g' \\
         -i.bak \\
         /etc/yum.repos.d/CentOS-*.repo

然后执行

yum makecache

二、安装必要软件

先以下这些,如有遗漏再添加

yum install screen gcc g++ cmake make git
 yum install epel-release

json命令行工具

yum install jq

三、系统设置

设置hostname

hostnamectl set-hostname master

关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

将 SELinux 设置为 permissive 模式(相当于将其禁用)

sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

关闭swap

swapoff -a  
sed -ri 's/.*swap.*/#&/' /etc/fstab

允许 iptables 检查桥接流量

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system

设置AllowTcpForwarding,不过默认也是yes

vim /etc/ssh/sshd_config

AllowTcpForwarding yes

三、开发环境搭建

3.1 docker

sudo curl -sSL https://get.daocloud.io/docker | sh
systemctl start docker
systemctl enable docker # 开机自启

设置镜像源

vim /etc/docker/daemon.json
"registry-mirrors": ["http://hub-mirror.c.163.com"]        
sudo systemctl daemon-reload
sudo systemctl restart docker

3.2 k8s系列

基础设置

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
   http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF

全部命令, 看着办 ,–disableexcludes=kubernetes 这个参数别忘了


sudo yum install -y kubelet-1.20.9 kubeadm-1.20.9 kubectl-1.20.9 --disableexcludes=kubernetes

sudo systemctl enable --now kubelet

3.2.1 kubectl

sudo yum install -y kubectl-1.23.12  --disableexcludes=kubernetes

3.2.2 rke

cd /opt/software
wget https://github.com/rancher/rke/releases/download/v1.4.0/rke_linux-amd64
cp /opt/software/rke_linux-amd64 rke
cp /opt/software/rke /usr/bin/
chmod  a+x /usr/bin/rke

3.3 软件存放目录

mkdir /opt/software/
mkdir /opt/module/

3.4 go

mkdir /opt/module/go/
mkdir -p /opt/module/gopath/go1.17 #gopath放在用户目录下,避免互相影响
cd /opt/module/gopath/go1.17
mkdir bin
mkdir pkg
mkdir src

cd /opt/software/
wget https://go.dev/dl/go1.17.13.linux-amd64.tar.gz
tar -zxvf go1.17.13.linux-amd64.tar.gz -C /opt/module/go/
cd /opt/module/go/
mv ./go ./go1.17

vim /etc/profile.d/my_env.sh
export GOROOT=/opt/module/go/go1.17       ##Golang安装目录
export PATH=$GOROOT/bin:$PATH
export GOPATH=/opt/module/gopath/go1.17  ##Golang项目目录
source /etc/profile

3.5 java

https://www.oracle.com/java/technologies/downloads/#java8

上传到/opt/software/

tar -zxvf jdk-8u351-linux-x64.tar.gz -C /opt/module/
 vim /etc/profile.d/my_env.sh
#JAVA_HOME 
export JAVA_HOME=/opt/module/jdk1.8.0_351
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile

3.6 x11 图形界面

yum install xorg-x11-xauth.x86_64 xorg-x11-server-utils.x86_64 dbus-x11.x86_64 xclock -y
vim /etc/ssh/sshd_config
X11Forwarding yes
X11UseLocalhost no # 禁止将X11请求绑定到本地回环地址上
vim ~/.bashrc

本机ip,不是centos服务器的ip

export DISPLAY=192.168.137.1:0.0

使用图像界面的时候最好使用mobaxterm,不用其他额外配置,用xshell目前还没有配置成功过

3.7 goland

cd /opt/software
wget "https://download-cdn.jetbrains.com/go/goland-2021.3.3.tar.gz?_ga=2.228962204.1446260195.1668308974-1416473211.1640081858&_gac=1.228096495.1668308993.Cj0KCQiApb2bBhDYARIsAChHC9u5W7kFfSWKTZ6fcjpIp71x-i1BYTxJ04d-CsexDx1lu7j8vPoBhWoaAh24EALw_wcB&_gl=1*q5lwqy*_ga*MTQxNjQ3MzIxMS4xNjQwMDgxODU4*_ga_9J976DJZ68*MTY2ODMwODk3My4yLjEuMTY2ODMwOTA0MS4wLjAuMA.." -O /opt/software/goland-2021.3.3.tar.gz
tar -zxvf goland-2021.3.3.tar.gz -C /opt/module/

运行goland的时候,建议使用安装java,目前没找到自己安装的java为啥启动不了,好像是jre不行?

yum install java

3.8 git 升级到2.x

yum remove git*
sudo yum install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
yum install git

以上是关于centos开发环境配置的主要内容,如果未能解决你的问题,请参考以下文章

CentOS下配置Java开发环境---安装OpenJDK

CentOS 7.2 开发环境 配置

CentOS 7.2 开发环境 配置

python 开发环境配置

centos开发环境配置

centos开发环境配置