I bought Tencent cloud server on March 06, 2018 for Java background. Because this is the first time to use, so there is this article. This article will skip the purchase section and go to configuring Java and the background environment.Copy the code

Tools: Xshell and XFTP

Xshell: Connects to the remote server and operates the remote server using commands

XFTP: used to transfer files to the server

1. Connect to the server.

1. Use Xshell to connect to the server

Find the host in the management page of Tencent Cloud, set the user name and password, and remember the public IP and port number.

Open Xshell, enter the server address and port number, click Connect, enter the user name and password for the first time, which can be seen in the background of Tencent Cloud. If you remember the password, you do not need to enter it every time.

2. Reset the root permission password

After entering the screen, enter:

sudo passwd

Enter the new password + Press Enter * 3 times

3. Obtain the permission of the root directory of the usr user

Root instruction

su root

Enter the root password and press Enter

2. Configure the Java environment

1. Upload the DECOMpressed JDK environment package

1.1 Creating a Java Directory

mkdir /usr/local/java

1.2 Download the Linux installation package from the JDK official website, upload it to the server using XFTP, and copy the shell command to the /usr/local/java directory

1.3 Use the CD to go to a directory and decompress the software package

sudo tar xvf jdk-8u121-linux-x64.tar.gz

1.4 Deleting the Original Compressed package

sudo rm jdk-8u121-linux-x64.tar.gz

2. Change environment variables

2.1 Using vim to open the. Bashrc environment configuration file

sudo vim ~/.bashrc

2.2 Add at the end of the file (note that the folder name must match the JDK version number) :

Export JAVA_HOME = / usr/local/Java/jdk1.8.0 _161

export JRE_HOME=${JAVA_HOME}/jre

export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib

export PATH=${JAVA_HOME}/bin:$PATH

2.3 Save the configuration and exit, enter :wq, and press Enter

2.4 Application Environment Configuration

source ~/.bashrc

2.5 Verifying the Java Environment Is properly configured

java -version

Returns:

java version "1.8.0 comes with _161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
Copy the code

2.6 If Permission is not allowed, manually change directory permissions

Chmod 777 < folder name >

3. Configure Tomcat

1. Download the decompressed installation package

1.1 Download apache-tomcat-7.0.78.tar.gz from the tomcat website

1.2 Decompressing the installation package

Tar ZXVF - apache tomcat - 7.0.78. Tar. Gz

1.3 Deleting the Installation Package

Sudo rm apache tomcat - 7.0.78. Tar. Gz

2. Modify the initiator

2.1 Modifying the startup.sh startup file

CD apche -- tomcat 7.0.78 / bin

sudo vim startup.sh

2.2 Add the following information under esAC:

JAVA_HOME = / usr/local/Java/jdk1.8.0 _161

JRE_HOME = / usr/local/Java/jdk1.8.0 _161 / jre

PATH=$JAVA_HOME/bin:$JRE_HOME:$PATH

CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

TOMCAT_HOME = / home/ubuntu/apache tomcat -- 7.0.78

2.3 Save the configuration and exit: :wq

Start tomcat 2.4

sudo ./startup.sh

return

Using CATALINA_BASE:   /home/ubuntu/apache-tomcat-7.0.85
Using CATALINA_HOME:   /home/ubuntu/apache-tomcat-7.0.85
Using CATALINA_TMPDIR: /home/ubuntu/apache-tomcat-7.0.85/temp
Using JRE_HOME:        /usr/local/ Java/jdk1.8.0 _161 Using the CLASSPATH: / home/ubuntu/apache tomcat - 7.0.85 / bin/bootstrap jar: / home/ubuntu/apache tomcat - 7.0.85 / bin/tomcat - juli. Jar tomcat started.Copy the code

2.5 check

Enter localhost:8080 in the browser to view the Tomcat home page.

Close the tomcat 2.6

sudo ./shutdown.sh

If tomcat is closed

Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
Copy the code

Because Tomcat does not recognize environment variables, the setclasspath. Sh file needs to be modified

sudo vim setclasspath.sh

Since the javA_HOME and jRE_HOME environment variables are not recognized, we need to add them manually in the file header.

JAVA_HOME=/usr/local/ Java/jdk1.8.0 _161 JRE_HOME = / usr /local/ Java/jdk1.8.0 _161 / jreCopy the code

If tomcat can be shut down, the modification is complete.

Configure mysql

1. The installation of mysql

1.1 Linux Installing the mysql environment is as simple as executing the following commands step by step.

The password must be set during sudo apt-get install mysql-server

apt-get isntall mysql-client

sudo apt-get install libmysqlclient-dev

1.2 check

Check whether port 3306 is normal

netstat -an | grep 3306

If listen is displayed, the installation is successful

TCP 0 0 127.0.0.1:3306 0.0.0.0:* LISTENCopy the code

2. Log in to the mysql database

mysql -u root -p

Select login -u user name root and enter the password -p

Enter the password to log in to mysql

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1705 Server version: Ubuntu Copyright (C) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type'help; ' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
Copy the code

3. Create a remote mysql user

3.1 a lookup table

Displays the current database

show databases;

Displays the form for the current database

show tables;

3.2 Remote Access Users

Mysql default is native 127.0.0.1 to access the database. To access the database remotely, open the mysql server and create a new user to access mysql.

3.2.1 Opening the Server And Modifying the Configuration File

/etc/ mysql.cnf/mysql.cnf/mysql.cnf/mysql.cnf/mysql.cnf/mysql.cnf/mysql.cnf/mysql.cnf/mysql.cnf/mysql.cnf

CNF file in /etc/mysql.conf. d directory

3.2.2 Creating a User to Grant remote IP Access Permission:

Query the user table of mysql

select user,authentication_string,host from mysql.user;

3.2.3 Creating a User

Grant all PRIVILEGES on *.* to 'myuser' @'46.224.259.19' IDENTIFIED by 'password' with grant option;

Create user myuser using password to connect to mysql server from IP 46.224.259.19

Of course, the IP address can be changed to ‘%’, indicating any IP address, which is not allowed in actual environments.

3.2.4 Perform Flush PRIVILEGES after the operation. , reload the database.

Query again:

+ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + | user | host | + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + | myuser | 46.224.259.19 | | debian-sys-maint | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +------------------+---------------+ 5 rowsin set (0.00 sec)
Copy the code

3.2.5 exit

mysql>quit; Logging out of mysql

3.2.6 again check 3306 port netstat – an | grep, 3306

tcp6       0      0 :::3306                 :::*                    LISTEN
Copy the code

ok

Mysql >Delete FROM user Where user =’myuser’ and Host=’46.224.259.19′;

Reload Flush PRIVILEGES;

4. Start the database

4.1 Starting the Service

service mysql start

4.2 stop

service mysql stop

4.3 restart

service mysql restart

5. Navicat for MySQL connects to the database

Host name or address: < your server address >

Port: 3306 (default port)

User name: <mysql >

Password: < password corresponding to user name >

conclusion

1. You need to learn xshell instruction to better operate the server.

2. XFTP is very convenient to use, file transfer only need to drag past, upload, do not have permission to unlock permission.

3. You need root permission to operate the usr directory.

4. The default IP address of the server is localhost. You need to manually change the IP address and add the access account.

5. If “10061” is displayed when Navicat connects to the database, the database does not allow the access to this IP address. You need to modify the remote access permission.