安装Maven、MySQL、Tomcat

打印 上一主题 下一主题

主题 1771|帖子 1771|积分 5315

1、下载并安装 Maven

(mvn下令对应的软件包)(确认 Java 环境已安装,在上面安装Hadoop环境的时候已经安装好Java环境)Hadoop安装、配置与管理_centos环境下hadoop的安装与配置-CSDN博客
可以在内里找到java安装
   [root@hadoop ~]# java -version   //查看java的版本
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
  
  //从 Apache Maven 的官方网站下载最新版本的 Maven。通常会下载一个二进制压缩包。使用wget下令来下载//
  
[root@hadoop ~]# wget https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz   
--2025-03-21 00:15:06--  https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz
正在剖析主机 dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
正在连接 dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... 已连接。
已发出 HTTP 哀求,正在等待回应... 200 OK
长度:9102945 (8.7M) [application/x-gzip]
正在保存至: “apache-maven-3.9.9-bin.tar.gz”
  apache-maven-3.9.9-bin.tar.gz           100%[=============================================================================>]   8.68M  1.38MB/s  用时 3m 26s
  2025-03-21 00:18:32 (43.2 KB/s) - 已保存 “apache-maven-3.9.9-bin.tar.gz” [9102945/9102945])
  
   //下载完成后,使用tar下令解压压缩包:    
  [root@hadoop ~]# tar -zxvf apache-maven-3.9.9-bin.tar.gz 
apache-maven-3.9.9/README.txt
apache-maven-3.9.9/LICENSE
apache-maven-3.9.9/NOTICE
apache-maven-3.9.9/lib/
apache-maven-3.9.9/lib/aopalliance.license
.
  .
  .
  //将解压的文件移动到/opt目录,便于背面管理
  [root@hadoop ~]# sudo mv maven-3.9.9 /opt/
[root@hadoop ~]# cd /opt
[root@hadoop opt]# ll
总用量 0
drwxr-xr-x. 6 root root 99 3月  21 00:30 maven-3.9.9
 
  
   //编辑文件,添加以下内容  
  vim /etc/profile
  
  添加:
  export MAVEN_HOME=/opt/apache-maven-3.9.9
export PATH=$PATHMAVEN_HOME/bin
  
  使配置收效
  source /etc/profile
  
  验证安装是否成功,若成功安装,会显示 Maven 的版本信息。
    mvn -version 
  

2、安装MySQL

   安装MySQL: yum install mysql-server -y
  查看MySQL状态: sudo systemctl status mysqld
  启动MySQL
  sudo systemctl start mysqld
  sudo systemctl enable mysqld
  
  确保MySQL用户拥有数据目录权限:
  sudo chown -R mysql:mysql /var/lib/mysql
  sudo chmod -R 755 /var/lib/mysql
  
  初始化安全配置(设置 root 密码) sudo mysql_secure_installation
  登录 MySQL sudo mysql -u root -p
  
  1. [root@hadoop ~]# sudo mysql_secure_installation
  2. Securing the MySQL server deployment.
  3. Connecting to MySQL using a blank password.
  4. The 'validate_password' component is installed on the server.
  5. The subsequent steps will run with the existing configuration
  6. of the component.
  7. Please set the password for root here.
  8. New password:    //输入密码,尽量有大写字母,小写字母,数字,符号
  9. Re-enter new password:  //再次输入
  10. Estimated strength of the password: 100
  11. Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
  12. By default, a MySQL installation has an anonymous user,
  13. allowing anyone to log into MySQL without having to have
  14. a user account created for them. This is intended only for
  15. testing, and to make the installation go a bit smoother.
  16. You should remove them before moving into a production
  17. environment.
  18. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
  19. Success.    //是否删除匿名用户,建议y
  20. Normally, root should only be allowed to connect from
  21. 'localhost'. This ensures that someone cannot guess at
  22. the root password from the network.
  23. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
  24. Success.    //是否禁止root远程登陆,跟随自己的情况,我是y
  25. By default, MySQL comes with a database named 'test' that
  26. anyone can access. This is also intended only for testing,
  27. and should be removed before moving into a production
  28. environment.
  29. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
  30. - Dropping test database...   //是否删除test数据库,y
  31. Success.
  32. - Removing privileges on test database...
  33. Success.
  34. Reloading the privilege tables will ensure that all changes
  35. made so far will take effect immediately.
  36. Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
  37. ... skipping.  //是否重新加载权限表,y
  38. All done!
复制代码

  1. [root@hadoop ~]# sudo mysql -u root -p   //进入MySQL
  2. Enter password:
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.
  4. Your MySQL connection id is 12
  5. Server version: 8.0.26 Source distribution
  6. Copyright (c) 2000, 2021, Oracle and/or its affiliates.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. # 创建数据库和用户表
  12. mysql> CREATE DATABASE cloud_disk;  
  13. Query OK, 1 row affected (0.01 sec)
  14. mysql> USE cloud_disk;
  15. Database changed
  16. mysql> CREATE TABLE users (
  17.     ->   id INT PRIMARY KEY AUTO_INCREMENT,
  18.     ->   username VARCHAR(50) UNIQUE NOT NULL,
  19.     ->   password VARCHAR(100) NOT NULL,
  20.     ->   role ENUM('user', 'admin') DEFAULT 'user',
  21.     ->   status ENUM('active', 'blocked') DEFAULT 'active'
  22.     -> );
  23. Query OK, 0 rows affected (0.02 sec)
  24. # 创建文件元数据表
  25. mysql> CREATE TABLE files (
  26.     ->   id INT PRIMARY KEY AUTO_INCREMENT,
  27.     ->   user_id INT NOT NULL,
  28.     ->   hdfs_path VARCHAR(255) NOT NULL,
  29.     ->   filename VARCHAR(255) NOT NULL,
  30.     ->   upload_time DATETIME DEFAULT CURRENT_TIMESTAMP,
  31.     ->   FOREIGN KEY (user_id) REFERENCES users(id)
  32.     -> );
  33. Query OK, 0 rows affected (0.01 sec)
复制代码
 3、安装Tomcat9

#Tomcat 依赖 Java,需先安装 JDK:
   yum install java-11-openjdk-devel -y
  #创建Tomcat专用用户:
   sudo useradd -r -s /bin/nologin tomcat
  #下载Tomcat压缩包
   wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.102/bin/apache-tomcat-9.0.102.tar.gz
  # 3. 验证校验和
   sha512sum apache-tomcat-9.0.102.tar.gz
  
  # 4. 解压到:
    sudo tar -xzf apache-tomcat-9.0.102.tar.gz -C /opt/
  # 5. 查抄效果:
   ls /opt/apache-tomcat-9.0.102
  # 确保用户所有权
   sudo chown -R tomcat:tomcat /opt/tomcat9
  # 设置目录权限
   sudo chmod -R 755 /opt/tomcat9 
   #创建systemd配置文件
   vim /etc/systemd/system/tomcat9.service
  
  #在内里添加配置
   [Unit]
Description=Apache Tomcat 9
After=syslog.target network.target
  [Service]
Type=forking
User=tomcat
Group=tomcat
  # 环境变量配置
Environment=CATALINA_PID=/opt/tomcat9/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat9
Environment=CATALINA_BASE=/opt/tomcat9
Environment=JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-4.el8_5.x86_64   # 根据实际路径调整
  # 启动/停止下令
ExecStart=/opt/tomcat9/bin/startup.sh
ExecStop=/opt/tomcat9/bin/shutdown.sh
  # 失败时主动重启
Restart=on-failure
  [Install]
WantedBy=multi-user.target
 
   #查看JAVA_HOME路径,根据自己的位置所在地,背面的/bin/java不需要
   readlink -f $(which java)
  

 #重载systemd系统
   sudo systemctl daemon-reload # 加载新服务配置
  sudo systemctl start tomcat9 # 启动服务
  sudo systemctl enable tomcat9 # 设置开机自启
  #查抄启动状态
   systemctl status tomcat9
   




免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

祗疼妳一个

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表