CentOS install nginx+tomcat+java+mysql operating environment

This article introduces the process of setting up a server environment such as CentOS7 64 Java, Tomcat, MySQL, and Maven hot deployment.

Server: Tencent Cloud Server

The required tools (Xshell, Xftp, FileZilla and other sftp upload tools, jdk-8u101-linux-x64.tar.gz and apache-tomcat-9.0.0.M10.tar.gz) have been uploaded to Baidu Cloud [http://pan.baidu.com/s/1qYRms8G] (http://pan.baidu.com/s/1qYRms8G)

1、 tomcat official websitehttps://tomcat.apache.org/download

Java environment configuration

Environmental preparation

Use uname -r to determine how many bits the system is

Install Java JDK8.0

  1. Create a Java directory to store Java and Tomcat
  1. Use FileZilla to upload the downloaded jdk-8u101-linux-x64.tar.gz and apache-tomcat-9.0.0.M10.tar.gz to the Java directory (the transmission of the foreign server is very slow, and the domestic Times, but only two to three hundred KB, it may also be a computer problem)
  2. Unzip the uploaded jdk and rename it to jdk
  1. Configure environment variable Environment=JAVA_HOME=/usr/local/Java/jdk
  2. vim /etc/profile
  3. After opening, press the keyboard (i) to enter the editing mode, and copy the content below to the bottom
    JAVA_HOME=/usr/local/java/jdk PATH=JAVA_HOME/bin:PATH CLASSPATH=JAVA_HOME/jre/lib/ext:JAVA_HOME/lib/tools.jar export PATH JAVA_HOME CLASSPATH
  4. After writing, we press the keyboard (ESC) button to exit, then press (:wq) to save and close Vim.
  5. Use the source /etc/profile command to make it effective immediately
  6. Use java -version to verify that Java is successfully configured.

Install Tomcat9.0

  1. Unzip the Tomcat9.0 uploaded in the previous step in the Java directory
  1. The startup command is /usr/local/java/tomcat/bin/startup.sh
  2. After the startup is complete, you need to open port 8080 (the firewall of this version of CentOS7 uses firewall by default, which is different from the previous version using iptables. For firewall ports, please refer to the following reference documents)
  1. Then enter http://ip:8080 in the browser again, if you see the tomcat system interface, the installation is successful.
  2. Tomcat port 8080 cannot be accessed
  1. The shutdown command is /usr/local/Java/tomcat/bin/shutdown.sh

Self-start:

Edit the file /usr/local/java/tomcat/bin/catalina.sh (modify according to your own jdk path) At the beginning of the body of the file, that is, before the official code, add the following code about 99 lines

export JAVA_HOME=/usr/local/java/jdk

export JRE_HOME=/usr/local/java/jdk/jre

first step:

vim /lib/systemd/system/tomcat.service

[ Unit]
Description=tomcat
After=network.target
 
[ Service]
Type=oneshot
ExecStart=/usr/local/java/tomcat/bin/startup.sh   //Own tomcat directory
ExecStop=/usr/local/java/tomcat/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
 
[ Install]
WantedBy=multi-user.target

(2). Setting permissions

chmod 754 tomcat.service

(3). Start and close the service, set the startup to start

# Start service
systemctl start tomcat.service   
# Close service
systemctl stop tomcat.service   
# boot
systemctl enable tomcat.service 

MySQL

1. System environment

The system version after yum update upgrade is

[ root@yl-web yl]# cat /etc/redhat-release 
CentOS Linux release 7.1.1503(Core)

At the beginning, it was installed directly through this command:

1[ root@yl-web yl]# yum install mysql
2[ root@yl-web yl]# yum install mysql-server
3[ root@yl-web yl]# yum install mysql-devel

The installation of mysql and mysql-devel were successful, but the installation of mysql-server failed, as follows:

[ root@yl-web yl]# yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.sina.cn
 * extras: mirrors.sina.cn
 * updates: mirrors.sina.cn
No package mysql-server available.
Error: Nothing to do

Checking the information found that the CentOS 7 version removed the MySQL database software from the default program list and replaced it with mariadb.

There are two solutions:

1、 Method 1: Install mariadb

The MariaDB database management system is a branch of MySQL, which is mainly maintained by the open source community and is licensed under GPL. One of the reasons for the development of this branch is that after Oracle acquired MySQL, there is a potential risk of closing MySQL to the source, so the community uses branching to avoid this risk. The purpose of MariaDB is to be fully compatible with MySQL, including API and command line, so that it can easily become a substitute for MySQL.

Install mariadb, size 59 M.

[ root@yl-web yl]# yum install mariadb-server mariadb 

The related commands of the mariadb database are:

systemctl start mariadb #Start MariaDB

systemctl stop mariadb #Stop MariaDB

systemctl restart mariadb #Restart MariaDB

systemctl enable mariadb #Set boot up

So start the database first

[ root@yl-web yl]# systemctl start mariadb

Then you can use mysql normally

[ root@yl-web yl]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with; or \g.
Your MariaDB connection id is 3
Server version:5.5.41-MariaDB MariaDB Server

Copyright(c)2000,2014, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h'for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               |+--------------------+4 rows inset(0.00 sec)

MariaDB [(none)]>

MariaDB (none)> is displayed after installing MariaDB, which may seem a bit unaccustomed. Here is the second method.

2、 Method 2: Download and install mysql-server from the official website

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server

After the installation is successful, restart the mysql service.

# service mysqld restart

When mysql is installed for the first time, the root account has no password.

[ root@yl-web yl]# mysql -u root 
Welcome to the MySQL monitor.  Commands end with; or \g.
Your MySQL connection id is 3
Server version:5.6.26 MySQL Community Server(GPL)Copyright(c)2000,2015, 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> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               |+--------------------+4 rows inset(0.01 sec)

mysql>

set password

mysql>set password for'root'@'localhost'=password('password');
Query OK,0 rows affected(0.00 sec)

mysql>

No need to restart the database to take effect.

The following content during the mysql installation:

Installed:
 mysql-community-client.x86_64 0:5.6.26-2.el7                mysql-community-devel.x86_64 0:5.6.26-2.el7                
 mysql-community-libs.x86_64 0:5.6.26-2.el7                  mysql-community-server.x86_64 0:5.6.26-2.el7               

Dependency Installed:
 mysql-community-common.x86_64 0:5.6.26-2.el7                                                                            

Replaced:
 mariadb.x86_64 1:5.5.41-2.el7_0          mariadb-devel.x86_64 1:5.5.41-2.el7_0   mariadb-libs.x86_64 1:5.5.41-2.el7_0  
 mariadb-server.x86_64 1:5.5.41-2.el7_0  

So after installation, mariadb is automatically replaced and will no longer take effect.

[ root@yl-web yl]# rpm -qa |grep mariadb
[ root@yl-web yl]# 

Three, configure mysql

1、 Encoding

The mysql configuration file is /etc/my.cnf

Finally add the encoding configuration

[ mysql]default-character-set=utf8

The character encoding here must be the same as in /usr/share/mysql/charsets/Index.xml.

2、 Remote connection settings

Assign all permissions of all tables in all databases to the root user at all IP addresses.

mysql> grant all privileges on *.* to root@'%'identified by 'password';

If it is a new user instead of root, you must first create a new user

mysql>create user 'username'@'%' identified by 'password';

At this point, you can connect remotely.

Maven hot deployment

Maven hot deployment can be deployed to the local server with one line of command. If there is no problem, just one line of command can be deployed to the official server. It facilitates development and deployment. Because my Tomcat9 encountered many problems.

You can refer to [maven automatic deployment to remote tomcat tutorial] (http://www.cnblogs.com/xyb930826/p/5725340.html) for deployment and testing.

The following is an error I encountered, because there is no make configuration IDEA caused an error.

[ ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy(default-cli) on project liwenhao: Cannot invoke Tomcat manager: Connect
ion reset by peer: socket write error ->[Help 1][ERROR][ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.[ERROR] Re-run Maven using the -X switch to enable full debug logging.[ERROR][ERROR] For more information about the errors and possible solutions, please read the following articles:[ERROR][Help 1]

You can configure make as follows

Can succeed

**The war package is deployed on the server garbled **

You can solve the garbled code of the Chinese war package server by configuring the following properties.

< properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding></properties>

After configuring the figure.

When I used the mvn tomcat7:deploy command to hot deploy, mysql could not be connected. Later, when I redeployed, this problem did not occur.

guess

It should be a problem with my configuration file

Reference documents

  1. Centos 7 open port 80
  2. centos7 set Chinese
  3. Completely uninstall MySQL database under CentOS 7
  4. CentOS7 Remote access to MySQL
  1. How To Install Apache Tomcat 8 on CentOS 7

Recommended Posts

CentOS install nginx+tomcat+java+mysql operating environment
Centos6.9 install npm environment
CentOS 7 install JAVA environment (JDK 1.8)
1.5 Install Centos7
CentOS7 compile and install L(A|N)MP environment
Install Centos7 operating system in Docker
Centos6 install Python2.7.13
Centos7.3 install nginx
CentOS7.2 install Mysql5.7.13
CentOS install Redmine
Graphic KVM to install CentOS7.6 operating system
Centos7 install Python 3.6.
CentOS7 install MySQL
Centos7 install protobuf
CentOS 7 install Docker
CentOS7 install GlusterFS
CentOS 7.4 install Zabbix 3.4
CentOS7 install Docker
Centos6.5 install Tomcat
CentOS install Python 3.6
centos7 install docker-ce 18.01.0
CentOS 7.2 install MariaDB
CentOS 7 install Hadoop 3.0.0
Centos7 install Python2.7
Centos 7.6 install seleniu
CentOS 7.3 install Zabbix3
Centos7 install LAMP+PHPmyadmin
CentOS install mysql
CentOS install openjdk 1.8
CENTOS6.5 install CDH5.12.1 (1)
CentOS install PHP
CentOS6 install mist.io
Centos7 install Docker
CentOS7 install mysql
centOs install rabbitMQ
CentOS 7 install MySQL 5.6
[PHP] Build a PHP operating environment under CentOS
Centos7 install Nginx
CentOS6.5 install CDH5.13
Centos7 install docker18
Centos install Python3
centos7 install docker
CentOS install jdk
centos7 install nginx-rtmp
CentOS8 install MySQL8.0
Centos6.3 install KVM
CentOS install PostgreSQL 9.1
CentOS7 install mysql8
CentOS 7 install Java 1.8
CentOS8 install fastdfs6.06
CentOS 7 install Gitlab
Centos 7 install PostgreSQL
CentOS7 install MySQL8
CentOS 7 install Java 1.8
CentOS 6 install Docker
centos 6.5 install zabbix 4.4
Centos8 install Docker
CentOS6.8 install python2.7
CentOS install nodejs 8
CentOS6.5 install GNS3
centos 7.5 install mysql5.7.17