I am bored in my free time recently and like to study chatgpt and domestic GPT large models. Then I wanted to find a machine to make a robot to play with, so I bought an Alibaba cloud space. I haven't been working on a cloud server for a long time, and the commands are a bit rusty. The cloud host is not the same as the local machine. Use dependency commands.
1. First configure anaconda, which makes it easier for us to switch between different versions of python and manage resource packages.
1. First copy the latest version of anaconda path from Tsinghua source, and then use wget to download
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2023.03-1-Linux-x86_64.sh
2. Then install bash Anaconda3-2023.03-1-Linux-x86_64.sh
3. Replace conda with Alibaba source
channels:
- defaults
show_channel_urls: true
default_channels:
- http://mirrors.aliyun.com/anaconda/pkgs/main
- http://mirrors.aliyun.com/anaconda/pkgs/r
- http://mirrors.aliyun. com/anaconda/pkgs/msys2
custom_channels:
conda-forge: http://mirrors.aliyun.com/anaconda/cloud
msys2: http://mirrors.aliyun.com/anaconda/cloud
bioconda: http://mirrors.aliyun .com/anaconda/cloud
menpo: http://mirrors.aliyun.com/anaconda/cloud
pytorch: http://mirrors.aliyun.com/anaconda/cloud
simpleitk: http://mirrors.aliyun.com/anaconda/ If
there is an error when downloading the update, you can copy it here:
https://developer.aliyun.com/mirror/anaconda/?spm=a2c6h.25603864.0.0.499519e4RLqrR3
4. Clean the cache, conda clean -i
5. Create a 310 env environment
conda create --name python310 python=3.11.1
6. After successful creation, you can view
the conda env list
7. Delete env. If you created it incorrectly, you can delete it.
save env remove -n python310
8. Activate the environment
conda activate python310
conda deactivate
Some other commands
List installed
conda list
Delete an environment
conda remove --name environment name
The installation package is theoretically the same as pip installation. If pip cannot install it, you can use conda to try
conda install --upgrade --name package name
Delete the package, pay attention to distinguish
the conda uninstall package name from the deletion environment
Find the package
conda search package name
9. Replace pip with Alibaba’s source to improve the speed of downloading software packages and libraries.
Check what the source is
pip config list
View packagewufl
pip show packagename
Update libraries or packages
pip install --upgrade package_name
View information about a package
pip show -f requests
View packages that need to be upgraded
pip list -o
Specify the domestic source to install. If the installation fails, you can specify the domestic source to download.
pip install -i https://pypi.douban.com/simple/ package_name
Download the package but don't install it
pip download requests -d "."
You can also change it to another fixed source. If there is no such file, creating a new one is still valid.
vim ~/.pip/pip.conf
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
10. Generate requirements.txt for the project to facilitate configuration
pip freeze > requirements.txt
pip install pipreqs
This only generates the framework
pipreqs ./ --encoding=utf8
pipreqs ./ --encoding=utf8 --use-local --force
11. You can also use conda to export
- Batch export of packages in an environment
conda list -e > requirements.txt
或者
conda env export > requirements.yaml
- Packages in batch installation files
conda install --yes --file requirements.txt
or
conda env create -f requirements.yaml
Sincerely, the python environment configuration is complete, and other installations are required.
12. The python 310 package has been installed when creating the environment in step five.
Some commands to maintain the system
free Check memory status
netstat -lntp to check the port number
topView cpups
-df View process status
df to view disk usage
13.Install mysql
apt-get install mysql-server
apt-get install mysql-client
apt-get install libmysqlclient-dev
mysql is only used on the server, not remotely operated
14. Install nginxsudo apt-get install nginx
Modify the first line user to root
vim /etc/nginx/nginx.conf
15. Add other administrators to ecs. Root can easily go offline. You still need to create other users.
Add xxx user, r represents the system user, m creates a home directory for the user, and s specifies the default shell.
sudo useradd -r -m -s /bin/bash xxx
sudo passwd xxx
Join the sudo group and add a new group at the end of the group list to prevent misoperation. Generally, just join the sudo group.
sudo usermod -a -G sudo xxx
sudo usermod -a -G root xxx
Another method of modifying files to add groups, but it feels like adding is not very good.
chmod 777 /etc/sudoers
vim /etc/sudoers
add
root ALL=(ALL:ALL) ALL
xxx ALL=(ALL:ALL) ALL
chmod 755 /etc/sudoers
Switch users, switch between root and ordinary users
sudo -i someonesudo su
su username
delete users:sudo deluser username
View the list of currently logged in users:whoami
View user group information:sudo groups username
Remove a user from a user group:sudo deluser username groupname
A little trick: When installing the software and configuring the environment, root installation is used, which makes other users unable to use it.
Create a new file in the /etc/profile.d/ directory, for example anaconda.sh
, and edit the file. Enter the following:
export PATH="/root/anaconda3/bin:$PATH"
Use the following command to change the permissions of the Anaconda directory and all its subdirectories to readable and executable by all users.
sudo chmod -R o+rx /root/anaconda3
After restarting the computer, other users can use it. You can also execute export PATH="/root/anaconda3/bin:$PATH" without restarting the entire set.
16.Upload project
scp -r ~/work/ [email protected]:/root/
scp [email protected]:/root/filename.txt /User/username/Desktop# Download the folder to the desktop
scp -r [email protected]:/root/filedir /User/username/Desktop# cd to the file to be uploaded directory, upload the file
scp -r filename.py [email protected]:/root/filedir
pip install -r requirements.txt
pip --default-timeout=100 install -r requirements.txt -i https://pypi.douban.com/simple
17 Newly created ssh is easily broken
vim /etc/ssh/sshd_config
Modify these two lines
#ClientAliveInterval 0
#ClientAliveCountMax 3
#去掉
ClientAliveInterval 30
ClientAliveCountMax 86400
18. Install uwsgi. I don’t know why, but when using flask, I always get a warning and prompt to change to uwsgi.
The web application server used by uwsgi to run the Django service area project.
apt-get install uwsgi
apt-get install uwsgi-plugin-python
sudo apt-get install uwsgi-plugins-all
Common commands for test examples
Start
uwsgi using ini file --ini start.ini
Start using ini background
uwsgi -d --ini start.ini
Start and shut down in the background, find the process id, kill
ps -ef|grep uwsgi
kill -9
19Install docker
20. Modify root ssh to prevent disconnection
vim /etc/ssh/sshd_config
Find ClientAliveInterval and ClientAliveCountMax
The values are changed to 120 and 3 respectively.
Finally, after everything is done, you can only play it by yourself and cannot show it to others, because the IP of the external network now also needs to be registered. It is best to apply for a domain name and register it together. You need to spend a few extra dollars to apply for the domain name. If the registration is not approved, you can only play solo.