前段时间在阿里云买了一台ecs服务器,准备搭建博客使用,因此需要java环境和mysql数据库,这里学习记录一下搭建的过程。
Java环境搭建:准备工具:Xshell、JDK8(下载路径:jdk下载)
1、将本地下载的JDK上传到服务器上。(下面的上传文件的方法比较慢):
在Xshell中:--- 1.在/opt/下创建software文件夹存放从本地上传到服务器中的软件[root@Z ~]# cd /opt/[root@Z opt]# mkdir software --- 2.使用yum安装lrzsz,方便从本地上传软件到服务器,假如有Xftps可以省略此步骤 [root@Z software]# yum -version[root@Z software]# yum install lrzsz--- 3.将jdk-8u181-linux-x64.tar.gz和mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar上传到服务器上[root@Z software]# rz
2、对JDK进行解压:
在Xshell中:--- 4.在/opt/下创建module文件夹用来存放软件安装位置[root@Z opt]# mkdir module--- 5.将software文件夹下的上传的jdk解压缩到module下[root@Z software]# tar -zxvf jdk-8u181-linux-x64.tar.gz -C /opt/module/--- 6.可以看到Java的解压位置[root@Z jdk1.8.0_181]# pwd
3、配置Java环境变量:
在Xshell中:--- 7.进入到/etc/profile.d配置环境变量[root@Z jdk1.8.0_181]# cd /etc/profile.d--- 8.创建my_env.sh文件(可以直接在profile文件中添加,这里不演示)[root@Z profile.d]# vim my_env.sh--- 9.在键盘上Insert可以编辑,Esc加上:wq退出编辑并保存(my_env.sh输入下面的配置信息)#JAVA_HOMEexport JAVA_HOME=/opt/module/jdk1.8.0_181export PATH=$PATH:$JAVA_HOME/bin--- 10.source一下重新加载配置信息[root@Z profile.d]# source /etc/profile--- 11.查看安装Java环境的情况[root@Z profile.d]# java[root@nZ profile.d]# java -version
Mysql5.7环境搭建:
1、从本地上传文件到服务器。(MySQL下载:MySQL5.7下载):
(此处略,同上面的Java上传)
也可以用下面方法直接下载:Xshell中:[root@Z software]# wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/
2、解压到/opt/module/mysqL5.7/下,删除系统自带的mysql相关库:
在Xshell中:--- 1.提前在/opt/module/下创建要解压的文件夹mysql5.7[root@Z module]# mkdir mysql5.7--- 2.检查系统安装mysql、mariadb情况,有的话删除[root@Z software]# rpm -q | grep mysqlrpm: no arguments given for query[root@Z software]# rpm -qa | grep mysql[root@Z software]# rpm -qa | grep mariadbmariadb-libs-5.5.52-1.el7.x86_64[root@Z software]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64--- 3.解压到/opt/module/mysql5.7/下[root@Z software]# tar xvf mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar -C /opt/module/mysql5.7/
3、安装解压后的相关.rpm文件:
在Xshell下:--- 1.安装[root@Z mysql5.7]# rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm[root@Z mysql5.7]# rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm[root@Z mysql5.7]# rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm--- 2.【出现报错】[root@Z mysql5.7]# rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm warning: mysql-community-server-5.7.35-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEYerror: Failed dependencies:libaio.so.1()(64bit) is needed by mysql-community-server-5.7.35-1.el7.x86_64libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.35-1.el7.x86_64libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.35-1.el7.x86_64--- 3.【libaio下载】[root@Z mysql5.7]# yum install -y libaio--- 4.重新安装mysql-community-server-5.7.35-1.el7.x86_64.rpm [root@Z mysql5.7]# rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm
4、启动mysql并查看密码登录:
在mysql下:--- 1.第一次启动[root@Z mysql5.7]# systemctl start mysqld--- 2.查看初始密码[root@Z mysql5.7]# cat /var/log/mysqld.log | grep password--- 3.登录mysql[root@Z mysql5.7]# mysql -uroot -pEnter password:
5、修改mysql配置并修改密码:
在Xshell下:--- 1.mysql5.66以后root密码不能修改成简单的密码,因此需要关闭校验插件[root@Z mysql5.7]# vim /etc/my.cnfvalidate_password=off--- 2.重启并登录[root@Z mysql5.7]# systemctl restart mysqld[root@iZbp1fkiw7iblacz4tykgnZ mysql5.7]# mysql -uroot -pEnter password:--- 3.修改密码并查看数据库mysql> alter user 'root'@'localhost' identified by '123';mysql> exitmysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4 rows in set (0.00 sec)mysql>
6、修改权限可以远程登录:
在Xshell下:--- 1.修改权限远程登录mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;Query OK, 0 rows affected, 1 warning (0.00 sec)--- 2.关闭防火墙的3306端口[root@Z mysql5.7]# firewall-cmd --list-allFirewallD is not running[root@Z mysql5.7]# service firewalld restartRedirecting to /bin/systemctl restart firewalld.service[root@Z mysql5.7]# firewall-cmd --list-allpublic target: default icmp-block-inversion: no interfaces: sources: services: dhcpv6-client ssh ports: protocols: masquerade: no forward-ports: sourceports: icmp-blocks: rich rules: [root@Z mysql5.7]# firewall-cmd --permanent --add-port=3306/tcpsuccess[root@Z mysql5.7]# service firewalld restartRedirecting to /bin/systemctl restart firewalld.service[root@Z mysql5.7]# firewall-cmd --query-port=3306/tcpyes[root@Z mysql5.7]# firewall-cmd --list-all public target: default icmp-block-inversion: no interfaces: sources: services: dhcpv6-client ssh ports: 3306/tcp protocols: masquerade: no forward-ports: sourceports: icmp-blocks: rich rules: [root@Z mysql5.7]#
参考资料:
[1] 尚硅谷大数据Hadoop 3.x(入门搭建+安装调优)P24 (java环境)
[2] centos7中安装mysql安装 P1(mysql环境)
[3] libaio安装(安装mysql-community-server-5.7.16-1.el7.x86_64.rpm报错问题)
[4] CentOS7.2下MySql5.7开启远程连接授权(开启mysql远程连接)