Location>code7788 >text

Spend 100 bucks to make a small fishing website! First - Buying a Cloud Server and Initializing the Environment

Popularity:908 ℃/2024-08-05 08:31:48

I. Preface

Hello, I'm Summo, and I've already written about why I'm doing this.a small website that catches fishI'm going to talk to you step-by-step about how I built this website from the start of this post. I know that for many newbies, building a website can be quite overwhelming and you don't know where to start, so I'll try to make it as simple and clear as possible, so that you can understand it at a glance and take the road less traveled.

Let's start with buying a server. It seems that AliCloud has a free trial now, which is a good deal for newbies. However, whether you are free to use or pay money to buy, after getting the server, the first thing is to get the environment to tidy up. It's just like decorating a new house, the foundation is laid well, and only after that can things go smoothly. For usa small website that catches fishTo say, must be the environment is JDK, Redis, MySQL, how to build these environments online article a whole lot, but always this has a problem that has a problem, so I also write a copy of the problem we have a comment area to exchange.

Second, buy cloud servers (also known as Elastic Compute Service, ECS)

Click on this.link (on a website)You can go to the official website of AliCloud, I bought the2 core 2G, 3M fixed bandwidthThis, 99 a year, lasts 3 years. Here's a point to note, the mirror image I chose wasCentOS 7.9 64-bitThe way of installing the environment is also a bit different for different mirrors, for example, Centos usually uses yum to download the installer while Ubuntu uses apt-get, although they are generally similar, but I am only familiar with Centos. if you don't know how to do this, you'd better choose the same as me.

If you want to try it out first, slide to the bottom to find the

Once you've bought it, go to the ECS console and you can find the instance you just bought. We can see that it has two IPs.private IPcap (a poem)public IPThe public IP can be pinged, if your website is ready, you can share this public IP with your friends, they can directly access your website.

strike (on the keyboard)remote connectionYou can log in to the server remotely, enter the control interface and start deploying your environment!

You need to set a password when you log in for the first time, and you can also reset your password over here if you forget it later.

Third, install jdk

JDK then I will not install the recently popular 17 and 21, or use our old friend JDK8 it, on Windows to install the JDK is more trouble, and environment variables and so on, but in Centos7 on the installation is very convenient, do not worry, do not read those wild documents on the line.

1. Check the JDK version

yum list |grep java-1.8.0

As you can see there are still a lot of versions available, let's download thejava-1.8.0-openjdk-devel.x86_64This one.

2. Download JDK

yum install java-1.8.0-openjdk-devel.x86_64 -y

After downloading it will automatically install, environment variables do not have to care, do not have to match this and that, very convenient.

3. View the JDK environment

java -version

IV. Installing Redis

Redis installation is also very simple, a few lines of commands, follow my steps, the probability is that there will not be any problems.

1. Download Redis

sudo yum install epel-release -y
sudo yum update -y
sudo yum install redis -y

2. Start the Redis service and set it to boot up.

sudo systemctl start redis
sudo systemctl enable redis

3. Verify that Redis is running

redis-cli ping

4. Connecting to Redis remotely

We all know that Redis port is 6379, although the server Redis started, but the local currently still can not connect, want to connect to Redis locally, but also need some settings.

(1) Modify Redis configuration to support public access

## Open the Redis configuration file
vim /etc/

Find these three parameters below:

## Bind the ip to allow access
bind 127.0.0.1
## Protected mode on
protected-mode yes
## Request password for access
## requestpass yourpassword

One or two items is a combination of items, especially important, the third item is to set the password, you can play the role of permission authentication. Modified as follows:

## Comment out this line directly
##bind 127.0.0.1
## Disable protected mode
protected-mode no
## Set your password
requirepass xxx

Finally restart Redis

systemctl restart 

(2) Open port 6379 on the server's firewall

## Check firewall status
sudo systemctl status firewalld
## Turn on the firewall
sudo systemctl start firewalld
## Enable external access to 6379
sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent
## Reboot the firewall
sudo firewall-cmd --reload
## View current ports for external access
sudo firewall-cmd --zone=public --list-ports

Only open port 6379 on the server is still not enough, you also need to modify it in the Aliyun ECS platformSecurity Group RulesThis is something that many students are not very clear, I will briefly say: ECS security group is to prevent people from indiscriminately opening ports to cause their services to be attacked, to give you a pocket of protection.

(3) Aliyun security group configure port 6379

Click to manage rules

Click Quick Add to select Redis, and finally click OK.

It's very simple, isn't it! But if I do not say a little, we are likely to half a day do not know why their Redis connection is not, about this security group, there are still some things to pay attention to, such as authorizing the IP for 0.0.0.0 is effective for all network segments, and often configured later, encountered again.

5. Connectivity tools

RedisInsight (recommended)

V. Installing MySQL 8.0

The database is very important to us as aa small website that catches fishIt is the most important, but its installation is also the most complicated. I also searched a lot of information, or just stepped on a lot of pits, if you really can not get it, theWe recommend that you directly use the AliCloud that free 3-month use of RDS, the results are better

1. Download MySQL 8.0

Execute the download command

## Create the MySQL directory
mkdir /usr/local/mysql

