First said the ha, whatever version, actually installation is the same, the installation error on the way, as long as the patience to find what is the wrong places, such as lack of dependence, we will go to the download, I also installed the countless times, the midway do not collapse, I hereby writing this tutorial, let us not professional operations can also smooth installation is not an error, could run, Don’t waste time on installation. ~

Install Python

Centos7 comes with Python, but it’s Python 2. What if you want to install Python 3?

Since python3 is not readily available in the YUM source, you must manually compile and install it yourself.

Follow the steps: easy to install python3 on centos7, after more than 30 installs experience finally write the following secret!

1. Resolve dependencies

#Make sure you have all the necessary dependency packages in the system or an error will be reported:
yum -y groupinstall development

yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

yum install libffi-devel -y
#Note: the above three packages are very important, if not installed in advance will fail to install.
#Check to see if this machine installation using the command: "yum list | grep package name" and "yum grouplist" view.
Copy the code

2. Know the python2 path information in the centos system

[root@root ~]# whereis python
We can see that our python is in /usr/bin
python: /usr/bin/python2.7 /usr/bin/python /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz

Python points to PYTHon2, python2 points to Python2.7, so we can install Python3, then python points to Python3, then python2 points to Python2.7, Then both versions of Python can coexist.
[root@root ~]# cd /usr/bin/
[root@root bin]# ll python*
lrwxrwxrwx. 1 root root    7 2month7 09:30 python -> python2
lrwxrwxrwx. 1 root root    9 2month7 09:30 python2 -> python2.7
-rwxr-xr-x. 1 root root 7136 8month4 2017 python2.7
Copy the code

3. Install PIP /wget (not installed by default)

Run this command to add the epel extension source
yum -y install epel-release

# installation PIP
yum install python-pip

Install wget with PIP
pip install wget
Copy the code

4. Download python3

This tutorial can be downloaded via wget, or you can download the python installation package in source format from the Python website and upload it to your server using winscp or XFTP.

If you want to download the specified version, you can find the download address and change itWget HTTP: / / https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz# decompression
xz -dPython - 3.6.4 radar echoes captured. Tar. Xz tar xf Python - 3.6.4 radar echoes captured. The tarCopy the code

5. Manually compile

Go to the decompressed directory and run the following commands in sequence

./configure prefix=/usr/local/python3
make && make install

Python3 = /usr/local/
Copy the code

6. Add Python and PIP soft links

Back up the original link
mv /usr/bin/python /usr/bin/python.bak

# add python3 soft link
ln -s /usr/local/ python3 / bin/python3.6 / usr/bin/pythonTest whether the installation was successful
python -V

Python3 pip3
find / -name pip3
# my display: /usr/local/python3/bin/
Create a soft connection
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
# verify
pip3 -V
Copy the code

7. Change the YUM configuration

# yum cannot use python2 if python2 is usedVi/usr/bin/yum#! Change /usr/bin/python to #! /usr/bin/python2Vi/usr/libexec/urlgrabber - ext - down#! Change /usr/bin/python to #! /usr/bin/python2
Copy the code

8. Ubuntu 16.04 Installation

A reference: https://blog.csdn.net/u014775723/article/details/85213793?depth_1-utm_source=distribute.pc_relevant_right.none-task-blog -BlogCommendFromBaidu-1&utm_source=distribute.pc_relevant_right.none-task-blog-BlogReference CommendFromBaidu - 1 2: https://blog.sbot.io/articles/47/Ubuntu16.04-18.04-%E5%AE%89%E8%A3%85-Python-3.7.x need ahead of the pack good environment, Not installed in the sudo make install error appears in the python3 compile time zipimport. ZipImportError: can't decompress data; zlib not available
Makefile:1079: recipe for target 'install'failed make: *** [install] Error 1: sudo apt-get install zlib1g-dev failed make: *** [install] Error 1: sudo apt-get install zlib1g-devCopy the code

Extension: If you want to install centos, ubuntu, etc., you are recommended to use the usb boot mode for installation, rufus.ie/, this tool is very perfect…

Installing a Virtual Environment

1. Create a virtual environment command

