Score Query System-publishing-centOS7tomcat startup + mysql Database Configuration

Source: Internet
Author: User
Tags jboss server

Score Query System-publishing-centOS7tomcat startup + mysql Database Configuration
Prerequisites

The score query system is put into use and deployed on a linux server. It is a centOS7 system. previously, centOS7 was installed in the local virtual machine and a blog was written. this time, the system has been installed. I don't need to install it again. Then, the jdk environment is ready before and mysql has been installed (but it has never been put into use ), the jboss server is also installed, but my project uses tomcat, so I only need to install a tomcat.

Tomcat installation

First of all, download from tomcat official website, tomcat linux version, I download tomcat 7, version is: apache-tomcat-7.0.62.tar.gz. for this operation, I directly used a graphical interface, decompress it, put it under/usr/local, and rename it tomcat. installation steps:

Then start tomcat, enter the command [cd/usr/local/tomcat], and enter the command [. /bin/startup. sh],. at the start of the startup, the system said there was no permission, so it logged on with root and changed the permission to 777. The command [chmod 777 startup. sh]; later, it was found that it still could not be started, so the setclasspath in the bin directory. in the sh file, add java_home and jre_home (based on the actual situation. main reference: tomcat cannot be started in linux

 

export JAVA_HOME=/opt/zimbra/jdk1.6.0_31export JRE_HOME=/opt/zimbra/jdk1.6.0_31/jre 
Later, tomcat starts successfully. When it starts successfully, the producer will output a text, followed by tomcat start. enter localhost: 8080. You can access it. then we deployed our system. At the very beginning, we put the source code in a zip package. Later we found that it was not automatically deployed under tomcat's webapps. later, I thought that my project is a dynamic web project. I should pack it into a war package, put it under webapps, and then start tomcat to automatically deploy it. so I typed a war package again and it was enough.

 

I thought everything was done, but I found two problems later. first, tomcat is not set to start automatically at startup, so every time the server is turned on, I need to manually enter [cd/usr/local/tomcat], and then enter [. /bin/startup. sh], start tomcat by yourself. the second is that the mysql database connected to our project is on my computer. In this way, every time I use a project, my computer must be in the Enabled state, in this case, the data on my computer is very insecure, so we need to change the database to mysql on linux.

Start tomcat

It is relatively simple to start tomcat at startup. for details, refer to the linux Tutorial: [4] how to configure Tomcat to start upon startup. The steps are very detailed and clear (except for some pictures and texts, and the main figure is better ).

Step 1: Modify startup under tomcat. sh file, switch to the bin directory of tomcat, and then use the command [vi startup. sh], Open start. sh file. You can also find the file on the graphical interface and open it directly. next [#! /Bin/sh] add three sentences below this sentence.

 

#chkconfig: 2345 80 90    #description:tomcat auto start    #processname: tomcat
Among them, chkconfig is the key to being added to auto-start. Do not write the wrong word. at the beginning, because the operation was not skillful, although it was copied in the past, but it was accidentally changed to kconfig. Therefore, the following command [chkconfig -- list] reported an error, and tomcat service does not support chkconfig. because that sentence is to find the # chkconfig: 2345 80 90.

 

By the way, use vi to enter startup. sh file, click esc, and then click I to see the words -- insert --, which indicates that you can enter. after modification, Press esc and enter [: wq] to save and exit. another method is to find the file. after entering the file, enter [. /], then you will see [/], and then enter the text you want to search for, such as export, after the [/] command, so the input is complete, in this case, the [/export] will automatically jump to the next export when you press Enter.

Step 2: complete startup. sh to edit catalina. sh is in the bin directory of tomcat. find [export QIBM_MULTI_THREADED = Y] According to the vi search method, and add three environment variables next to this. the three statements are the tomcat installation directory (based on your actual situation). The actual path of my tomcat is/usr/local/tomcat. after modification, [: wq], save and exit.

 

export CATALINA_BASE=/usr/local/tomcatexport CATALINA_HOME=/usr/local/tomcatexport CATALINA_TMPDIR=/usr/local/tomcat
Step 3: Set startup. sh to make a shortcut, put the shortcut in/etc/rc. d/init. d, the name is tomcat7. you can also consider directly using catalina. sh, directly copy it to this directory, and make some modifications. rename it tomcat7. refer to this article: linux Tomcat 7 is automatically started.

 

The command is like this [ln-s/usr/local/tomcat/bin/startup. sh/etc/rc. d/init. d/tomcat7], and then from the interface, you can see in init. d. There will be a shortcut pointing to startup. sh file.

Of course, from the terminal, switch to the [cd/etc/rc. d/init. d], and then use ll or ls to check whether there are executable permissions. Generally, if not, you can add executable permissions or add all permissions. the command is [chmod + x tomcat7] or [chmod 777 tomcat7].

Step 4: add tomcat to the startup service and run the command [chkconfig -- add tomcat7]. If [tomcat service does not support chkconfig], check startup. at the top of sh, are the three statements of chkconfig correct.

Step 5: Check whether the file is successfully added. Run the [chkconfig -- list] command to check whether the file is successfully added.

 

Tomcat 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
Step 6: restart linux and enter localhost: 8080 as soon as it is started to check whether it can be used. If it can be used, it indicates that it is successful. If it cannot be used, please find the information to solve it.

 

The above is the process of self-starting tomcat configuration.

CentOS mysql

After the problem of tomcat is solved, mysql is switched from my computer 35 to server 244. Many problems have been encountered.

Initialize mysql password

First, I want to find out where mysql is in linux or how to open it. open the terminal anywhere and enter the command [mysql-u root-p]. Then, enter the password and root.

 

[Root @ bogon desktop] # mysql-u root-pEnter password: ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: YES)
Here an error occurs. You need to set the initialization password. Enter the command [mysql_secure_installation], and you will be asked to change the password later and confirm the password. All the places with background below are the places where I entered the value.

 

 

[Root @ localhost/] # mysql-u-root-p
Enter password:
ERROR 1045 (28000): Access denied for user'-root' @ 'localhost' (using password: YES)
[Root @ localhost/] # mysql_secure_installation
NOTE: running all parts of this script is recommended for all MySQL
Servers in production use! Please read each step carefully!
In order to log into MySQL to secure it, we'll need the current
Password for the root user. If you 've just installed MySQL, and
You haven't set the root password yet, the password will be blank,
So you shoshould just press enter here.
Enter current password for root (enter for none ):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
Root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n '.
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables ..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
To log into MySQL without having to have a user account created
Them. This is intended only for testing, and to make the installation
Go a bit smoother. You shoshould remove them before moving into
Production environment.
Remove anonymous users? [Y/n] n
... Skipping.
Normally, root shoshould only be allowed to connect from 'localhost'. This
Ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
... Skipping.
By default, MySQL comes with a database named 'test' that anyone can
Access. This is also intended only for testing, and shocould be removed
Before moving into a production environment.
Remove test database and access to it? [Y/n] n
... Skipping.
Reloading the privilege tables will ensure that all changes made so far
Will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
All done! If you 've completed all of the above steps, your MySQL
Installation shoshould now be secure.
Thanks for using MySQL!
Cleaning up...
After the password is changed, enter the command and enter the password.

 

 

[Root @ localhost/] # mysql-u root-p
Enter password:
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 12
Server version: 5.6.24 MySQL Community Server (GPL)
Copyright (c) 2000,201 5, 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.

 

Create databases and tables

 

In this way, create the database officialsystem and run the [create database officialsystem] command. then, restart tomcat, the process is quite tangled, I rely on restarting the linux server to restart tomcat, I do not know why I shutdown. sh tomcat, and then startup. sh does not work. Later, I thought that I could actually Delete the unzipped files automatically deployed by tomcat in webapps. then, let him re-deploy the package based on the war package stored in webapps.

Later, I found that the code we wrote was very problematic. first, I originally had four tables, but after tomcat is restarted, there are only three tables in the database, because the previous Entity's Official id type was int, but then changed to String, then, the auto-increment generation policy [@ GeneratedValue] is not removed from the id. then, the comment is deleted and four tables are successfully generated.

Then, write data to the Users table, and manually write data using the insert into statement, which can be tested. log on to the background with the Administrator account you just wrote and want to write data to the backstage table. However, the modification failed. previously, we updated all the functions, but we did not have the original write function. therefore, we need to initialize the data, so we manually added a piece of data in the backstage, all written 1.

Mysql Workbench remote connection to mysql in linux

Then I want to update the backstage table and find whether it still fails. Then I put the update Statement on the mysql graphical interface and found it was a Chinese garbled problem.

Describe Mysql connector. After installation, the workbench is successfully installed.

Then remote connection to mysql, it is more tragic. Because I do not have, I will provide a picture of others. Reference: Install MySQL5.6.22 under the CentOS-7

Unable to connect, mainly to do two steps, 1. Give the user remote access permissions; 2. Disable the firewall.

Step 1: ON the terminal, enter mysql and enter [grant all privileges on *. * TO 'root' @ '%' identified by 'Here is your password' with grant option;]. Change the password TO your real password. do not write the password [grant all privileges on *. * TO 'root' @ '%' identified by ''with grant option;], you can directly execute this statement so that you can access it without entering a password.

My role is to set all user names to remotely access all the tables in mysql. If you do not want to open them, you can set them according to this rule. grant permission 1, permission 2 ,... Permission n on database name. Table name to user name @ user address identified by 'Password'. I wrote this sentence for reference, MYSQL remote login permission settings.

Step 2: After the permission is set, you can close the firewall. First of all, it is said that centOS7 is different from the previous one to disable firewall.

 

[Root @ bogon desktop] # systemctl stop firewalld. service # stop firewall [root @ bogon desktop] # systemctl disable firewalld. service # disable firewall startup
Enter the preceding two sentences to stop firewall and disable the startup of friewall. Before this operation, you can use [systemctl list-unit-files]. to view the startup status of the system. At that time, the firewall status was enable, and it became disable.

 

Run [systemctl stop firewalld. service. later, I restarted my computer and directly entered [systemctl stop firewalld. service] No problem, so I think it may be because I did not enter it in the desktop path.

Now that the firewall is disabled, install iptables and disable iptables permanently. in fact, I don't know why to disable iptables after it is installed. in this case, do not install it. but I did.

According to the statement, although the default centOS is not iptables, it is also installed, so configure open rules for port 3306. edit the iptables file. enter the command [vi/etc/sysconfig/iptables] and add the [-ARH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT].

 

[Root @ bogon desktop] # vi/etc/sysconfig/iptables
# Sample configuration for iptables service
# You can edit this manually or usesystem-config-firewall
# Please do not ask us to add additionalports/services to this default configuration
* Filter
: Input accept [0: 0]
: Forward accept [0: 0]
: Output accept [0: 0]
-A input-m state -- stateRELATED, ESTABLISHED-j ACCEPT
-A input-p icmp-j ACCEPT
-A input-I lo-j ACCEPT
-ARH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT
-A input-p tcp-m state -- state NEW-m tcp -- dport 22-j ACCEPT
-A input-j REJECT -- reject-withicmp-host-prohibited
-A forward-j REJECT -- reject-withicmp-host-prohibited
COMMIT

Disable the firewall iptables permanently and restart the server.

 

 

[Root @ bogon bin] # chkconfig iptables off note: the request is being forwarded to "systemctl disableiptables. service ".
After running the preceding commands, restart the server computer and use mysql workbench to connect to the server.

 

Mysql Chinese garbled

Back to the problem we just encountered, update the data, and the data contains Chinese characters. The error is probably like this.

ERROR 1366 (HY000): Incorrect string value: '\ xE8 \ x8B \ xB1 \ xE5 \ xAF \ xb8...' for c
Next, we need to change the mysql encoding to UTF-8. this problem has been solved in mysql of my window, mainly by changing my. INI file, change latin1 to UTF-8.

 

[mysql]default-character-set=utf8

 

Start from scratch. First, you need to enter mysql from the terminal, or enter [show variables like 'character % '] in mysql weork.pdf.

Then we found that the database and server are both latin1, so we need to change these two to UTF-8. enter the command [vi/etc/my. cnf], open and find my. the content in cnf is less than that in all the documents I have seen. for example, in this article, the problem of MySQL Chinese garbled characters installed in CentOS 6.5 is solved.

 

[Client] default-character-set = utf8 # this is what I added

 

Only this sentence was added by him, but my. cnf does not have [client], nor [mysql], and only one [mysqld]. so according to this article, I asked MySQL to support Chinese content modification in CentOS7, basically all of which he provided were copied. For example, he added the last sentence in [mysql, I copied all three sentences.

[Mysql]

No-auto-rehash

Default-character-set = utf8

Finally, I added these things. In the end, this is probably the case. For mysqld, it not only changes the server encoding, but also sets the encoding of the newly created database and table.

 

[mysqld]port = 3306socket = /var/lib/mysql/mysql.sockdefault-storage-engine=INNODBcharacter-set-server=utf8collation-server=utf8_general_ci[client]port = 3306socket = /var/lib/mysql/mysql.sockdefault-character-set=utf8[mysql]no-auto-rehashdefault-character-set=utf8

 

Then, enter [service mysql restart] on the terminal to restart the mysql service. if the terminal is in mysql, enter exit to exit mysql. enter [service mysql restart. PS, if your my. if there is a problem with cnf copying, [service mysql restart] will be executed for a long time, indicating that it is unsuccessful. if there is no problem, restart in about 3-4 seconds.

Then check [show variables like 'character % ']. The database encoding is successful, all of which are UTF-8, except for filesystem, which is always binaray and binary.

Then, just in case, re-create the database officialsystem and run the [show create databse officialsytem] command to check that the database encoding is utf8.

Next, initialize the Administrator data and backstage data and update the backstage data through the interface.

Import data in excel to mysql

The last step is to import the real data in official. here we need to explain that, because we only write the @ Entity label on the Entity, but not the table name, in mysql of window, the table generated by hibernate is in lowercase, for example, if the object is Official and the table is official, but the table generated by mysql and hibernate in linux is the same as the object, the Official table is still Official, they all felt very difficult. Why didn't I set a default table name.

Then, the data is moved to the database, and the observed results are very slow. On average, two pieces of data are written in one minute. at the beginning, I thought it was a problem with the number of connections, so I modified my. in the cnf file, add [max_connections = 1000] under [mysqld]. restart mysql [service mysql restart] and run it again.

PS, in addition to completely modifying the maximum number of connections, there is also a temporary way, that is, in the terminal mysql, first enter [show variables like 'max _ connections '], check the current maximum number of connections and enter [set global max_connections = 1000]. This is only valid in the current mysql service process. Once mysql is restarted, it will return to the initial state. refer to the Centos script for modifying the maximum number of concurrent connections of the Mysql database. [display the currently running Query: mysql> show processlist;]. This command is quite useful, after I solved the following problem, I used this to observe the running status. At that time, I mainly performed 3-4 records, mainly 35 records. When I connected the database, I noticed that the time was 10 at the beginning, after refreshing, it is changed to 6 and then to 2. the data is imported normally.

Later, I carefully observed the code and found that the Code looked like this,

 

Public class DBHelper {String driver = "com. mysql. jdbc. Driver"; String url = "jdbc: mysql: // localhost: 3306/officialsystem? UseUnicode = true & characterEncoding = UTF-8 "; Connection con = null; ResultSet res = null; // Connection to the DataBase, very slow public void DataBase () {try {Class. forName (driver); con = DriverManager. getConnection (url, "root", "root");} catch (ClassNotFoundException e) {// TODO Auto-generated catch block System. err. println ("failed to load JDBC/ODBC driver. "); E. printStackTrace ();} catch (SQLException e) {// TODO Auto-generated catch block System. err. println ("unable to connect to Database"); e. printStackTrace () ;}/// Add/delete public int AddU (String SQL, String str []) {int a = 0; // execute DataBase () every time (); try {PreparedStatement pst = con. prepareStatement (SQL); if (str! = Null) {for (int I = 0; I <str. length; I ++) {pst. setString (I + 1, str [I]) ;}} a = pst.exe cuteUpdate ();} catch (Exception e) {e. printStackTrace () ;}return ;}}
The addU method will execute DataBase () every time to connect to the DataBase. In my later observations, this process is very slow, so I changed the code to this

 

 

Public class DBHelper {Connection con = null; ResultSet res = null; // Connection database public DBHelper () {String driver = "com. mysql. jdbc. driver "; String url =" jdbc: mysql: // localhost: 3306/officialsystem? UseUnicode = true & characterEncoding = UTF-8 "; try {Class. forName (driver); con = DriverManager. getConnection (url, "root", "root");} catch (ClassNotFoundException e) {// TODO Auto-generated catch blockSystem. err. println ("failed to load JDBC/ODBC driver. "); E. printStackTrace ();} catch (SQLException e) {// TODO Auto-generated catch blockSystem. err. println ("unable to connect to Database"); e. printStackTrace () ;}}// Add/delete public int AddU (String SQL, String str []) {int a = 0; try {PreparedStatement pst = con. prepareStatement (SQL); if (str! = Null) {for (int I = 0; I <str. length; I ++) {pst. setString (I + 1, str [I]) ;}} a = pst.exe cuteUpdate ();} catch (Exception e) {e. printStackTrace () ;}return ;}}
Then, at the very beginning, there was no response in 10-15 seconds to connect to the database, and then the data was inserted into the database very quickly. after about 20 seconds, 450 data records inserted.

 

Finally, update the isTrue fields in the Official table to "yes", but use [update officialsystem. after Official set isTrue = 'yes'], No. refer to: Error Code: 1175. you are using safe update. Change the mysql running mode to 0. If the running mode is 1, the update or delete command cannot be executed without the primary key. therefore, in mysql, enter [set SQL _SAFE_UPDATES = 0] And then update it. then change it back and enter [set SQL _SAFE_UPDATEA = 1], so that the database security level is relatively high.

PS, because the primary key of the Official table is of the String type, but the value is actually. To view this, enter [select * from Official order by-id desc], you can sort the data from small to large. The difference is that [-] is added before the id.

At this point, tomcat's self-start and mysql database switching are complete. I checked a lot of information, tried n times, and finally completed. in order to prevent me from forgetting, I immediately wrote this blog to commemorate the fact that I checked more than n pieces of information.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.