Imitation cattle project deployment

Aliyun ECS

  • This is a one-month free trial , the basic operations are clearly written in the documentation
  • Configuring CentOS 7.6 64-bit
    2 vCPU 4 GiB (I/O optimized)

Download PuTTY

  • The password entered when connecting to Aliyun should be set here

Download the required tools to root

I can't use the teacher's method of copying the link address. The following is the same download address as the teacher's version.
The connection failure may be a network problem, try again a few times, or change the network, change the time period

cd /root
  • MySQL
wget -i -c https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
  • Maven
wget -i -c https://archive.apache.org/dist/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz
  • Elasticsearch
wget -i -c https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.3.tar.gz
  • Chinese plugin for Elasticsearch ik
wget -i -c https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.3/elasticsearch-analysis-ik-6.4.3.zip
  • Tomcat
wget -i -c https://downloads.apache.org/tomcat/tomcat-9/v9.0.68/bin/apache-tomcat-9.0.68.tar.gz
  • Kafka
wget -i -c https://archive.apache.org/dist/kafka/2.3.0/kafka_2.12-2.3.0.tgz
  • Install JRE
yum list java*
yum install -y  java-1.8.0-openjdk.x86_64 
java -version
  • Upload files from local
    -> Compress the file to upload
    -> Open the command line in the compressed file directory and execute the following command
    -> Then ask if you want to add the key to the cache, I choose y (there is no such step when uploading for the first time)
    -> Then enter the password
pscp Compressed file.zip root@public net IP:/root

  • Check the files in the root directory at this time in PUTTY and should be as shown below

I slipped an extra ik,

Install an unzip tool

yum list unzip*
yum install -y unzip.x86_64

Configure Maven

- unzip to /opt under the path
tar -zvxf apache-maven-3.6.1-bin.tar.gz -C /opt
cd /opt
- Bundle Maven add the path to the system path
vim /etc/profile

❗ ❗ ❗ For those who have no experience with Linux, they may not be able to keep up with the rhythm of the teacher at all (I almost tried most of the keyboards, only to find that the INSERT operation is to press the insert key 😅), here are some simple operations, You can try to save yourself

Press the letter "i" to enter "INSERT" mode

Click "Esc" on the upper left of the keyboard to exit "INSERT" mode

:wq exit vi after saving, if it is :wq!, it is forced to exit after saving

:w save without exiting

:w! Forcibly write the file if the file attribute is "read-only"

:q leave vi

:q! If you have modified the file and don't want to save it, use ! to force quit without saving the file.

:e! Restore the file to its original state!

If you use the above button to change the /etc/profile file beyond recognition, you can create a new ECS and start over.
(If there are too many instances created that exceed the free permissions, click the release settings in the figure below)

- At the end of the file add:
export PATH=${PATH}:/opt/apache-maven-3.6.1/bin
- make the file valid
source /etc/profile
- an examination
mvn -version
cd config
- Open configuration file
vim settings.xml
- the local maven Copy the image to the server (you can adjust the display range of the file by pressing the up and down buttons)
<mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
      </mirror>

Configure MySQL

- Install MySQL
yum list mysql*
cd /root
ll
yum install -y mysql80-community-release-el7-3.noarch.rpm
- search again
cd /
yum list mysql*
- Install MySQ server
yum install -y mysql-community-server.x86_64   

❗ ❗ ❗The mysql version is wrong, uninstall it
Error:

The GPG keys listed for the "MySQL 8.0 Community Server" repository are already installed but they are not cor rect for this package.
Check that the correct key URLs are configured for this repository.

  • Add --nogpgcheck after the instructions to install the MySQL server
- start up MySQL
systemctl start mysqld
- Check MySQL status
systemctl status mysqld
- turn up MySQL the original password
grep 'password' /var/log/mysqld.log
- Login to the database with the found password
mysql -u root -p
- Change the password of the database
alter user root@localhost identified by 'XXX';
- Sign out and sign in with new password
exit
mysql -u root -p
- Exit after confirming that there is no problem
exit
  • Import MySQL files
- back to root under the folder
cd /root
ll
- Unzip the uploaded file
unzip -d /root XXX.zip
ll
mysql -u root -p
- create database
create database community;
- import data table
source /root/XXX/init_data.sql;
- display table
showtables;
- Change the avatar path contains localhost path of
update user set header_url = 'http://images.nowcoder.com/head/760t.png' where header_url like '%localhost%';
exit