## Switch to the MySQL directory
cd /usr/local/mysql

## Download the MySQL installer
wget /archives/mysql-8.0/mysql-8.0.35-1.el7.x86_64.

## Extract the MySQL installer
tar -xvf mysql-8.0.35-1.el7.x86_64.

2. Preparing the installation environment

Run the following commands in sequence:

yum update -y

yum install -y libaio
yum install -y net-tools
yum install openssl-devel.x86_64 openssl.x86_64 -y

yum -y install autoconf
yum install perl.x86_64 perl-devel.x86_64 -y
yum install  -y
yum install perl-Test-Simple -y

Mariadb should be uninstalled or the later installation will also report errors, do not know what the reason, query the installed mariadb

## 'xxxx' stands for rpm -qa | grep mariadb Show all names, if there are more than one, then repeat to remove more than one
rpm -qa | grep mariadb

## Be sure to remove them all
rpm -e --nodeps filename

The above command is to resolve the dependency environment issue when installing mysql8. (If the above command fails to run it may affect the next installation)

3. Installing MySQL8

In the /usr/local/mysql8 directory, run the following commands in order to install MySQL8. Note that the following commands cannot be run in reverse order and must be run strictly in the following order:

rpm -ivh mysql-community-common-8.0.35-1.el7.x86_64.rpm   
rpm -ivh mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm 
rpm -ivh mysql-community-libs-8.0.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.35-1.el7.x86_64.rpm 
rpm -ivh mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.0.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.35-1.el7.x86_64.rpm  

4. Setting up the configuration file

Edit the /etc/ file to set the following parameters for MySQL (just choose as needed)

[mysqld]
# Set the port number on which the MySQL service runs
port = 3306
# Specify the default character set for the MySQL database
character-set-server=utf8mb4
# Allow external access
bind-address=0.0.0.0

# Set the character set when client connects to mysql, to prevent garbled code
init_connect='SET NAMES utf8mb4' # Set the character set when client connects to mysql to prevent garbage.

# Set the maximum number of connections allowed for MySQL access
max_connections = 1000

# Specify the directory where the MySQL server stores the data files
datadir=/var/lib/mysql

# If or not the sql statement is case sensitive, 1 means it is not.
lower_case_table_names = 1

# Transaction isolation level, the default is repeatable read, mysql default repeatable read level (this level may parameterize a lot of gap locks, affecting performance)
transaction_isolation = READ-COMMITTED

# TIMESTAMP if no display declaration NOT NULL, allow NULL values
explicit_defaults_for_timestamp = true

5. Directory authorizations

chown -R mysql:mysql /var/lib/mysql/

6. Starting MySQL

## Start MySQL
systemctl start

## Check MySQL status
systemctl status

## Enable self-start
systemctl enable mysqld

7. Connecting to MySQL

(1) Configuring MySQL to Support Remote Access

A temporary password will be generated after starting mysql, use this command to query the temporary password.

grep "A temporary password" /var/log/

To log into MySQL with this password, the login command ismysql -u root -p Press enter and enter the temporary password you just saw.
Once inside, we set a new password for the root user with the following command:

# Change the password, pay attention to the password strength check, here set the password to xxx (your password)
ALTER USER 'root' @'localhost' IDENTIFIED WITH mysql_native_password BY 'xxx(your password)';
# Flush Privileges
FLUSH PRIVILEGES;

Setting up to allow root remote login

UPDATE  SET host='%' WHERE user='root';
FLUSH PRIVILEGES;

(2) Open port 3306 on the server's firewall

## Enable 6379 for external access
sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
## Reboot the firewall
sudo firewall-cmd --reload
## View current ports for external access
sudo firewall-cmd --zone=public --list-ports

As with Redis, you also need to go to AliCloud's security group and release port 3306.

(3) AliCloud security group configuration 3306

Click Quick Add to select MySQL, and finally click OK.

8. Connectivity tools

You can choose from Navicat (best, but charges), DBeaver (not bad, free), and MySQL-Front (not bad, free).

VI. To summarize

Once upon a time, the installation of the environment and scaffolding is my biggest fear, too much knowledge of the blind spot, failure do not know the reason, this thing even if someone else's documentation written in detail, the turn to install their own but always encountered strange and strange problems, and sometimes doubt that they are not a BUG body. Here I would like to remind everyone, if you are a novice, the installation environment, do not give yourself a drama, consider this and that, this is not safe that to personality, do not engage in this way, failing ten million times as well as succeeding once!

My installation tutorial this time is directly on the server operation, the installation package are downloaded with the command, the probability of problems should not be too big, there are problems in the comments section to exchange. As I said at the beginning, it's just like decorating a new house, if you build a good foundation, the rest will go smoothly. Don't be in a hurry, engineering is much more interesting than studying the source code, and the sense of acquisition is very strong. All hands on deck, everyone!

Most of the students most of the time are just doing CRUD work, there is no independent experience in building a website, although there is no but can learn! Now will not practice will be! 100 dollars of hands-on experience is definitely more meaningful and useful than 100 dollars to buy the column!

Finally.Self-built groping websiteThe main site hot search at a glance, go to work and touch the fish is a good match oh!