A:Virtualenv can not be found by creating a soft linkSudo pip3 install virtualenv1.Virtualenv install directory find / -name virtualenv / usr/local/python3 / bin/virtualenv so it can directly go through the original executable file to create the virtual/usr/local/python3 / bin/virtualenv env to create soft links, So can directly use virtualenv command ln -s/usr/local/python3 / bin/virtualenv/usr/bin/virtualenv way 2: Sudo pip3 install virtualenvwrapper sudo pip3 install virtualenvwrapperCopy the code

2. Search for the virtualenvWrapper directory

If you want to add.sh, the path is not correctWhereis Virtualenvwrapper. Sh or find / -name virtualenvwrapperCopy the code

3. Create a folder to manage all VirtualenvWrappers

You are advised to use the home directoryExample: the mkdir/home/rock /. VirtualenvsCopy the code

4. Find the path where the. Bashrc configuration file resides

Bashrc = /root/.bashrc = /root/.bashrc
exportWORKON_HOME path = /. VirtualenvssourceVirtualenvwrapper. sh Directory to save# Save exit and execute (activate update configuration)
sourcePath /.bashrc Example:export WORKON_HOME=/home/rock/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
The configuration takes effect only after you run the following command:
source .bashrc
Copy the code

5. Create, exit, and activate the virtual environment

There are two ways to build a virtual environment: one is traditional and the other is officially recommended. Choose one of them.

  • Traditional operation of creating a virtual environment
Create a new virtual environment: mkvirtualenv nameFor example, mkvirtualenv python001 deactivate to exit the environmentIf you want to specify a python3 virtual environment to run inMkvirtualenv python002 -p Python Path for example, run the mkvirtualenv python002 -p /usr/bin/python3 commandDelete the virtual environmentCommand: rmvirtualenv [venvname]# Quickly activate the virtual environmentWorkon Virtual environment name Example: workon PYTHon001Copy the code
  • Pipenv is officially recommended for creating virtual environments
Create a file directoryThe mkdir filename# installation pipenv
pip install pipenv 

Install various packages in the virtual environmentPipenv install package name# uninstall packagesPipenv uninstall the package nameBoot into the virtual environment
pipenv shell 

Check the path of the current virtual environment
pipenv --venv 

Check package dependencies
pipenv graph 

Exit the virtual environment
exit

Copy the code

6. PIP installs the specified image source

  • Install the PIP
Create a soft connection
# I need to query the location of PIp3
Find / -name 'pip3' to find the location of pip3. Again, add a soft link to bin:
# /usr/local/bin/pip3 is the python3.7 installation path and /usr/bin/pip is the file to link to
pip3: /usr/local/bin/pip3 /usr/local/ bin/pip3.7# 1

ln -s /usr/local/bin/pip3 /usr/bin/pip

PIP -v if the PIP version is displayed, the installation is successful
Copy the code

In the first method, you need to specify the image source during the installation. In the second method, you need to change the image source directly

Specify the image source each time you install the packagePIP install - I domestic mirror address The package name Tsinghua university: https://pypi.tuna.tsinghua.edu.cn/simple ali cloud: http://mirrors.aliyun.com/pypi/simple/, https://pypi.mirrors.ustc.edu.cn/simple/, China university of science and technology, huazhong university of science and Shandong university of science and technology: http://pypi.hustunique.com/ http://pypi.sdutlinux.org/ douban: http://pypi.douban.com/simple/Copy the code
# Change the mirror source directlyPIP validation# pip -VPIP 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7) PIP 8.1.2 from /usr/lib/python2.7/site-packages PIP/vi ~/.pip/ PIP. Copy the following content to save [global] index-url=http://pypi.douban.com/simple [install] trusted-host=pypi.douban.comCopy the code

Virtual Environment Migration (Netless/Networked)

