Home  >  Article  >  Java  >  How to set up a Java Web project running environment on a Linux system?

How to set up a Java Web project running environment on a Linux system?

王林
王林forward
2023-04-26 08:07:061347browse

1. Install jdk

1. Uninstall the old version or the jdk that comes with the system

(1) List all installed jdk

 rpm -qa | grep jdk

(2) Uninstall unnecessary jdk

 yum -y remove installation package name

2. Download and decompress jdk

(1) Download the installation package

Enter the /usr/local directory and create a new java directory

mkdir java

​, use the wget command in the java directory to download the installation package, such as

wget --no-cookies --no-check-certificate --header "cookie: gpw_e24=http%3a%2f%2fwww.oracle.com%2f; oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.tar.gz

​, or use the shell tool to upload it locally to Linux.

(2) Decompress the installation package

After downloading, use the command to decompress,

tar -zxvf compressed package name

3 .Configure environment variables

Enter the /etc/ folder and use the vim profile command editor to edit the profile file (global environment variable configuration). If there is no profile file, go to /root to configure the .bash_profile file (environment variable configuration under the current user) and add the following configuration at the end of the file: (If you are worried about modification errors, you can use the ps command to back up the file)

export java_home=jdk安装包的根目录
  export path=$java_home/bin:$path
  export classpath=.:$java_home/lib/dt.jar:$java_home/lib/tools.jar:$java_home/jre/lib/rt.jar  

Finally, don’t forget to execute the command

 source /etc/profile

to make the configuration file take effect.

Enter java -version to check whether the jdk configuration is successful. If the version information appears, the jdk installation and configuration is completed.

2. Install tomcat

2. Download and decompress tomcat

(1) Download the installation package

Enter /usr Create a new mywork directory in the /local directory

  mkdir mywork

 , and use the wget command in the mywork directory to download the installation package, such as

 wget "" 

Or use shell tools to download locally and upload to linux.

(2) Decompress the installation package

After downloading, use the command to decompress,

 tar -zxvf compressed package name

3 .Start tomcat

Enter the main directory of tomcat, start tomcat, use the command

 bin/startup.sh

Check whether tomcat is started Success (whether the process exists), use the command

 ps -ef | grep tomcat

4. Check whether tomcat is installed successfully

(1) Check Firewall status

 systemctl status firewalld

Use the command if the above command is invalid

 service iptables status

(2) Turn off the linux firewall

 systemctl stop firewalld

Use the command if the above command is invalid

 service iptables stop

(3) Check the ip address information of linux

  ifconfig

(4) Visit tomcat

Enter the address in the browser, address: 8080

3. Install mysql

1. Uninstall the system’s own database mariadb

yum list installed | grep mariadb (查看系统是否安装了mariadb)

  yum -y remove 应用名称  (卸载mariadb)

2. Download and unzip mysql

(1) Download the installation package

Enter the /usr/local directory and use the wget command to download the installation package, such as

wget "http://dev.mysql.com/get/ downloads/mysql-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz"

Or use the shell tool to upload it to Linux locally.

(2) Decompress the installation package

After downloading, use the command to decompress,

tar -zxvf compressed package name

Decompress After completion, change the file name,

 mv decompress the file name mysql

3. Create the data warehouse directory

 mkdir /mysql/data ( This directory stores database data)

4. Create mysql user and user group

  groupadd mysql (创建用户组)
  useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql  (将mysql用户添加至组中并为用户指定mysql目录)

5. Specify the owner of the directory

进入到mysql根目录
  cd /usr/local/mysql
  改变目录所有者,
  chown -r mysql .  (不要忘记后面的.)
  chgrp -r mysql .
  chown -r mysql /mysql/data

6. Initialize mysql configuration parameters

在mysql根目录下执行,
  bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data
  注意:命令执行后在末尾处会生成初始密码,将其复制到记事本中用于后面首次登录。
  设置数据加密,
  bin/mysql_ssl_rsa_setup --datadir=/mysql/data

7. Modify the system configuration file

将mysql配置文件添加到系统配置文件中,进入目录
  cd /usr/local/mysql/support-files
  复制,
  cp my-default.cnf /etc/my.cnf
  cp mysql.server /etc/init.d/mysql
  编辑mysql配置文件,指定基础目录和数据目录,
  vim /etc/init.d/mysql
  修改如下属性:
  basedir=/usr/local/mysql
  datadir=/mysql/data

8. Modify the password

启动mysql,
  /etc/init.d/mysql start  --5.0版本是 mysqld start
  登录,
  mysql -h localhost -u root -p
  输入第(6)步拿到的密码。如果出现:-bash :mysql :commond not found 就执行:ln -s /usr/local/mysql/bin/mysql /usr/bin  --创建命令软连接
  修改密码,
  set password=password('你要设置的密码')

9. Modify the operation of the remote host for the root user Permissions

Give all hosts all permissions

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

Make permissions effective

flush privileges; 

View user table permissions

 use mysql;
  select * from user;

10. Add system environment variables

vim /etc/profile 

Add at the end:


export path=/usr/local/mysql/bin:$path 

Make the configuration file effective

source /etc/profile<br>

11. Remote connection test

You can use the mysql client tool to connect remotely. If the connection fails, you can close the firewall and try again.

Supplement:

Check the running status of mysql,
service mysql status --5.0 version is service mysqld status
Stop mysql,
service mysql stop --5.0 version is service mysqld stop
Start mysql
service mysql start --The 5.0 version is service mysqld start
Restart mysql
service mysql restart --The 5.0 version is service mysqld restart

mysql can be passed Modify /etc/my.cnf for detailed configuration.

The above is the detailed content of How to set up a Java Web project running environment on a Linux system?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete