Centos 服务器 安装 JDK、Tomcat、Mysql

配置JAVA环境

    查看yum库中的Java安装包

    yum -y list java*

    输入之后回车,会看到各种不同版本的jdk包


使用yum安装Java环境

安装java-1.8.0版本的所有相关程序yum -y install java-1.8.0-openjdk*



出现complete!说明安装结束


查看刚安装的Java版本信息 

java -version 出现下图信息,说明安装成功 


配置环境变量


由上可知java的路径为: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64
打开文件

vi /etc/profile

在文件最后一行添加

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64

export JRE_HOME=${JAVA_HOME}/jre

export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib

export PATH=${JAVA_HOME}/bin:$PATH

//查看是否配置成功

echo $PATH

 


配置Tomcat

转自 https://blog.csdn.net/TheBlackbeard/article/details/52549763

关于LINUX权限-bash: ./startup.sh: Permission denied

在执行./startup.sh,或者./shutdown.sh的时候,爆出了Permission denied,
其实很简单,就是今天在执行tomcat的时候,用户没有权限,而导致无法执行,
用命令chmod 修改一下bin目录下的.sh权限就可以了
如chmod u+x *.sh

在此执行,OK了


开启防火墙

1.使用命令  firewall-cmd --state查看防火墙状态。得到结果是running或者not running

2.为running 时,向firewall 添加需要开放的端口

命令为 firewall-cmd --permanent --zone=public --add-port=8080/tcp //永久的添加该端口。去掉--permanent则表示临时。

4.firewall-cmd --reload //加载配置,使得修改有效。

5.使用命令 firewall-cmd --permanent --zone=public --list-ports //查看开启的端口,出现8080/tcp这开启正确

6.再次使用外部浏览器访问,这出现tomcat的欢迎界面。

 


安装mysql

一、系统环境

yum update升级以后的系统版本为

[root@yl-web yl]# cat /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core) 

二、mysql安装

一般网上给出的资料都是

#yum install mysql
#yum install mysql-server
#yum install mysql-devel

安装mysql和mysql-devel都成功,但是安装mysql-server失败,如下:

复制代码
[root@yl-web yl]# yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.sina.cn
 * extras: mirrors.sina.cn
 * updates: mirrors.sina.cn
No package mysql-server available.
Error: Nothing to do
复制代码

查资料发现是CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。

有两种解决办法:

1、方法一:安装mariadb

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

安装mariadb,大小59 M。

[root@yl-web yl]# yum install mariadb-server mariadb 

mariadb数据库的相关命令是:

systemctl start mariadb  #启动MariaDB

systemctl stop mariadb  #停止MariaDB

systemctl restart mariadb  #重启MariaDB

systemctl enable mariadb  #设置开机启动

所以先启动数据库

[root@yl-web yl]# systemctl start mariadb

然后就可以正常使用mysql了

复制代码
[root@yl-web yl]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.41-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> 
复制代码

安装mariadb后显示的也是 MariaDB [(none)]> ,可能看起来有点不习惯。下面是第二种方法。

2、方法二:官网下载安装mysql-server

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server

安装成功后重启mysql服务。

# service mysqld restart

初次安装mysql,root账户没有密码。

复制代码
[root@yl-web yl]# mysql -u root 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

mysql> 
复制代码

设置密码

mysql> set password for 'root'@'localhost' =password('password');
Query OK, 0 rows affected (0.00 sec)

mysql> 

不需要重启数据库即可生效。

在mysql安装过程中如下内容:

复制代码
Installed:
  mysql-community-client.x86_64 0:5.6.26-2.el7                mysql-community-devel.x86_64 0:5.6.26-2.el7                
  mysql-community-libs.x86_64 0:5.6.26-2.el7                  mysql-community-server.x86_64 0:5.6.26-2.el7               

Dependency Installed:
  mysql-community-common.x86_64 0:5.6.26-2.el7                                                                            

Replaced:
  mariadb.x86_64 1:5.5.41-2.el7_0          mariadb-devel.x86_64 1:5.5.41-2.el7_0   mariadb-libs.x86_64 1:5.5.41-2.el7_0  
  mariadb-server.x86_64 1:5.5.41-2.el7_0  
复制代码

所以安装完以后mariadb自动就被替换了,将不再生效。

[root@yl-web yl]# rpm -qa |grep mariadb
[root@yl-web yl]# 

三、配置mysql

1、编码

mysql配置文件为/etc/my.cnf

最后加上编码配置

[mysql]
default-character-set =utf8

这里的字符编码必须和/usr/share/mysql/charsets/Index.xml中一致。

2、远程连接设置

把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。

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

如果是新用户而不是root,则要先新建用户

mysql>create user 'username'@'%' identified by 'password';  

此时就可以进行远程连接了。


安装mysql转自https://www.cnblogs.com/starof/p/4680083.html


猜你喜欢

转载自blog.csdn.net/qq_40369944/article/details/81022466