In the real world, we’ll have things like this where we develop locally and need to upload to the server

  • If there is a net, it is very easy to move

    1. Simply go to the virtual environment you want to migrate to do so, PIP install freeze > requirements.txt
    2. Create a virtual environment on the server and PIP install requirements.txt
  • No network state, referred to a lot of information on the Internet, many things are not feasible, here I have repeatedly proved the following results

    1. Centos or Ubuntu is the same as the operating system, and the path for creating a VIRTUAL environment is the same as that for installing Python, virtual environment, and PIP. You can directly compress and transfer the files from the original virtual environment folder to the target machine

    2. If the Python installation and PIP paths are inconsistent, copy the virtual environment to the target machine and change the following paths: The created venv package is copied to the target environment and decompressed

    1. In the venv/bin/ directory, modify the parameters in the Activate file and modify the path of the current virtual environment VIRTUAL_ENV="your new venv path"
    Copy the code
    2. In /venv/bin/, change the Python path of the current virtual environment to the PIP path of the current machine#! /xx/venv/bin/python
    Copy the code
    3./venv/bin/ Modify the Python version path to /root/venv/bin/pythonCopy the code
  • Offline installation mode (the original machine is guaranteed to have network) :

    Activate the local virtual environment first
    source venv/bivn/activate   
    
    Export the package version file
    pip freeze > requirements.txt 
    
    Remove the dependency package names (e.g., I install Flask,
    Flask has installed a lot of other packages for me, so I need to delete the names of the packages I need.
    # Because during the installation process, the package you installed will automatically install the required dependencies. If we do not remove the dependencies, the download may not be successful
    
    Download the offline package in the development environment first:
    pip download -dYour_offline_packages -r requirements. TXT package your_offline_packages and copy to the target machine environmentCopy the code

    Create a new VirtualEnv environment in the target environment and activate it:

    Source venv/bivn/activateCopy the code

    Batch install offline installation packages

      pip install --no-index --find-links=your_offline_packages -r requirements.txt
    Copy the code

MySQL installation

This installation is version 5.7. If you install other versions, please change the link

CentOS 7 will integrate with Mariadb instead of mysql by default

yum remove mariadb-libs.x86_64
cd tmp
Copy the code

2. Download the mysql source installation package

wget https://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
Copy the code

3. Install the mysql source

# enter yes
yum localinstall mysql57-community-release-el7-8.noarch.rpm  

# yes yes Re-execute this command if the installation is too fast
yum install mysql-community-server  
Copy the code

4. Start the service

service mysqld start 
ps -ef|grep mysql
Copy the code

5. View the default password

# generate a default password for root in /var/log/mysqld.log
cat /var/log/mysqld.log | grep "password"   
Copy the code

Mysql > alter database password;

shell> mysql -uroot -p

# View password policies
mysql> show variables like '%password%'; Validate_password_policy: password policy. The default value is MEDIUM policy. Validate_password_dictionary_file: Validate_password_length: indicates the minimum password length. Validate_password_mixed_case_count: Indicates the minimum password length. The value contains at least one VALIDATE_PASSword_number_count: The value contains at least one VALIDATE_PASSword_special_char_count: Special characters At least one parameter indicates the password check rule of the default policy MEDIUM.Change the password based on the policy
mysql> set password for 'root'@'localhost'=password('New password is written here'); 
Copy the code

7. Set the default encoding to UTf8.

CNF: [mysqld] character_set_server=utf8 init_connect= [mysqld'SET NAMES utf8'
Copy the code

Install Redis

There is nothing particularly difficult about installing Redis. This time, 4.0 is taken as an example, and other versions are the same. You can rest assured to install redis by following the steps.

1. Download the installation package and decompress the package

Wget http://download.redis.io/releases/redis-4.0.13.tar.gz tar XZF redis - X.X.X.T ar. GzCopy the code

2. Move the directory to the usr/local directory

sudo mv ./redis-x.x.x /usr/local/redis/
Copy the code

3. Make generated

Go to the redis directory
cd /usr/local/redis/redis-x.x.x

# compiler
sudo make
# success will prompt you
# Hint It's a good idea to run 'make test' ;)
# make[1]:Leaving directory '/usr/local/redis/src'
Copy the code

4. The test takes a long time

Redis.x.x.x/SRC
sudo make test   

# Success tips
# Cleanup: May take some time... OK
# make[1]:Leaving directory '/usr/local/redis/src'

# redis' make test failedNewer versions of Redis maketest are killed by TCL 8.0 or TCL 8.0in order to run the Redis testSolution: TCL was installed earlier; [exception]: Executingtestclient: NOREPLICAS Not enough good slaves to write.. NOREPLICAS Not enough good slaves to write. Solution: vim tests/integration/replication - 2. TCL will be the first of themif[err]: Slave should be able to synchronize with the masterintests/integration/replication-psync.tcl Replication not started. Solution: Re-maketestOnce is enough; [err]: Test replication partial resync: ok psync (diskless: yes, reconnect: 1)inTests/integration/replication - psync. TCL solution: vim tests/integration/replication - psync. TCL will after 100 of these modified into after 1000.Error resolution may be reported here
cd src && make testMake [1]: go to /usr/directorylocal/redis/redis-4.0.13/ SRC "You need TCL 8.5 or newerin order to run the Redis test
make[1]: *** [test] make[1]: leave directory /usr/local/ redis/redis - 4.0.13 / SRC "make: * * * [testWget] error 2 methods to solve: one: http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz sudo tar XZVF tcl8.6.1 - SRC. Tar. Gz - C/usr /local/
cd /usr/local/tcl8.6.1/ Unix/sudo./configure sudo make sudo make install ————————————————Copy the code

5. Installation

Install the redis command to /usr/local/bin/
sudo make install   
Copy the code

6. Check the

cd /usr/local/bin ls -all Go to the directory to view informationCopy the code

7. Move the configuration file to/etc/directory

Copy the configuration file to the configuration directory
sudo cp /usr/local/redis/redis.conf /etc/redis/     /usr/local/redis/redis.conf 
Copy the code

8. Startup automatically

Let Redis run as a daemonvim /etc/redis/redis.conf daemonize yes                Make redis run pidfile /var/run/redis_6379.pid&emsp as daemon. Set the redis PID file location (as appropriate) port  6379                    Set the listening port number of redis dir  /var/redis/6379          Set the location where persistent files are stored (depending on the situation)Copy the code

9. Start the Redis service

redis-server   /etc/redis/redis.conf 
Copy the code

10. Start the client redis-CLI

Redis -cli, access the interactive command line redis-cli SHUTDOWN, connect to port 6379 on the host to stop the redis process redis-cli -h 127.0.0.1 -p 6379 SHUTDOWN, Specify the IP address and port number to be connected redis-cli PING, PING the port of redis, and check whether the port is normalCopy the code

Install the Java

This installation is version 1.8, which needs to be downloaded from the official website in advance

1. Check whether it has been installed before

The RPM - qa | grep Java RPM - qa | grep JDK RPM - qa | grep GCJ if no input information is not installed. If the installation can use RPM - qa | grep Java | xargs RPM-eNodeps uninstall all files with Java in batchesCopy the code

2. First retrieve the list containing Java

yum list java*
Copy the code

3. Retrieve the list of 1.8

Yum list Java 1.8 *Copy the code

4. Install all files for 1.8.0

Yum install Java - 1.8.0 comes with - its * - yCopy the code

5. Run commands to check whether the installation is successful

[root@localhost java]# java -version 
openjdk version "1.8.0 comes with _252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
Copy the code

6. Query the Java installation path

[root@localhost java]# which java
/usr/bin/java

[root@localhost java]# ls -lrt /usr/bin/javaLRWXRWXRWX 1 root root 22 May 12 15:32 /usr/bin/java -> /etc/alternatives/ JavaCopy the code

Editing is not easy, if it helps, please give a thumbs-up, life is not easy, it is you who give me the motivation to keep on!

Ali cloud recommended entry machine is only more than 100, usually practice hands, mother no longer need to worry about me in the local virtual machine run computer stuck ~

Well, everyone, that’s all the content of this article, you can see the people here, are talented.

If this article is written well, feel “Wang Caichen” I have something to ask for praise 👍 for attention ❤️ for share 👥 for Geng Nan I really very useful!!

White piao is not good, creation is not easy, everyone’s support and recognition, is the biggest power of my creation, we see the next article!

Wang Cai minister | article “original”

If there are any mistakes in this blog, please comment, thank you very much!

More wonderful attention to wechat public number, the first time updated ~

Welfare! Does the above command installation feel tedious, but xiaobian consider some small white, I wrote a shell script, do not copy the command, one key to install Python + virtual environment, public account reply “install Python”, can be