一、起因

服务器环境需要进行一些项目资源的部署和开发,为了统一开发环境和控制权限,独立创建了非 root 权限用户并进行开发环境的统一配置。服务器版本为 CentOS7。

二、资源准备

Conda 通过源文件进行手动安装,方便进行环境整合。下载地址目前使用的是清华大学的开源镜像站
Maven 和 Java 通过 SDKMAN 进行安装,便于版本切换和管理。安装地址为官网
Bazel 通过源码进行安装,直接从Github进行下载。

三、安装

1.安装 Conda

  • 第一步下载 miniconda 的安装文件,此处建议建立统一的下载目录。

    wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh

  • 第二步进行安装,如无特殊需要,用默认目录即可。安装最后一步我通过 yes 默认激活了 conda,如无需要可选择 no,在需要时手动激活 conda。

    bash Miniconda3-latest-Linux-x86_64.sh

  • 第三步修改 conda 的数据源,默认数据源在国外,有时不太稳定,这里继续选择清华的开源镜像站。在$HOME目录下新建.condarc文件并修改为如下内容。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    channels:
    - 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 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple将 pip 的数据源也切换到清华镜像站。

  • 第五步则根据自己的项目需求构建新的 conda 环境,默认的 base 环境建议保留原始内容。

2.安装 JAVA 和 Maven

  • 第一步安装 sdkman,这里通过 sdkman 进行 java 和 maven 的版本控制。

    curl -s "https://get.sdkman.io" | bash

    source ~/.bashrc

  • 第二步安装 Java,这里使用的版本是阿里出的 jdk11。

    sdk install java 11.0.9.4-albba

    此处如果下载速度缓慢可以通过设置代理下载或者手动安装。手动解压 Java 目录后,可以通过如下命令进行安装。

    sdk install java jdk-name path/to/jdk

  • 第三步安装 maven。这里直接使用最新版的 maven,目前的版本是 3.6.3

    sdk install maven

  • 第四步修改 maven 仓库地址,改到阿里的开源镜像仓库上以加速下载。修改~/.m2/settings.xml文件。

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
<?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下载。

    wget https://github.com/bazelbuild/bazel/releases/download/4.0.0/bazel-4.0.0-installer-darwin-x86_64.sh

  • 第二步安装 Bazel,默认安装路径为~/.bazel,二进制文件位于~/bin,缓存位于~/.cache/bazel

    1
    2
    chmod +x bazel-4.0.0-installer-darwin-x86_64.sh
    bash bazel-4.0.0-installer-darwin-x86_64.sh
  • 如果 bazel 初次编译过慢,可以通过设置HTTP_PEOXYHTTPS_PROXY。通过代理加速访问。

四、小结

  • 在服务器环境直接进行项目开发时,最忌讳的内容就是在多人协同时都通过 root 进行软件安装。同时不进行修改内容的记录,导致后续人员进场时出现难以解决的问题。

  • conda 环境命名规则为python版本-项目名称-用户/小版本

(未完待续···)

五、参考资料