Preface: All projects will be deployed online after the completion of development, generally with Linux system as the Server, Windows Server is rarely used (most of the development of projects are completed in the Windows desktop system), generally there are special personnel responsible for the online. As a developer, you can also play with Linux, which is the favorite of many IT people. Let’s deploy a Java Web project using a clean Linux system.
- Install a VMware Workstation
- Install CentOS on the VM (using CentOS6.7 64-bit)
- Install the Java development environment JDK 1.8
- Tomcat8.5 Other servers are also available
- Install MySQL5.7 (Oracle, MS Server also available)
First, build the Linux environment
1. Download and install a VMware workstation, which is the platform of the virtual machine. The virtual machine needs to build a Linux system in it later.
2. Download a centos installation package. There are many Linux versions, such as redhat, ubuntu, deepin, and BT3.
3. Create a new virtual machine, and the import in the installation package, remember steps during a step to build a user and password, the user is a common account of the Linux environment here, but the root password is root account and the ordinary users share the password (this section of the tutorial on my blog section also have detailed steps)
4. After the installation is complete, it is a graphical interface, generally we need to use the command line interface, so here you can use the shortcut keys CTRL+ALT+F2, you can switch to the command interface. There are several ways to enter the command line interface. Here gqzdev recommends ==Xshell5== to be easier to use. Need can leave a message!
XShell5 Xftp5 tool (other tools are available!)
5. Run the ifconfig command to check the IP address of the VM, and then use Xshell to connect to the VM. In this way, the operation command is more convenient and you do not need to switch out or switch out frequently.
The above installation and configuration problems can be baidu, a lot of online resources. It is mainly to build a good Linux system environment…..
Second, JDK installation
-
Gz == jdK-8u221-linux-x64.gz == (JDK1.8 is used a lot now!) Can go to download the JDK’s official website www.oracle.com/technetwork…
-
Upload to your Linux environment using XFTP. The upload path is /usr/java
Unzip the package and get a jdk1.8.0_221 folder. Run the tar -xzvf command to decompress it and upload it to the Linux environment using Xftp. There are two ways to do it: first, transfer right in the red box of the function bar and second, drag the folder, drag it. Very importantly, the path in Linux is /usr/java…..
With the JDK uploaded, it’s time to configure the JDK environment
-
First, open Xshell through XFTP (open method described in the previous section) 1) switch to “/ “directory CD.. /.. 3) Grant the JDK file the highest permission chmod 777-r jdk1.8.0_221
-
Configure JDK environment variables: 1) Switch to “/ “directory CD.. /.. 3) Edit the profile file vim Profile 4) Press insert on the keyboard to enter editing mode 5) Configure JDK environment variables, and enter the following content in the profile (fill in the blank space and add it at the end) : Export JAVA_HOME=/usr/ Java /jdk1.8.0_221 export JAVA_HOME=/usr/ Java /jdk1.8.0_221 6) Hold down the ESC key and type :wq to save the environment variable you just set. Enter the command Java -version, see the following corresponding installation JDK version screenshots, it shows that you have configured successfully!
Configure export….. at the end of the profile under etc
Export JAVA_HOME=/usr/java/jdk1.8.0_221 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/binCopy the code
Three, server installation
Download Tomcat8.5 tomcat.apache.org/download-80…
Here is the configuration of Tomcat
-
First download a version of Tomcat, I use apache-tomcat-6.0.37 version apache-tomcat-6.0.37.tar.gz is the corresponding zip package.
-
You can use XFTP to upload apache-tomcat-6.0.37 directly to /usr/local, and then configure the environment variables to start Tomcat
-
Configure tomcat environment variables: 1) Go to the “/ “directory CD.. /.. 3) Edit the profile file vi profile 4) Press I on the keyboard to enter the edit mode. 5) Configure tomcat environment variables. Enter the following information in profile (add the following line after configuring JDK environment variables) : Export CATALINA_HOME=/usr/local/apache-tomcat-6.0.37 export CATALINA_HOME=/usr/local/apache-tomcat-6.0.37 7) After editing, press ESC and enter :wq to save the Tomcat environment variables you just set. 8) Make the environment variables you just set effective source profile
Note: The above JDK configuration and tomcat path configuration may have some problems, you are advised to enable the following configuration mode
Run the CD ~ 2 command to open and edit the environment variable file. Run the vi. Bashrc command. 3) Go to the environment variable editing environment and add the following environment variables:
Export JAVA_HOME=/usr/local/jdk1.6.0_45 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib export PATH = $JAVA_HOME/bin: $JAVA_HOME/jre/bin: $PATH: $HOMR/bin export the CATALINA_HOME = / usr/local/apache tomcat -- 6.0.37Copy the code
4) Press ESC and enter: wq to save the changes. 5) To make the configuration take effect, run the source ~/. Bashrc command
4. You can start Tomcat to check whether the configuration is successful:
1) Switch to the “/ “directory CD.. /.. 2) Switch to the bin directory of the startup command: CD /usr/local/apache-tomcat-6.0.37/bin 3) Run the tomcat startup command./startup.sh. If the following information is displayed, you need to grant permission to the bin command: 4) Return to bin’s parent directory CD.. 5) Grant the highest permission to the bin file chmod 777 -r bin 6) Switch to the bin directory CD bin 7) Run the tomcat startup command./startup.sh again. If the following screenshot is displayed, the tomcat is successfully started. 8) Generally, the default port is 8080, so directly enter your IP address and port number in the browser of your PC to access the tomcat home page. http:// [IP address of your Linux server] :8080 PS: The IP address is the IP address of your Linux server. How to obtain it? –> Enter ifconfig in Linux to get it! Sh run tomcat log file:./catalina.sh run Tomcat log file: If you cannot access the firewall, you can try to turn off the firewall and run the service iptables stop command in Linux. 11) Enter the IP address and port number in the browser. If you see the tomcat home page, it indicates that tomcat is successful, as shown below:
Iv. Database
Install the open source MySQL database
- Select Yum install
- Use the tar.gz package to install the software
4.1 yum install
Mysql > install mysql
rpm -qa | grep mysql
Copy the code
Uninstall mysql:
RPM -e --nodeps RPM -e --nodeps RPM -e --nodepsCopy the code
Three lines of command:
yum install mysql
yum install mysql-server
yum install mysql-devel
Copy the code
Or one line:
yum install -y mysql mysql-server mysql-devel
Copy the code
4.2 Use the tar.gz package to install the software
Operating system: Centos6.4 64-bit tool: Xftp5, Xshell5 installation software: mysql5.7 note: use an official compiled binary file for installation
- Move the installation file to the specified directory
- Check whether Mysql is installed
rpm -qa | grep mysql
Copy the code
- Unpack the
The tar - XVZF mysql - 5.7.22 - Linux - glibc2.12 - x86_64. Tar. GzCopy the code
[root@VM_0_17_centos mysql]# mv mysql-5.7.27-linux-glibc2.12-x86_64 mysql57 [root@VM_0_17_centos mysql]# mv mysql-5.7.27-linux-glibc2.12-x86_64 mysql57Copy the code
Decompress the mysql package to /usr/mysql.rm and rename it to mysql57. The database file directory is == /usr/mysql.mysql57 ==
- Set the mysql directory access permission and user group
[root@VM_0_17_centos mysql57]# chown -r mysql/ usr/ mysql57 # chown -r mysql/ usr/ mysql57 [root@VM_0_17_centos mysql57]# CHGRP -r mysql/ usr/mysql/mysql57 mysql57]# cd /usr/mysql/mysql57 [root@VM_0_17_centos mysql57]# ll total 56 drwxr-xr-x 2 mysql mysql 4096 Aug 11 21:24 bin -rw-r--r-- 1 mysql mysql 17987 Dec 28 2017 COPYING drwxr-xr-x 2 mysql mysql 4096 Aug 11 21:40 data drwxr-xr-x 2 mysql mysql 4096 Aug 11 21:24 docs drwxr-xr-x 3 mysql mysql 4096 Aug 11 21:23 include drwxr-xr-x 5 mysql mysql 4096 Aug 11 21:24 lib drwxr-xr-x 4 mysql mysql 4096 Aug 11 21:23 man -rw-r--r-- 1 mysql mysql 2478 Dec 28 2017 README drwxr-xr-x 28 mysql mysql 4096 Aug 11 21:24 share drwxr-xr-x 2 mysql mysql 4096 Aug 11 21:24 support-filesCopy the code
Permissions are modified.
- Configure mysql==(key part)
Create the following files and set access permissions for mysql configuration
Sock == create file/TMP /mysql.sock== And set permissions
Create a file
[root@VM_0_17_centos mysql57]# mkdir tmp
[root@VM_0_17_centos mysql57]# cd tmp
[root@VM_0_17_centos tmp]# ll
total 0
[root@VM_0_17_centos tmp]# touch mysql.sock
[root@VM_0_17_centos tmp]# ll
total 0
-rw-r--r-- 1 root root 0 Aug 11 21:59 mysql.sock
Copy the code
Set the permissions
[root@VM_0_17_centos tmp]# chown -R mysql:mysql /usr/mysql/mysql57/tmp/mysql.sock
[root@VM_0_17_centos tmp]# chmod 755 /usr/mysql/mysql57/tmp/mysql.sock
Copy the code
Create /log/mysqld.log== And set permissions
[root@VM_0_17_centos mysql57]# mkdir log
[root@VM_0_17_centos mysql57]# cd log
[root@VM_0_17_centos log]# ll
total 0
[root@VM_0_17_centos log]# touch mysqld.log
[root@VM_0_17_centos log]# chown -R mysql:mysql /usr/mysql/mysql57/log/mysqld.log
[root@VM_0_17_centos log]# chmod 755 /usr/mysql/mysql57/log/mysqld.log
Copy the code
If an error occurs, the path is not written completely. Write an absolute path
Create/TMP /mysqld.pid==. And set permissions
[root@VM_0_17_centos log]# cd .. /tmp [root@VM_0_17_centos tmp]# touch mysqld.pid [root@VM_0_17_centos tmp]# chown -R mysql:mysql /usr/local/mysql57/tmp/mysqld.pid [root@VM_0_17_centos tmp]# chmod 755 /usr/local/mysql57/tmp/mysqld.pidCopy the code
- == Initialize mysql==
[root@VM_0_17_centos mysql57]# bin/mysqld --initialize --user=mysql --basedir=/usr/mysql/mysql57/ --datadir=/usr/local/mysql57/data/
Copy the code
Errors may be reported. Error message
bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
Copy the code
Solution: Cause: Yum installs libnuma. So.1, but installs 32 by default, while DB2 requires 64 bit
- 1. If libnuma.so.1 is installed, yum remove libnuma.so.1
[root@VM_0_17_centos mysql57]# yum remove libnuma.so.1
Copy the code
- Yum -y install numactl.x86_64
[root@VM_0_17_centos mysql57]# yum -y install numactl.x86_64
Copy the code
- 3. After the installation is complete, try again
[root@VM_0_17_centos mysql57]# bin/mysqld --initialize --user=mysql --basedir=/usr/mysql/mysql57/ --datadir=/usr/local/mysql57/data/
Copy the code
== Installation succeeds == Temporary password
Configure SSL parameters (in mysql directory)
[root@VM_0_17_centos mysql57]# bin/mysql_ssl_rsa_setup --datadir=/usr/mysql/mysql57/data/
Copy the code
Mysql-5.7.23 my.cnf is not in /support-files, so we == create my.cnf== file.
[root@VM_0_17_centos mysql57]# touch /etc/my.cnf
[root@VM_0_17_centos mysql57]# vim /etc/my.cnf
Copy the code
Copy the following contents (each installation path may be different, == needs to be modified ==) :
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql57
datadir=/usr/local/mysql57/data
port = 3306
socket=/tmp/mysql.sock
log-error=/usr/local/mysql57/log/mysqld.log
pid-file= / usr/local/mysql57 / TMP/mysqld. Pid # table name is case-insensitive lower_case_table_names =1
max_connections=5000
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Copy the code
Configuration is complete
- Start the mysql
- Methods a
[root@VM_0_17_centos mysql57]# bin/mysqld_safe --user=mysql &
Copy the code
Check the running status of mysql
[root@VM_0_17_centos mysql57]# ps -ef |grep mysql
Copy the code
First, I didn’t succeed, because I had a problem. I successfully configured in mode two.
- Mode 2 Configuring the mysql automatic startup (Based on site requirements)
[root@VM_0_17_centos mysql57]# cp support-files/mysql.server /etc/init.d/mysql
[root@VM_0_17_centos mysql57]# vim /etc/init.d/mysql
Copy the code
Add configuration (I enter edit; Esc –> :wq
If the mysql automatic startup mode is configured, you can start mysql in service mode
Mysql/mysql. d/ mysql. d/ mysql. d/ mysql. d/ mysql. Mysql / /etc/init.d/mysql restart/service mysql restart See the mysql service start ps - ef success | grep mysql start mysqlCopy the code
[root@VM_0_17_centos tmp]# service mysql start
Copy the code
Starting MySQL. ERROR! The server quit without updating The PID file (/ usr/local/mysql57 / TMP/mysqld. PID). = = error, The above said no/usr/local/mysql57 / TMP/mysqld. Pid. = =
Solution:
A) create a file/usr/local/mysql57 / TMP/mysqld. Pid
B) Modify permissions
Change the permission of the directory where the mysqld.pid file is stored
chown -R mysql /usr/local/mysql57/tmp
chgrp -R mysql /usr/local/mysql57/tmp
chmod 777 /usr/local/mysql57/tmp
Copy the code
The restart succeeded (if not, one of the intermediate steps was incorrectly written). Or set the mysql directory to 777.)
[root@VM_0_17_centos tmp]# /etc/init.d/mysql start
Starting MySQL. SUCCESS!
Copy the code
- Configure mysql to environment variables
[root@VM_0_17_centos tmp]# vim /etc/profile
Copy the code
export MYSQL57_HOME=/usr/mysql/mysql57/bin
export PATH=$PATH:${MYSQ57_HOME}
Copy the code
This place is the colon (:)
Setting environment variables takes effect immediately
[root@VM_0_17_centos tmp]# source /etc/profile
Copy the code
- Mysql > alter database forget password
Switch to the bin directory in mysql
[root@localhost bin]# ./mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Copy the code
The password is incorrect. And I forgot the password of the previous installation
Solution:
- Step 1: Skip the MySQL password authentication
(Note: under Windows, modify my.ini)
[root@VM_0_17_centos bin]# vim /etc/my.cnf
Copy the code
Add “==skip-grant-tables==” to any line after [mysqld] to skip password validation, as shown below:
Save and exit (esc–> :wq)
- Step 2: Restart mysql
[root@VM_0_17_centos bin]# /etc/init.d/mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
Copy the code
- Step 3: Log in to mysql
Go to the mysql/bin directory and start mysql
[root@VM_0_17_centos bin]# ./mysql
Copy the code
Start-up success
- Step 4: Change the password using SQL statements
mysql> use mysql; Mysql > update user set authentication_string=password(" password ") where user="root"; mysql> flush privileges; mysql> quitCopy the code
- Step 5: Re-edit my.cnf
Delete skip-grant-tables from [mysqld]
[root@VM_0_17_centos bin]# vim /etc/my.cnf
Copy the code
Restart the mysql
[root@VM_0_17_centos bin]# mysqld [root@VM_0_17_centos bin]# /etc/init.d/mysqld restartCopy the code
- Example Set the mysql remote login
Log in to the mysql server locally
[root@localhost bin]# ./mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.21 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.Copy the code
- 1. An error
Suddenly an error
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
Copy the code
mysql> use mysql
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
Copy the code
== Solution: You need to change the password ==
Mysql > alter user 'root'@'localhost' identified by '; mysql> flush privileges; mysql> quit;Copy the code
- 2. Continue the configuration
mysql> use mysql; Mysql > update user set host='%' where user='root'; Mysql > GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypwd' WITH GRANT OPTION; mysql> FLUSH PRIVILEGES; mysql> quit;Copy the code
- 3. Restart mysql
[root@VM_0_17_centos bin]# service mysql restart; [root@VM_0_17_centos bin]# /etc/init.d/mysqld restartCopy the code
- 4. Configure the firewall
A) Configure the firewall to enable port 3306
[root@VM_0_17_centos bin]# /sbin/iptables -I INPUT -p tcp --dport 3306-j ACCEPT
[root@VM_0_17_centos bin]# /etc/rc.d/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables: [ OK ]
[root@VM_0_17_centos bin]# /etc/rc.d/init.d/iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
Copy the code
B) Temporarily disable the firewall
[root@VM_0_17_centos bin]# service iptables stop
Copy the code
C) Disable the firewall permanently
The restart takes effect permanently
[root@VM_0_17_centos bin]# chkconfig iptables off
Copy the code
Use the Navicat tool to connect
5. Deploy the project
The following is to package the project to deploy to the server above, I will continue to write down the content below if I have time!!
- Deploy by packaging as a WAR file