1. 程式人生 > >安裝JDK、Tomcat和Mysql(CentOS 7.4)

安裝JDK、Tomcat和Mysql(CentOS 7.4)

pen state 需要 密碼 bootstrap commands set register mysq

  • 上傳軟件包
  • rz上傳jdk-8u181-linux-x64.tar.gz和apache-tomcat-8.5.32.tar.gz
    或者FileZilla Client進行sftp鏈接上傳

    技術分享圖片

    • 解壓JDK到/usr/local/目錄
    tar xzvf jdk-8u181-linux-x64.tar.gz -C /usr/local/
    • 查看JAVA是否安裝成功
    cd /usr/local/jdk1.8.0_181/bin
    [root@fudanwuxi003 bin]# ./java -version 
    java version "1.8.0_181"
    Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mix-ed mode)
    • 配置環境變量
      [root@fudanwuxi003 bin]# vim /etc/profile
      export JAVA_HOME=/usr/local/jdk1.8.0_181
      export CLASSPATH=.:JAVA_HOME/lib
      export PATH=$PATH:$JAVA_HOME/bin
      [root@fudanwuxi003 ~]# source /etc/profile
      [root@fudanwuxi003 ~]# java -version      
      openjdk version "1.8.0_131"
      OpenJDK Runtime Environment (build 1.8.0_131-b12)
      OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
    • 安裝Tomcat
      [root@fudanwuxi003 software]# tar xzvf apache-tomcat-8.5.32.tar.gz
      [root@fudanwuxi003 software]# cd apache-tomcat-8.5.32/
      [root@fudanwuxi003 apache-tomcat-8.5.32]# ll
      總用量 92
      drwxr-x---. 2 root root  4096 8月  20 14:56 bin
      drwx------. 2 root root   238 6月  21 03:53 conf
      drwxr-x---. 2 root root  4096 8月  20 14:56 lib
      -rw-r-----. 1 root root 57092 6月  21 03:53 LICENSE
      drwxr-x---. 2 root root     6 6月  21 03:50 logs
      -rw-r-----. 1 root root  1723 6月  21 03:53 NOTICE
      -rw-r-----. 1 root root  7138 6月  21 03:53 RELEASE-NOTES
      -rw-r-----. 1 root root 16246 6月  21 03:53 RUNNING.txt
      drwxr-x---. 2 root root    30 8月  20 14:56 temp
      drwxr-x---. 7 root root    81 6月  21 03:51 webapps
      drwxr-x---. 2 root root     6 6月  21 03:50 work
      [root@fudanwuxi003 apache-tomcat-8.5.32]# cd bin/
      [root@fudanwuxi003 bin]# pwd
      /root/software/apache-tomcat-8.5.32/bin
      [root@fudanwuxi003 bin]# ./startup.sh 
      Using CATALINA_BASE:   /root/software/apache-tomcat-8.5.32
      Using CATALINA_HOME:   /root/software/apache-tomcat-8.5.32
      Using CATALINA_TMPDIR: /root/software/apache-tomcat-8.5.32/temp
      Using JRE_HOME:        /usr/local/jdk1.8.0_181
      Using CLASSPATH:       /root/software/apache-tomcat-8.5.32/bin/bootstrap.jar:/root/software/apache-tomcat-8.5.32/bin/tomcat-juli.jar
      Tomcat started.
    • 放行默認端口8080,關閉selinux
      [root@fudanwuxi003 bin]# firewall-cmd --permanent --add-port=8080/tcp
      success
      [root@fudanwuxi003 bin]# firewall-cmd --reload 
      success
      [root@fudanwuxi003 bin]# getenforce
      Enforcing
      [root@fudanwuxi003 bin]# setenforce 0
      [root@fudanwuxi003 bin]# getenforce  
      Permissive

      技術分享圖片

    • 安裝Mysql
      [root@fudanwuxi003 bin]# yum repolist | grep mysql
      [root@fudanwuxi003 bin]# rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
      獲取https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
      警告:/var/tmp/rpm-tmp.m7U7PD: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY
      準備中...                          ################################# [100%]
      正在升級/安裝...
      1:mysql80-community-release-el7-1  ################################# [100%]
    [root@fudanwuxi003 bin]# yum repolist | grep mysql
    mysql-connectors-community/x86_64        MySQL Connectors Community           63
    mysql-tools-community/x86_64             MySQL Tools Community                69
    mysql80-community/x86_64                 MySQL 8.0 Community Server           33
    • 獲得兩個mysql的yum repo源
    [root@fudanwuxi003 yum.repos.d]# pwd
    /etc/yum.repos.d
    [root@fudanwuxi003 yum.repos.d]# ll
    總用量 40
    -rw-r--r--. 1 root root 1503 8月   3 05:03 CentOS-Base.repo
    -rw-r--r--. 1 root root 1664 8月   3 05:01 CentOS-Base.repo.bak
    -rw-r--r--. 1 root root 1309 8月  30 2017 CentOS-CR.repo
    -rw-r--r--. 1 root root  649 8月  30 2017 CentOS-Debuginfo.repo
    -rw-r--r--. 1 root root  314 8月  30 2017 CentOS-fasttrack.repo
    -rw-r--r--. 1 root root  630 8月  30 2017 CentOS-Media.repo
    -rw-r--r--. 1 root root 1331 8月  30 2017 CentOS-Sources.repo
    -rw-r--r--. 1 root root 3830 8月  30 2017 CentOS-Vault.repo
    -rw-r--r--. 1 root root 1864 2月  22 16:49 mysql-community.repo
    -rw-r--r--. 1 root root 1885 2月  22 16:49 mysql-community-source.repo
    [root@fudanwuxi003 software]# yum install mysql-community-server
    [root@fudanwuxi003 software]# yum install mysql-server
    [root@fudanwuxi003 ~]# rpm -qa | grep mysql
    mysql-community-server-8.0.12-1.el7.x86_64
    mysql80-community-release-el7-1.noarch
    mysql-community-libs-8.0.12-1.el7.x86_64
    mysql-community-common-8.0.12-1.el7.x86_64
    mysql-community-libs-compat-8.0.12-1.el7.x86_64
    mysql-community-client-8.0.12-1.el7.x86_64
    
    [root@fudanwuxi003 lib]# systemctl start mysqld
    [root@fudanwuxi003 lib]# systemctl enable mysqld
    [root@fudanwuxi003 lib]# cat /var/log/mysqld.log |grep password  #查看初始密碼
    2018-08-20T11:54:48.607318Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: +goyZ3q8w?!z
    [root@fudanwuxi003 lib]# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 8
    Server version: 8.0.12
    
    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.
    
    mysql> show databases;
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.  #提示需要先修改密碼
    
    mysql> alter user root@‘localhost‘ identified by ‘CentOS7@ajie‘;  #修改密碼為CentOS7@ajie
    Query OK, 0 rows affected (0.10 sec)
    
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.02 sec)
    
    mysql> 

    安裝JDK、Tomcat和Mysql(CentOS 7.4)