Configure Redis

cd /
yum list redis*
- Install redis
yum install -y redis.x86_64
- turn on redis
systemctl start redis
- an examination redis status
systemctl status redis
redis-cli
keys *
- quit
exit

Configure Kafka

- Enter root
cd /root
ll
- Bundle Kafka unzip to/opt under the folder
tar -zvxf kafka_2.12-2.3.0.tgz -C /opt
- Enter/opt under the folder
cs /opt
ll
- Enter config folder
cd config/
ll
- start up Zookeeper
bin/zookeeper-server-start.sh -daemon config/zookeeper.peoperties
- start up kafka
nohup bin/kafka-server-start.sh config/server.properties 1>/dev/null 2>&q &
- an examination
bin/kafka-topics.sh --list --bootstrap-server localhost:9092

Configure Elasticsearch

- decompress
tar -zvxf elasticsearch-6.4.3.tar.gz -C /opt
unzip -d /opt/elasticsearch-6.4.3/plugins/ik elasticsearch-analysis-ik-6.4.3.zip
- Modify the configuration file
cd /opt/elasticsearch-6.4.3/
ll
cd /config
vim elasticsearch.yml
vim jvm.options
- create a user
groupadd nowcoder
useradd nowcoder1 -p 123456 -g nowcoder
- Authorize the new user
cd /opt
chown -R nowcoder1:nowcoder *
cd /tmp
chown -R nowcoder1:nowcoder *
- switch to user: 
su - nowcoder1
cd /opt/elasticsearch-6.4.3
- switch back root
su -
- an examination
curl -X GET "localhost:9200/_cat/health?v"

Configure wkhtmltopdf

- return root path
cd /
yum list wkhtmltopdf*
- Install wkhtmltppdf
yum install -y wkhtmltppdf.x86_64
- install a virtual GUI server
yum list *xvfb*
yum install -y xorg-xll-server-Xvfb.x86_64
- test
cd /root/test
xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltoimage https://www.baidu.com 1.png
ll
- Write a script to wrap the above verbose code
cd /opt
vim wkhtmltoimage.sh
xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltoimage "$@"
ll
- Give wkhtmltoimage.sh Execute permission on this file
chmod +x wkhtmltoimage.sh
ll
- test
cd /root/test
/opt/wkhtmltoimage.sh https://www.baidu.com 2.png
ll

Configure Tomcat

cd /root
ll
- decompress tomcat
tar zvxf apache-tomcat-9.0.68.tar.gz -C /opt
-Bundle tomcat/bin The path is configured to the system environment variable
cd /opt/apache-tomcat-9.0.68/bin
ll
pwd
vim /etc/profile
(add in the file pwd)
vim /etc/profile
source /etc/profile
- verify
echo $PATH\
- start up tomcat
startup.sh
- closure tomcat
shutdown.sh
  • If it is a one-month trial version on Aliyun, you need to configure the port

Configure Nginx

cd /
yum list nginx*
- Install Nginx
yum install -y nginx.x86_64
- configuration file
vim /etc/nginx/nginx.conf
- start up nginx
systemctl start nginx 
- View status
systemctl status nginx 
  • Here is the same problem as tomcat, Aliyun trial version needs to configure port 80 on Aliyun

Modify project configuration

delete all default projects under tomcat

cd /opt/apache-tomcat-9.0.68/
ll
cd webapps
ll
rm -rf *
ll

Modify project configuration

  • application.properties
server.servlet.context-path=
  • global.js
var CONTEXT_PATH = "";
  • HomeController
@GetMapping("/")
    public String root(){
        return "forward:/index";
    }
  • Project package community.zip
  • Open cmd under the path of the project to upload the project
pscp -P 22 community.zip root@my own IP:/root
- source code decompression: 
unzip -d /root community.zip
cd community/
- ignore test:
mvn clean package -Dmaven.test.skip=true
  • If the following error occurs

No compiler is provided in this environment. Perhaps you are running on a JRE rather
than a JDK?

  • Solution
yum install -y java-devel
mvn clean package -Dmaven.test.skip=true
cd target/
ll
- copy ROOT.war arrive tomcat Down
cd target/
mv ROOT.war /opt/apache-tomcat-9.0.64/webapps/
- start up tomcat:
startup.sh

Posted by soapsuds on Sun, 23 Oct 2022 06:03:16 +0300