Ali Yunduo Application Deployment Record

Keywords: MySQL Tomcat Database encoding

Deploying applications to servers is the last step in publishing. In theory, there should be professional teams and deployment platforms to deal with it. But for personal developers, at first it was only a bit shabby. Recently, many java applications need to be deployed on a server to record their ideas and operations.
Please refer to the previous article for installing the system environment: Construction of Ali Cloud Server Deployment Environment

System environment:
OS:         centos 6.8/2.6.32-696.3.2.el6.x86_64
jdk:        1.8.0_144
mysql:      5.1.7
tomcat:     8.0.36
maven:      3.5.0
git:        1.7.1

tomcat

Each application runs through a tomcat separately, so you need to copy tomcat once and configure each application separately. By default, you only need to modify conf/server.xml in the tomcat directory, mainly two ports:

<!--8080 It changed to 8081. URIEncoding="UTF-8"Plus to avoid Chinese scrambling-->
  <Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8"/>
<!--8009 Changed to 8010-->
    <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />

Because it is multi-application, it is a good practice to record the ports of each application.

Code

Code management uses the code warehouse provided by Aliyun: https://code.aliyun.com/
Establish a code base in the Aliyun Code Warehouse and submit the code to the code base
Create a code directory in the home directory, where you create a folder for each application, such as mine:

/home/lucas/code
├── buquan
└── ssm

After entering the project directory, the code git clone is downloaded, the `mvn clean package'is executed in the project root directory, and the packaged files are downloaded in the target directory.
The package is then copied to the corresponding tomcat webapps directory, provided that tomcat is concerned.

cp ./target/receptionaccount.war {tomcat-dir}/webapps/

Go to the tomcat directory, start tomcat and view the start log

 ./bin/catalina.sh start & tailf logs/catalina.out

data base

Create a separate database for each project and create tables.
One of the problems encountered is the encoding of MySQL. First, I build the table and start the application. As a result, the runtime error is reported.

SQL state [HY000]; error code [1366]ERROR: Incorrect string value: '\xE5\x95\x8A\xE5\xAE\x9E...' for column 'problem' at row 1

Obviously, it is a problem of character encoding set.
Processing method:

  1. Look at the JDBC connection string, configured with useUnicode = true & amp; characterEncoding = utf-8, no problem

  2. tomcat configuration < Connector > plus URIEncoding="UTF-8" has no effect

  3. Looking at the database character encoding set, there is a problem:

mysql>show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | latin1                     |
| character_set_connection | latin1                     |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | latin1                     |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql>show variables like 'collation_%';
+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database   | utf8_general_ci   |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)
mysql> STATUS
--------------
mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1

Connection id:      99
Current database:   accounting
Current user:       root@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.1.73 Source distribution
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    utf8
Client characterset:    latin1
Conn.  characterset:    latin1
UNIX socket:        /var/lib/mysql/mysql.sock
Uptime:         13 days 23 hours 26 min 16 sec

Threads: 2  Questions: 163  Slow queries: 0  Opens: 30  Flush tables: 1  Open tables: 15  Queries per second avg: 0.0
--------------

Then modify the character encoding set of the database

alter database accounting character set 'UTF8';

Still wrong
4. Modify MySQL configuration file, sudo vim/etc/my.cnf
Add default-character-set=utf8 under [mysqld]
I don't have [client] configuration, manually add [client] default-character-set=utf8, and finally configure it

[client]
default-character-set=utf8

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Restart MySQL

sudo /etc/init.d/mysqld stop
sudo /etc/init.d/mysqld start

Sure enough, it came into effect:

mysql> show variables like 'collation_%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

But it still makes a mistake.
5. Look again at the configuration of the data table:

mysql> SHOW FULL COLUMNS FROM user;   

Collation s are all latin1_swedish_ci
So modify the data type of the table field

ALTER TABLE user CONVERT TO CHARACTER SET utf8

Try again and succeed.
Almost all the places involved in the coding set have been modified.

Nginx configuration

//TODO

Posted by ryanhowdy on Tue, 21 May 2019 16:55:10 -0700