云服务器ECS实例手动部署Java Web环境
配置信息
云服务器:阿里云(2G 1核基础版)
操作系统:CentOS 7.4
Tomcat版本:apache-tomcat-8.5.30
JDK版本:jdk1.8.0_141
MySQL:5.7.20
安装前准备
下载JDK和Tomcat、MySQL
wget https://mirrors.aliyun.com/apache/tomcat/tomcat-8/v8.5.30/bin/apache-tomcat-8.5.30.tar.gz
wget http://mirrors.linuxeye.com/jdk/jdk-8u141-linux-x64.tar.gz
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
安装JDK
1.新建目录
mkdir /usr/jdk
2.解压 jdk-8u141-linux-x64.tar.gz 到 /usr/jdk
tar xzf jdk-8u141-linux-x64.tar.gz -C /usr/jdk
3.设置环境变量
i.编辑/ect/profile
vi /etc/profile
ii.按i进入编辑模式
iii.在/etc/profile文件中尾部插入以下信息:
#set java environment
JAVA_HOME=/usr/jdk/jdk1.8.0_141
export CLASSPATH=.:$JAVA_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH
jre参考这个
export JAVA_HOME=/usr/java/jdk/jdk1.8.0_151
export JRE_HOME=/usr/java/jdk/jdk1.8.0_151/jre
export CLASSPATH=.:$JAVA_HOME/lib$:JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin/$JAVA_HOME:$PATH
iv.按esc
退出编辑模式,输入:wq
保存并关闭文件
4.加载环境变量:source /etc/profile
5.查看JDK版本:java -version
如果出现版本信息,则说明JDK安装成功
安装Tomcat
1.依次输入以下命令解压tomcat包到指定目录
tar xzf apache-tomcat-8.5.30.tar.gz -C /opt
2.创建链接
ln -s /opt/apache-tomcat-8.5.30 /opt/tomcat
3.启动Tomcat
/opt/tomcat/bin/startup.sh
查看tomcat启动信息
tail -f /opt/tomcat/logs/catalina.out
4.添加云服务器ECS安全组规则放行8080端口
5.设置开启自动启动 vim /etc/rc.local
插入以下代码
export JAVA_HOME=/usr/jdk/jdk1.8.0_141
/opt/tomcat/bin/startup.sh start
6.访问http://ip地址:8080
出现tomcat页面即可
安装MySQL
1.安装MySQL
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
2.安装MySQL服务
yum -y install mysql-server
Linux CenterOs 64位中安装 MySQL-server-5.5.25a-1.rhel5.x86_64.rpm 出现以下错误
[root@localhost upload]# rpm -ivh MySQL-server-5.5.25a-1.rhel5.x86_64.rpm
error: Failed dependencies:
libaio.so.1()(64bit) is needed by MySQL-server-5.5.25a-1.rhel5.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.5.25a-1.rhel5.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.5.25a-1.rhel5.x86_64
从以上错误信息可以看出是因为缺少库libaio,所以需要安装libaio
3.安装成功后可以对mysql进行一些设置
(1)开机自启:systemctl enable mysqld
(2)启动mysql:systemctl start mysqld
(3)重置密码:mysql_secure_installation
# systemctl start mysqld
# systemctl enable mysqld
# systemctl daemon-reload
4.修改my.cnf vim /etc/my.cnf
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server_id = 1
expire_logs_days = 3
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
5.启动MySQL service mysqld restart
查看MySQL中password相关的日志,获得初始密码 grep "password" /var/log/mysqld.log
[Note] A temporary password is generated for root@localhost: &fapv6lzHsWQ
上述&fapv6lzHsWQ便是初始密码
6.登录MySQL并修改密码
mysql -u root -p
接着输入初始密码即可登录
重置密码 alter user 'root'@'localhost' identified by 'Password123';
- Password123便是密码,默认配置下要求长度至少8位
7.刷新权限 flush privileges
8.设定root用户指定任意IP登录
grant all on *.* to 'root'@'%' identified by 'Root@@' with grant option;
- %为任意,如指定IP,则替换此处
9.添加云服务器ECS安全组规则放行3306端口,以便于使用远程数据库连接工具连接
参考 https://blog.csdn.net/qq_38736310/article/details/79904924?utm_source=copy