Linux server installation python environment configuration

Server Springboard

insert image description here

A springboard is a server accessible from the public network that allows users to SSH into other servers on the private network. As shown in the figure above, you can connect to 7 private servers through the springboard

When you are connected to the jumpbox, you can use SSH tunneling or proxies to access other servers on the private network. When you use an SSH tunnel or proxy, you are actually forwarding a local port to a port on the remote server in order to access the remote server on your local computer.

A server jumper is a transit server through which other servers can be accessed. Its function is to improve the security of the server and reduce the risk of being attacked. It can realize intranet penetration, data encryption, user authentication, log recording and other functions, and it can also facilitate administrators to manage multiple servers and improve work efficiency. Server springboards are usually used in scenarios such as remote login, file transfer, and data backup, and are an indispensable part of enterprise informatization construction.

server configuration

Configure the anaconda environment

  1. Download the Anaconda installer: First, you need to download the appropriate Anaconda installer from Anaconda's official website (https://repo.anaconda.com/archive/). You can choose the Python 3.x version. Use the wget command to download directly on the server:
wget https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh

Note that the above link may be outdated, you should get the latest download link from Anaconda official website.

  1. Run the Anaconda installer: After the download is complete, you can run the installation script
bash Anaconda3-2021.05-Linux-x86_64.sh

Then, follow the prompts.
insert image description here
When you see more, keep pressing Enter until the please answer 'yes' or 'no' appears

insert image description here

When prompted to accept the license agreement, enter 'yes'. It will then prompt you to choose an installation location, you can accept the default location, or enter a new one.
insert image description here
The default file directory here is root, but it is not recommended to save files in the root directory. It is recommended to create a new folder under the root directory and save the files in this folder. This reduces potential security risks and the risk of system files being modified. At the same time, for some files that require permission management, it is recommended to save them in the home directory of ordinary users to avoid permission problems.

continue to enter

  1. Initialize Anaconda: After the installation is complete, the installer will ask you if you want to run conda init to initialize Anaconda3. If you agree, then Anaconda will be added to your shell script (such as .bashrc or .bash_profile), so that each new shell session will have the Anaconda environment set up

insert image description here
Continue
insert image description here
This vs compiler environment does not need to be installed

  1. Activate the installation: After the installer finishes, you need to close and reopen your shell window, or you can run the following command to activate the installation:
source ~/.bashrc

or

source ~/.bash_profile
  1. Test the installation: To confirm that Anaconda has been installed correctly, you can run:
conda list

If the installation was successful, this will display a list of installed packages. After that, you can start using conda commands to create new environments, install packages, and more.

Install other python versions

If you've installed Anaconda on your server, then you already have an environment that includes Python and many common scientific computing libraries.

Anaconda installs Python and some commonly used Python libraries by default, such as Numpy, Pandas, Scipy, and Matplotlib, so you don't need to install the Python environment separately.

An important feature of Anaconda is the conda environment. You can use conda to create new environments, and each environment can have different versions of Python and different libraries. This is useful for managing multiple projects and avoiding conflicts between library versions.

Here's how to create a new environment using conda

conda create --name myenv

This will create a new environment called myenv. You can replace myenv with any name you like. Then, you can activate this environment with the following command

conda activate myenv

Now that you are in a new environment, you can install the required libraries. For example, if you need to install tensorflow, you can do this:

conda install tensorflow

If you need to use a different version of Python, you can specify the Python version when creating the environment, such as:

conda create --name myenv python=3.6

In this way, you have created a new environment with Python 3.6 version. When you're done working and want to leave the environment, you can use the following command:

conda deactivate

uninstall anaconda

  1. First, you need to open your terminal.
  2. Then, to delete the entire Anaconda directory, you can use the rm -rf command. The default Anaconda directory is usually in your home directory and is named anaconda3 or anaconda2, depending on whether you installed a version of Python 3 or Python 2. So the command should be
rm -rf ~/anaconda3

or

rm -rf ~/anaconda2

Note that the rm -rf command silently deletes the directory and all files in it, so make sure the path is correct.

  1. Finally, you need to remove the Anaconda script path from your .bashrc or .bash_profile file. Open this file:
nano ~/.bashrc

or

nano ~/.bash_profile

then find this line

# added by Anaconda3 4.4.0 installer
export PATH='/home/username/anaconda3/bin:$PATH'

