愚根琢玉 發表於 2023-9-2 00:00:00

详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)

<p>
        本文会详细介绍 windows 上安装虚拟机之后,如何在 linux 中安装 jdk、tomcat 和 mysql 的过程,希望能帮助到你。</p>
<p>
        首先,这些安装都是在 xshell 中运行的,什么,没有 xshell?好吧,我给你资源。安装之后里面就会有 xshell,直接打开用就行了。</p>
<p>
        <strong>1. 安装 jdk</strong></p>
<p>
        个人建议安装的时候使用 rpm 包,linux 中的 rpm 相当于 windows 中的 exe,使用本文的安装方法无需手动设置环境变量。</p>
<p>
        在这里给大家提供一份 jdk-8 的资源。</p>
<p>
        <strong>1.1 将本地的 jdk 文件上传到服务器(linux)中</strong></p>
<p>
        很多人会使用 xftp 直接拖动到 linux 中,虽然能够达到同样的效果,但这是菜鸟的做法,今天就来使用另外一种方法,相当粗暴:敲命令。</p>
<p>
        敲命令会借助于一个软件,以后安装软件优先使用 yum。yum 将 linux 一些流行的包,放到国内一些比较快的服务器上,它下载的是 rpm 格式的安装包,并且安装。</p>
<p>
        好了,先来安装一下这个软件,命令:yum -y install lrzsz;</p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/bc1aa908ea0d448e7cc58ffffcaafa65.jpg"></p>
<p>
        使用文件上传命令:rz -y;</p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/babf1d06a02dfdb56bd5331dbb33e475.jpg"></p>
<p>
        会弹出一个对话框,选择 jdk 的安装包就行了。</p>
<p>
        <strong>1.2 拿到 rpm 包</strong></p>
<p>
        使用命令:<code>yum -y install jdk-8u141-linux-x64.rpm;</code></p>
<p>
        之后稍等片刻就可以安装成功了,这种方法不需要配置环境变量。装完之后要养成一个习惯,测试环境变量好不好使:</p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/9fa6d7d42d74f4ffb9ee0bc2c30d7aa8.jpg"></p>
<p>
        <strong>2. 安装 tomcat</strong></p>
<p>
        <strong>2.1 tomcat 安装包放进 linux 中</strong></p>
<p>
        可以使用命令行,在这里为了省事儿就不用命令了,直接使用 xftp 拖动到 linux 中(见谅见谅)。这里给一份 tomcat 的资源。</p>
<p>
        (各种资源,怎么样,我还不错吧,哈哈)</p>
<p>
        建议将自己需要解压的软件都放到 /data 目录下面,如果没有这个目录,可以直接在根目录下创建该目录,创建该目录的命令:mkdir /data</p>
<p>
        进入到/data目录中,将 tomcat 的压缩包复制(剪切到) /data 目录中:</p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/d916915ed5e72574dc58238dccd82ff3.jpg"></p>
<p>
        <strong>2.2 解压 tomcat 的压缩包</strong></p>
<p>
        使用命令:tar -xzvf apache-tomcat-8.0.45.tar.gz</p>
<p>
        其中:</p>
<p>
        x:代表释放(解压);<br>
        v:代表显示解压的过程;<br>
        z:代表这是不是一个压缩包,一般来说结尾是 gz 都代表是压缩过的包;<br>
        f:表示递归解压;</p>
<p>
        当然你也可以选择修改 tomcat 的名字,命令:mv(此处有空格)apache-tomcat-8.0.45(此处也有空格)tomcat_test_1</p>
<p>
        启动 tomcat:不管写的是相对路径还是绝对路径,都要指定运行 startup.sh</p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/0fd36044fff5aecc20a1bb47b6084bc4.jpg"></p>
<p>
        <strong>2.3 查看 tomcat 有木有启动</strong></p>
<p>
        有人会有疑问,tomcat 有没有启动你自己还不造吗,有的时候 tomcat 端口被占用,就会启动失败。</p>
<p>
        查看是否启动命令:ps aux|grep tomcat</p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/17d53109c06ff84c2350fb35bd4da9f9.jpg"></p>
<p>
        然后看一下 tomcat 路径和它的端口号,如上图红框所示。</p>
<p>
        当你的 tomcat 打开之后,欣喜若狂的在浏览器中输入你的虚拟机 ip 地址加 8080 访问三条腿的猫(tomcat 图标)时,就会发现,等到天亮猫也不会出现,不是猫丢了,而是它在你的电脑的路上被伟大的防火墙挡住了。</p>
<p>
        所以还差一步,停掉防火墙。</p>
<p>
        <strong>2.4 停掉防火墙</strong></p>
<p>
        命令:<code>service iptables stop</code></p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/56a090b8a5e28ec3993ede00c5d424b2.jpg"></p>
<p>
        然后再在浏览器里输入虚拟机的 ip 地址加 8080 就可以看到 tomcat 的标识了:</p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/f20b51eb0b7daee2fe80c6c263a75204.jpg"></p>
<p>
        <strong>3. 安装最新版本的 mysql 5.7</strong></p>
<p>
        在 mysql 的官网上,有一个链接:a quick guide to using the mysql yum repository。</p>
<p>
        现在,我按照这个地址,给大家走一下安装流程。</p>
<p>
        3.1 创建 yum 源</p>
