Utunbu系统中安装jdk,tomcat,mysql,并在tomcat运行项目


本文记录一个干净的utunbu系统到完成一个项目运行的过程

 要想项目能运行起来就必须要知道这个项目需要哪些运行环境。话不多说,直接进入正题。。。    

1. 搭建一个jdk1.8(本人对jdk1.8情有独钟,虽然现在java se 16都已经更新了,但没去研究,下次有时间去研究一下。ps:1.8和1.7还是有点区别的,之前有做过一个项目1.7jdk的项目升级到1.8是有问题的)

jdk1.8 下载地址:https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

安装jdk1.8

为了方便日后项目管理,在系统创建了mkdir /data,mkdir /data/project, mkdir /data/soft 文件夹

在soft 目录中 放入刚刚下载的jdk

 解压jdk :tar -zxvf jdk1.8.0_141.tar.gz  

 在将解压过的文件夹转移到 /usr/local 下面 便于安装查看管理: mv jdk1.8.0_141 /usr/local/jdk1.8

添加环境变量:vim /etc/profile  编辑模式把代码加入

export JAVA_HOME=/usr/local/jdk1.8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=.:${JAVA_HOME}/bin:$PATH

记得退出保存

最后看下java版本有没有,如果有jdk配置完毕: java -version

 2. jdk 配置完毕了,接下来我们安装一下tomcat 

 tomcat 下载地址:https://tomcat.apache.org/download-10.cgi

解压tomcat :tar -zxvf apache-tomcat-10.0.5.tar.gz

 再将解压的tomcat 重命名 移动到项目文件夹中去(此步骤可不必要): mv apache-tomcat-10.0.5 /data/project/tomcat10-library
如果你用的是系统子账号可能存在权限问题:sudo chmod 755 -R  xx

到这里tomcat 也安装结束了

3.接下来安装mysql:

sudo apt-get install mysql-server

等待安装结束。mysql密码设置不再描述。

本人在安装过程中出现一些问题记录一下。

check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY '123456' WITH GRANT OPTION' at line 1

应该是用户用户的创建和赋值权限不能同事执行导致的。

mysql> UPDATE mysql.user SET authentication_string=password('000000') WHERE User='root' AND Host ='localhost';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('000000') WHERE User='root' AND Host ='localhost'' at line 1
mysql> USE mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> GRANT ALL PRIVILEGES ON *.* TO zx@localhost IDENTIFIED BY "123456";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY "123456"' at line 1
mysql> use mysql
Database changed
mysql> LTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LTER USER 'root'@'localhost' IDENTIFIED BY '123456'' at line 1
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.03 sec)

mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.18 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | debian-sys-maint |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
5 rows in set (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.14 sec)

mysql>

修改mysql密码: ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

4. web项目放到tomcat下面:/data/project/apache-tomcat10-library/webapps/ROOT/   

如果是java项目 建议打成war包,放到webapps 目录下,tomcat启动会自动解压

启动tomcat:cd /data/project/apache-tomcat10-library/bin

 ./startup.sh

tomcat 默认端口是8080

页面访问:  ip:8080/项目名/    如:http://127.0.0.1:8080/dist/#/centerscreen

好了,到这里一个web项目就简单的部署完毕了。如有疑问欢迎留言。