Cloud server environment construction and deployment, jdk, mysql, redis, nginx environment construction

1. Jdk environment installation

1. Check the java version

java -version

The command not found prompt appears as shown in the figure, indicating that java has not been installed in the system. If not, uninstall the relevant jdk products first.

2. Upload the java installation package

Switch to the usr directory and check whether the java folder exists in the directory. If it does not exist, create the folder.

cd /usr
ls
mkdir java

 Upload the jdk compressed package to the usr/java directory

 3. Unzip the compressed package

Switch to the java directory.

First, make sure you are in the root directory or the usr directory. If you are in the root directory, enter cd /usr/java. If it is in the usr directory, enter cd java directly. The root directory is followed by the ~ symbol, and the usr directory is followed by usr.

cd java
ls
tar –zxvf jdk-8u301-linux-x64.tar.gz

 

Check whether decompression is successful 

4. Delete the compressed package

 Delete compressed packages to free up disk space

rm -rf jdk-8u301-linux-x64.tar.gz
ls

5. Configure JDK

 Open text editor using vi command

vi /etc/profile

In English mode, press the i key on the keyboard or press shift + A to enter the editable state.

In the last line of text, add the following code

#java environment
export JAVA_HOME=/usr/java/jdk1.8.0_301
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin

 Press the esc key on the keyboard to cancel the editing state

Distinguish between editing and non-editing status to see if there is an INSERT flag

 After exiting the editing state, press :wq and press Enter to save and exit. (When the input is incorrect, or the file is modified, press :q! to exit without saving, and then try again)

 6. Let environment variables take effect

source /etc/profile

If no information is prompted below, it means the configuration is successful, otherwise it means the configuration is unsuccessful. 

7. Check whether the configuration is successful

java -version

If the following information is displayed, the configuration is successful.

 2. Mysql database environment installation

1. Upload the mysql installation package

Upload the mysql installation package to the opt directory of the server

 Check whether the upload is successful

2. Check whether mysql has been installed

rpm -qa|grep mysql

If there are other prompts later, it means that mysql has been installed and needs to be uninstalled. After pressing Enter, if there is no prompt message, just skip it and perform the next step.

yum remove mysql
rpm –qa|grep mysql
rpm –e mysql_libs
rpm -e --nodeps mysql_libs

3. Check whether there is mariadb

rpm –qa|grep maridb

If there is no prompt message below after pressing Enter to execute, you can skip this step and proceed to the next step. If so, perform uninstallation.

rpm -e --nodeps mariadb-libs

 Check if it has been uninstalled

rpm -qa|grep mariadb

 Press Enter to execute the command without any prompt, indicating that the uninstallation is complete.

4. Install mysql dependency package

yum install -y libaio
yum install -y numactl

If the form [y/d/n] appears and prompts you with the next step, just execute y directly. Or modify the above command directly to yum install –y libaio (-y means when installing software, the default choice is, similar to installing software on Windows system, click the next step)

5. Unzip mysql

tar -zxvf mysql-8.0.21-el7-x86_64.tar.gz

Check whether decompression is successful

 Delete compressed package

rm -rf mysql-8.0.21-el7-x86_64.tar.gz

6. Rename and move location

In the opt directory, rename the decompressed folder to mysql

mv mysql-8.0.21-el7-x86_64 mysql

 Move the /opt/mysql folder to /usr/local

mv /opt/mysql /usr/local/

Switch to the /usr/local/mysql directory, create the mysqldb folder in this directory, and check whether mysqldb is created successfully. In the box below, please fill in the appropriate code. 

cd /usr/local/mysql
mkdir mysqldb

7. Mysql installation directory and grant permissions

chmod -R 777 /usr/local/mysql

8. Create mysql group and user

Switch to the usr/local/mysql directory; and create a group

groupadd mysql

Create a user (-s /bin/false parameter specifies that the mysql user only has ownership, but no login permissions)

useradd –r –g mysql –s /bin/false mysql

Add user to group

chown –R mysql:mysql ./

Check whether the addition is successful

id mysql

9. Modify the mysql configuration file

 Open the etc/my.cnf file and edit it

vi /etc/my.cnf
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/mysqldb
# 允许最大连接数
max_connections=10000
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
# 是否对sql语句大小写敏感,1表示不敏感
lower_case_table_names = 1
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4

 10. Install mysql

Switch to the /usr/local/mysql/bin directory and perform the installation operation

./mysqld --initialize --console

After the initial installation is successful, be sure to remember the initialization password.

 11. Start msyql service

Grant permissions to the /usr/local/mysql directory

chmod -R 777 /usr/local/mysql

After granting permissions, switch to the /usr/local/mysql/support-files directory and execute the mysql.server start command.

A SUCCESS prompt means success, otherwise it means failure.

 12. Add mysql to the system process

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

13. Set mysql to start automatically

chmod +x /etc/init.d/mysqld
systemctl enable mysqld

If the prompt below appears, the setting is successful.

14. Modify root user login password

Switch to the /usr/local/mysql/bin directory and execute

./mysql -uroot -p

 Enter the initialization password for mysql installation and enter mysql

Change mysql login password to Root@2021

alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Root@2021';

 If the following prompt appears, it means the password has been changed successfully.

15. Set up to allow remote login

use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;

 If the following prompt appears, it means that the remote login setting is successful.

After modification, exit mysql.

16. Restart the service and test

systemctl restart mysql
systemctl status mysql

If there is a prompt below, it means success

 3. Redis environment installation and configuration

1. Install gcc dependencies

yum install –y gcc

2. Download and unzip the installation package

Switch to the /usr/local directory and perform the download operation. The redis version can be changed by yourself.

wget http://download.redis.io/releases/redis-5.0.3.tar.gz
ls

 Unzip the compressed package and write the command in the box below

tar -zxvf redis-5.0.3.tar.gz

3. Install and compile redis

Switch to the decompressed redis-5.0.3 directory and perform compilation and installation operations.

make

Install and specify the installation directory to the /usr/local/redis directory

make install PREFIX=/usr/local/redis

 4. Set up background startup

Copy redis.conf from the redis source code directory to the redis installation directory

cp /usr/local/redis-5.0.3/redis.conf /usr/local/redis/bin

 Switch to the /usr/local/redis/bin directory, open the redis.conf file, and edit it. Change daemonize no to daemonize yes

 Make the modified files effective

./redis-server redis.conf

5. Set up startup

Add a startup service, open the /etc/systemd/system/redis.service file, and modify the file content

[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 Set up start

systemctl daemon-reload
systemctl start redis.service
systemctl enable redis.service
ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

6. Set up remote connection to redis and set password

Open the /usr/local/redis/bin/redis.conf file, modify the remote connection address, and change bind 127.0.0.1 to bind 0.0.0.0

 Set the password, find the following line #requirepass foobared, remove the comment, and change the password to 123456

 After the modification is completed, restart the redis service

systemctl restart redis.service

 5. Install nginx service

1. Switch to the usr/local directory and download nginx1.20.1

wget http://nginx.org/download/nginx-1.20.1.tar.gz

After the download is completed, unzip it (the decompression command is omitted)

 Delete the nginx compressed package (the command to delete the compressed package is omitted)

 2. Install nginx

Install nginx dependent libraries

yum install -y gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

Switch to the nginx-1.20.1 directory and execute the following command

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module (the following instructions are to install the ssl or https protocol module)

./configure
make
make install

 3. Set nginx to start at boot

Switch to the /lib/systemd/system directory, open the nginx.service file, and add the following content

[Unit]
Description=nginx 
After=network.target 
   
[Service] 
Type=forking 
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true 
   
[Install] 
WantedBy=multi-user.target

After the modification is completed, save and exit, execute the following command

systemctl enable nginx.service

Execute systemctl start nginx.service to start the nginx service

systemctl start nginx.service

4. Modify nginx configuration file

Switch to the /usr/local/nginx/conf directory and open the nginx.conf file; make the following modifications to the configuration of port 80:

location / {
            root   /opt/office/web;
            index  index.html index.htm;
        }

location /api {
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://127.0.0.1:8010/api;
        }

location /upload {
                expires 24h;
                alias /opt/office/images;
        }

 6. Deploy java backend project

1. Upload the jar package

Switch to the /opt directory and create the office directory (the creation command is omitted)

Use the Xftp tool to upload the jar package to the /opt/office directory

 2. Start the jar package application in the background

Switch to the /opt/office directory

nohup java -jar office-registration-1.0-SNAPSHOT.jar > office1.log 2>&1 &

3. Check whether the back-end program is started

ps –ef|grep java

 

 7. Deploy front-end projects

1. Upload dist.zip to the /opt/office/web directory

 2. Unzip the dist.zip file and delete the compressed package

Guess you like

Origin blog.csdn.net/yu1431/article/details/131822414