Configure Centos7 server under VMware (ii)

Source: Internet
Author: User
Tags java web

In the "Configure Centos7 server under VMware (i)" article has been configured in the virtual machine, CENTOS7 and other related network environment, then began to build Linux Java Web server.

First step: Configure JDK Environment

1. Check and uninstall your own JDK:

Query command: java-version; Javac-version (the JDK does not have the Javac service installed, the Java file cannot be compiled)

Query command: RPM-QA | grep java

Uninstall command: Rpm-e--nodeps Java version (according to the query command, uninstall the corresponding Java version)

2. Download the Linux version of the JDK installation package and place the installation package on Linux; for example: USR/LOCAL/JDK; If you cannot move directly, place the installation package in Home/admin. And then switch to root: su root; then use the move command: RM Install package path target path; then unzip

3. Unzip: TAR-ZXVF Install package name

4. Configure environment variables, command: vim/etc/profile

Add configuration at the end of the article:

Export JAVA_HOME=/USR/LOCAL/JDK ... #jdk安装路径

Export classpath=.: $JAVA _home/jre/lib/rt.jar: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar

Export path= $PATH: $JAVA _home/bin and save exit: ESC, ": Wq"

5. Test: Command: Source/etc/profile (the modified content is valid at the current terminal)

Input: java-version; Javac-version should all be effective.

Step Two: Configure Tomcat

1. Download the Linux version of Tomcat (. tar.gz type) on the official website and place the installation package on Linux; for example: usr/local/tomcat; If you cannot move directly, place the installation package in Home/admin. And then switch to root: su root; then use the move command: RM Install package path target path; then unzip:

2. Unzip: TAR-ZXVF Install package name

3. Test, after the decompression is complete, enter the Tomcat installation directory and enter the bin directory to open the Tomcat service

Command:./startup.sh

Then enter: localhost:8080 in the Linux browser, is the access successful? If successful, the Tomcat installation is complete

Enter: Virtual machine IP address in host browser: 8080; Can you access it successfully? If you cannot access it, the next step

Modify FIREWALLD Firewall under 4.CENTOS7

1) in the Virtual machine Terminal Input command: Systemctl status firewalld (view firewall status)

2) Add port 8080

Add port, Command: Firewall-cmd--zone=public--add-port=8080/tcp--permanent (--permanent permanent, no failure after this parameter restart)

Reload, command: Firewall-cmd--reload

View port Status, command: Firewall-cmd--zone=public--query-port=8080/tcp

Look at the terminal return information, whether to successfully open 8080 port

----------------------------------------------------------------------------------------

Other commands:

A. Delete: firewall-cmd--zone= public--remove-port=80/tcp--permanent

B. Start: Systemctl start Firewalld

C. Stop: Systemctl Disable FIREWALLD

D. Disable: Systemctl stop Firewalld

-----------------------------------------------------------------------------------------

3) test again in the host browser to access the Tomcat service in the virtual machine

5. Configuring the Self-boot service for Tomcat

1) Create script file, command: Vim/etc/rc.d/init.d/tomcat

#!/bin/sh
#chkconfig: 2345 10 90
#description: Starts and Stops the Tomcat daemon.
##############################################
#Startup script for Tomcat on Linux
#filename tomcat.sh
#Make sure the Java and the Tomcat installation path have been added to the path
Java_home=/usr/local/jdk .... #JDK安装目录
Catalina_home=/usr/local/tomcat #tomcat安装目录
Export Java_home
Export Catalina_home
###############################################
start_tomcat= $CATALINA _home/bin/startup.sh #tomcat启动文件
stop_tomcat= $CATALINA _home/bin/shutdown.sh #tomcat关闭文件
Start () {
Echo-n "Starting Tomcat:"
${start_tomcat}
echo "Tomcat start OK."
}
Stop () {
Echo-n "shutting down Tomcat:"
${stop_tomcat}
echo "Tomcat stop OK."
}
# See how we were called

Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart
Stop
Sleep 10
Start
;;
*)
echo "Usage: $ {Start|stop|restart}"
Esac
Exit 0

2) Add permissions to the file so that the script file can execute, command: chmod 755/etc/rc.d/init.d/tomcat

3) Add to the service: Chkconfig--add/etc/rc.d/init.d/tomcat

4) Add the following configuration to the last side of the catalina.sh file in Tomcat:

Export JAVA_HOME=/USR/LOCAL/JDK ... #jdk的安装路径

Export Catalina_home=/usr/local/tomcat ... #tomcat的安装路径

Export Catalina_base=/usr/local/tomcat ... #tomcat的安装路径

Export Catalina_tmpdir=/usr/local/kencery/tomcat.../temp

Save, and exit

5) Test:

Command: Service Tomcat start

Command: Service Tomcat stop

6) Set Boot start

A. Open the Linux setup boot file and write the following configuration file to the Rc.local file at the end of the command: vim/etc/rc.d/rc.local

B. Add configuration:

  Export JAVA_HOME=/USR/LOCAL/JDK ... #jdk安装路径

Export classpath=.: $JAVA _home/jre/lib/rt.jar: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar

Export path= $PATH: $JAVA _home/bin

Export Catalina_home=/usr/local/tomcat ... #tomcat安装路径

#tomcat自启动

/usr/local/tomcat.../bin/startup.sh

C. Test: Restart Centos7, browser access Tomcat to see if it has been successful since startup.

Step Three: Configure Mysql


1. Use the command line to configure MySQL after the CENTOS7 version, when using MySQL branch:: MariaDB

2. In the terminal, enter the following command in turn:

Yum-y Install Mariadb-server mariadb mariadb-devel
Systemctl Start mariadb
Systemctl Enable MARIADB
Mysql_secure_installation (here may error, ignore, direct CTRL + C exit, continue to execute the following command)
Firewall-cmd--permanent--add-service MySQL
Systemctl Restart Firewalld.service
Iptables-l-n|grep 3306

3. Solve the problem of error

ERR: Error 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yes)

Command 1:/etc/init.d/mysqld Stop (stop the running of the MySQL service)

Command 2:mysqld_safe--user=mysql--skip-grant-tables--skip-networking & (Skip authorization table access)

Command 3:mysql-u root mysql (login MySQL)

   mysql> UPDATE userset Password=password ('newpassword') where user= ' root ' andhost= ' 127.0.0.1 ' or host= ' localhost '; (The blank user password will be changed to a non-empty password, for example: 123, for the mysql5.7 below version)

   mysql>Update mysql.userset authentication_string=password ('newpassword') where user= ' root ' and host= ' 127.0.0.1 ' or host= ' localhost ';

   mysql> FLUSH privileges;

   mysql>quit

Command 4:/etc/init.d/mysqld restart//leave and restart MySQL

Command 5:mysql-uroot-p

Enter the password for the new setting.



Configure Centos7 server under VMware (ii)

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.