centos安装java web服务器环境java8+tomcat8+mysql5.7

【centos安装java web服务器环境java8+tomcat8+mysql5.7】 一,准备工作
1,安装目录
创建如下路径/usr/develop,然后在develop目录下面创建java,tomcat和mysql三个目录。
二、配置java
1,下载jdk
wget命令下载jdk
wget http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz
2,安装jdk
tar -zxvf jdk-8u151-linux-x64.tar.gz
3,配置环境变量
#vi /etc/profile
export JAVA_HOME=/usr/develop/java/jdk1.8.0_121
export JRE_HOME=/usr/develop/java/jdk1.8.0_121/jre
export CLASSPATH=.:$JAVA_HOME/lib$:JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin/$JAVA_HOME:$PATH

链接:http://www.jianshu.com/p/2604e53a7f6a
來源:简书

保存后,输入source /etc/profile
4,验证是否成功
java-version
centos安装java web服务器环境java8+tomcat8+mysql5.7
文章图片




三、配置tomcat

1,下载tomcat
wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.23/bin/apache-tomcat-8.5.23.tar.gz
解压: tar -zxvf apache-tomcat-8.5.23.tar.gz
2,配置
将8080端口添加到防火墙例外并重启
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
3,启动tomcat
[root@localhost bin]# ./startup.sh


四、安装配置MySQL5.7

1,安装并配置mysql的yum源
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
安装之后/etc/yum.repos.d/会有mysql-community.repo和mysql-community-source.repo两个源
检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"

centos安装java web服务器环境java8+tomcat8+mysql5.7
文章图片




2,安装MySQL
yum install mysql-community-server
3,启动MySQL服务
systemctl start mysqld.service
查看mysql状态
centos安装java web服务器环境java8+tomcat8+mysql5.7
文章图片




4,修改root初始密码
在mysqld.log中找到mysql的初始密码
grep 'temporary password' /var/log/mysqld.log



用以上的密码登录,然后修改root密码
mysql>use mysql
mysql>alter user 'root'@'localhost' identified by 'NewPassword'
由于5.7开始有密码安全策略,修改密码策略
mysql>set global validate_password_policy=0;

mysql>set global validate_password_length=1;

5,设置mysql编码 mysql>status查看mysql状态(下图为已经设置过的) centos安装java web服务器环境java8+tomcat8+mysql5.7
文章图片


修改配置文件vi /etc/my.cnf
没有[client]的话,自己加上,然后client下添加代码defaul-character-set=utf8
在[mysqld]下添加代码
character-set-server=utf8
collation-server=utf8_general_ci
(此处参考https://www.cnblogs.com/woshimrf/p/5880055.html)
然后重启服务 systemctl restart mysqld.service


6,设置允许远程连接MySQL
update user set host='%' where user='root' and host='localhost';

flush privileges
如果还是不能远程访问,关闭防火墙systemctl stop firewalld.service



7,设置开机运行MySQL
systemctl enable mysqld
systemctl daemon-reload



    推荐阅读