<p>
        创建 yum 源,文件名随便起,但是官网建议命名为 mysql-community.repo,所以就新建一个该文件,扩展名为 repo,文件内容如下:</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlighterplain" id="highlighter_728135">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                        <div class="line number2 index1 alt1">
                                                                2</div>
                                                        <div class="line number3 index2 alt2">
                                                                3</div>
                                                        <div class="line number4 index3 alt1">
                                                                4</div>
                                                        <div class="line number5 index4 alt2">
                                                                5</div>
                                                        <div class="line number6 index5 alt1">
                                                                6</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="plain plain"></code>
</div>
                                                                <div class="line number2 index1 alt1">
                                                                        <code class="plain plain">name=mysql 5.7 community server</code>
</div>
                                                                <div class="line number3 index2 alt2">
                                                                        <code class="plain plain">baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/</code>
</div>
                                                                <div class="line number4 index3 alt1">
                                                                        <code class="plain plain">enabled=1</code>
</div>
                                                                <div class="line number5 index4 alt2">
                                                                        <code class="plain plain">gpgcheck=0</code>
</div>
                                                                <div class="line number6 index5 alt1">
                                                                        <code class="plain plain">gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-mysql</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
</div>
<p>
        将这个文件上传到 /etc/yum.repos.d/ 中。</p>
<p>
        然后使用命令:yum search mysql,会发现最下面多出一行:</p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/e4ef0daa7676574d7a2d0541b01feeac.jpg"></p>
<p>
        <strong>3.2 安装 mysql</strong></p>
<p>
        使用命令:<code>yum install mysql-community-server</code></p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/3ff6c992a148e28cd52858bd98d7c445.jpg"></p>
<p>
        <strong>3.3 重启 mysql</strong></p>
<p>
        使用命令:<code>service mysqld restart</code></p>
<p>
        <strong>3.4 查看登录密码</strong></p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/24a4e33f8313c5a0d63370bebcacc99a.jpg"></p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/e895a1baa02133b08eb15ec57c822582.jpg"></p>
<p>
        此密码是临时密码,只能使用一次,使用改密码登陆 mysql 客户端。</p>
<p>
        <strong>3.5 登陆 mysql 客户端</strong></p>
<p>
        使用命令:<code>mysql -u root -p</code></p>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/87dadcfbb5bc1a0d7267658c008d02ae.jpg"></p>
<p>
        登陆成功以后,第一件事当然是改密码啦,哈哈。</p>
<p>
        官网提供了修改密码的命令:</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlighterplain" id="highlighter_685585">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="plain plain">alter user 'root'@'localhost' identified by 'mynewpass4!';</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
</div>
<p>
        但是呢,这个密码也很难记啊,如果想改成简单的密码,比如说将mynewpass4! 换成 123456,这样的密码多好记,然后运行就会发现,它不让你改,因为过于简单不符合它的命名规则。</p>
<p>
        所以,首先按照上面官网提供的命令成功登录 mysql ,然后卸载 mysql密码的插件:</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlighterplain" id="highlighter_831248">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="plain plain">uninstall plugin validate_password;</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
</div>
<p>
        然后再修改密码:</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlightersql" id="highlighter_106576">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="sql keyword">alter</code> <code class="sql color2">user</code> <code class="sql string">'root'</code><code class="sql plain">@</code><code class="sql string">'localhost'</code> <code class="sql plain">identified </code><code class="sql keyword">by</code> <code class="sql string">'123456'</code><code class="sql plain">;</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
</div>
<p>
        键入 exit 退出客户端,再使用新密码登录。</p>
<p>
        默认账号使用本地使用,不同的电脑不让使用,比如说,你在 windows 里用 navicat 连接该 mysql 数据库是不可以的。</p>
<p>
        怎么样才可以呢?重新创建一个账号,允许远程链接,命令如下:</p>
<p>
         </p>
<div class="codetitle">
        <span><u>复制代码</u></span> 代码如下:</div>
<div class="codebody" id="code45386">
        grant all privileges on *.* to 'root'@'%'identified by '123456' with grant option;</div>
<p>
         </p>
<p>
        然后再在 windows 下使用 navicat 就可以连接上该数据库了。</p>
<p>
        <strong>3.6 修改默认的编码</strong></p>
<p>
        使用 navicat 就可以连接数据库之后默认的编码格式是拉丁文,所以要修改默认的编码格式。</p>
<p>
        修改配置文件 /etc/my.cnf,再改文件的时候,养成一个习惯,先备份一份在修改。</p>
<p>
        使用 vi /etc/my.cnf,然后找到 mysqld,增加一行</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlighterplain" id="highlighter_301179">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="plain plain">character_set_server=utf8</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
</div>
<p>
        <img title="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" alt="详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)" src="https://zhuji.jb51.net/uploads/img/202305/308cf3e916b98a7d3116ff73cbcf0c20.jpg"></p>
<p>
        然后重启mysql服务就可以了,使用命令:service mysqld restart</p>
<p>
        以上就是详细的安装过程希望能帮助到你,欢迎收藏加关注。</p>
<p>
        原文链接:http://www.jianshu.com/p/8a5e92a91e9a?utm_source=tuicool&amp;utm_medium=referral</p>
頁: [1]
查看完整版本: 详解Linux 安装 JDK、Tomcat 和 MySQL(图文并茂)