CentOS 配置开发环境
前言
服务器环境需要进行一些项目资源的部署和开发,为了统一开发环境和控制权限,独立创建了 非 root 权限
用户并进行开发环境的统一配置。服务器版本为 CentOS7
。
一、资源准备
软件 | 版本 | 注释 |
---|---|---|
Conda | 最新版 | 清华大学开源镜像站 |
Maven | 最新版 | 推荐 SDKMAN |
Java | 最新版 | 推荐 SDKMAN |
Bazel | 最新版,源码安装 | Github-Bazel |
二、安装
2.1 安装 Conda
- 第一步下载
miniconda
的安装文件,此处建议建立统一的下载目录。
BASH1wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh
- 第二步进行安装,如无特殊需要,用默认目录即可。安装最后一步我通过
yes
默认激活了conda
,如无需要可选择no
,在需要时手动激活conda
。
BASH1bash Miniconda3-latest-Linux-x86_64.sh
- 第三步修改
conda
的数据源,默认数据源在国外,有时不太稳定,这里继续选择清华的开源镜像站。在$HOME
目录下新建.condarc
文件并修改为如下内容。
sh1234567891011121314channels: - defaults show_channel_urls: true default_channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
- 第四步更新数据并修改
pip 源
。首先通过conda clean -i
清除索引缓存,保证用的是镜像站提供的索引。然后通过如下命令,将pip 源
也切换到清华镜像站。
BASH1pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
- 第五步则根据自己的项目需求构建新的
conda
环境,默认的base
环境建议保留原始内容。
2.安装 JAVA
和 Maven
- 第一步安装
sdkman
,这里通过sdkman
进行java
和maven
的版本控制。
BASH12curl -s "https://get.sdkman.io" | bash source ~/.bashrc
- 第二步安装
Java
,这里使用的版本是阿里出的jdk11
。
BASH123sdk install java 11.0.9.4-albba # 此处如果下载速度缓慢可以通过设置代理下载或者手动安装。手动解压 Java 目录后,通过如下命令进行安装。 sdk install java jdk-name path/to/jdk
- 第三步安装
maven
。这里直接使用最新版的maven
,目前的版本是3.6.3
。
BASH1sdk install maven
- 第四步修改
maven
仓库地址,改到阿里的开源镜像仓库上以加速下载。修改~/.m2/settings.xml
文件。
xml123456789101112131415161718192021222324252627<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <!-- <localRepository>\E:\Runtime\Maven\maven_local_repository</localRepository> --> <pluginGroups> </pluginGroups> <proxies> </proxies> </servers> <mirrors> <mirror> <id>aliyunmaven</id> <mirrorOf>central,jcenter</mirrorOf> <name>阿里云公共仓库</name> <url>https://maven.aliyun.com/repository/public</url> </mirror> </mirrors> <profiles> </profiles> </settings>
3.安装 Bazel
- 第一步下载安装包,从 github 下载。
BASH1wget https://github.com/bazelbuild/bazel/releases/download/4.0.0/bazel-4.0.0-installer-darwin-x86_64.sh
- 第二步安装
Bazel
,默认安装路径为~/.bazel
,二进制文件位于~/bin
,缓存位于~/.cache/bazel
。
bash12chmod +x bazel-4.0.0-installer-darwin-x86_64.sh bash bazel-4.0.0-installer-darwin-x86_64.sh
- 如果
bazel
初次编译过慢,可以通过设置HTTP_PEOXY
和HTTPS_PROXY
,通过代理加速访问。
四、小结
-
在服务器环境直接进行项目开发时,最忌讳的内容就是在多人协同时都通过
root
进行软件安装。同时不进行修改内容的记录,导致后续人员进场时出现难以解决的问题。 -
conda
环境命名规则为python版本-项目名称-用户/小版本
。
参考
本站点所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 我的个人天地!