Delete or comment these lines, then save and close the file.

  1. You may also need to delete some hidden Anaconda files and folders, these are usually in your home directory:
rm -rf ~/.conda
rm -rf ~/.continuum
  1. Finally, you need to reload your shell for these changes to take effect. In your terminal run:
source ~/.bashrc

or

source ~/.bash_profile

The root user adds permissions to the user

In Linux, the root user (also known as a super user) has full control over the system and can assign and modify permissions for other users. You can assign permissions to other users using:

  1. Add new users using the useradd or adduser command:
sudo useradd -m newuser
sudo passwd newuser

This will create a new user newuser and set its password.

  1. Use the usermod command to modify the groups of an existing user:
sudo usermod -aG groupname username

Add username to the groupname group. For example, to add user newuser to the sudo group, you can run:

sudo usermod -aG sudo newuser

This will allow newuser to execute sudo commands and gain temporary root privileges.

  1. Use the chmod command to modify the permissions of a file or directory:
sudo chmod permissiosn filepath

This will change permissions on filepath. For example, you can run the following command to allow the user group read/write permissions on the file:

sudo chmod 664 filename
  1. Use the chown and chgrp commands to change the owner and group of a file or directory:
sudo chown newowner filepath
sudo chgrp newgroup filepath

This will change the owner of filepath to newowner and its group to newgroup.

Be sure to exercise caution when assigning permissions, as assigning permissions incorrectly can affect the security and stability of your system. Always make sure you understand the changes you made and how they affect your system before making changes.

Other tools

The following are some commonly used practical tools that can help you facilitate Python programming and deep learning training and inference on Linux servers:

  • Anaconda: Anaconda is a Python distribution that includes a large number of scientific computing and deep learning libraries, which can facilitate Python environment management and package management.
  • Jupyter Notebook: Jupyter Notebook is an interactive notebook that supports multiple programming languages, including Python. It helps you create and share documents in your browser, including code, equations, visualizations, narrative text, and more.
  • TensorFlow: TensorFlow is an open source deep learning framework that can help you perform deep learning training and inference on Linux servers.
  • PyTorch: PyTorch is an open-source deep learning framework that helps you perform deep learning training and inference on Linux servers.
  • Keras: Keras is a high-level neural network API that helps you with deep learning training and inference on Linux servers.
  • Git: Git is a distributed version control system that helps you with code management and collaboration on Linux servers.
  • Vim: Vim is a powerful text editor that helps you code and edit on Linux servers.
  • Tmux: Tmux is a terminal multiplexer that helps you run multiple terminal sessions simultaneously on a Linux server and switch between different sessions.
  • Htop: Htop is an interactive system monitor that helps you monitor system resource usage on your Linux server.
  • Docker: Docker is an open-source containerization platform that helps you easily deploy and manage applications on Linux servers.

Jupyter Noetbook,tmux,Docker,TensorFlow

Jupyter Noetbook

  1. Open a terminal and activate your Anaconda environment.
  2. Run the following command to install Jupyter Notebook:
conda install jupyter notebook
  1. After the installation is complete, run the following command to start Jupyter Notebook:
jupyter notebook
  1. Enter the URL http://localhost:8888/ in the browser to open the main interface of Jupyter Notebook.
  2. In the main interface, you can create a new Notebook and start writing Python code.
    Note: If you have multiple Python environments on your server, make sure to select the correct environment when installing Jupyter Notebook. For example, if you want to use Python 3.x, you should activate the corresponding environment and install Jupyter Notebook with:
conda install -n myenv jupyter notebook

where myenv is the name of the environment you want to use.

tmux

There are different package managers available for installing tmux on a Linux system, depending on your Linux distribution. Here's how to install some common distributions:

  1. Ubuntu/Debian: On Ubuntu or Debian systems, you can use the apt package manager to install tmux:
sudo apt-get update 
sudo apt-get install tmux
  1. CentOS/RHEL/Fedora: On CentOS, RHEL or Fedora systems, you can use the yum or dnf package managers to install tmux:
sudo yum install tmux  # For CentOS/RHEL 
sudo dnf install tmux  # For Fedora
  1. Arch Linux: On Arch Linux or Arch-based systems, you can use the pacman package manager to install tmux:
sudo pacman -Syu tmux

Once installed, you can start tmux in the terminal by typing tmux. You can also use man tmux to view the tmux man page to learn how to use tmux.

Guess you like

Origin blog.csdn.net/weixin_42010722/article/details/130721318