Linux JAVA Web 环境搭建
编辑安装JDK 17
下载JDK
JDK下载地址:
https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html
https://repo.huaweicloud.com/java/jdk/11.0.2+9/jdk-11.0.2_osx-x64_bin.dmg
JDK版本:Java SE Development Kit 8u51 Linux x64 jdk-8u51-linux-x64.tar.gz
安装JDK
安装步骤:
1. mkdir java -在/opt下建立java目录下
2. tar zxvf ~/jdk-8u45-linux-x64.tar.gz -C /opt/java -解压jdk到java文件下
配置环境变量
操作步骤:
1. 打开.bashrc文件
vi ~/.bashrc
2. 文件的末尾添加:
export JAVA_HOME=/opt/java/jdk1.8.0_45
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
3. :wq
-保存退出
4. 运行命令来使之生效
source ~/.bashrc
安装 java 1.8
下载 JDK
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm
添加执行权限命令
chmod +x jdk-8u131-linux-x64.rpm
执行 rpm 进行安装命令
rpm -ivh jdk-8u131-linux-x64.rpm
查看JDK是否安装成功命令
java -version
查看JDK的安装路径(一般默认的路径:/usr/java/jdk1.8.0_131)
测试
运行命令:java -version
显示结果:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
表示安装成功。
安装Tomcat
下载Tomcat
下载地址:http://tomcat.apache.org/download-70.cgi
版本:7.0.63 Core tar.gz
安装Tomcat
操作步骤:
1. 解压Tomcat到java目录下
2. 运行命令:sh /opt/java/apache-tomcat-7.0.63/bin/startup.sh 启动Tomcat
3. 返回结果:
Using CATALINA_BASE: /opt/java/apache-tomcat-7.0.63
Using CATALINA_HOME: /opt/java/apache-tomcat-7.0.63
Using CATALINA_TMPDIR: /opt/java/apache-tomcat-7.0.63/temp
Using JRE_HOME: /opt/java/jdk1.8.0_45/jre
Using CLASSPATH: /opt/java/apache-tomcat-7.0.63/bin/bootstrap.jar:/opt/java/apache-tomcat-7.0.63/bin/tomcat-juli.jar
Tomcat started.
4. 测试:在浏览器运行http://IP:8080 是否能正确刷出网页
安装maven
下载maven
下载地址:http://maven.apache.org/download.cgi
版本:apache-maven-3.1.1-bin.tar.gz
安装maven
操作步骤:
1. 解压maven到java目录下
2. 配置环境变量:
export MAVEN_HOME=/opt/java/apache-maven-3.1.1
export PATH=${MAVEN_HOME}/bin:$PATH
3. :wq 保存退出
4. source ~/.bashrc 运行命令来使之生效
测试
运行命令:mvn -version
显示结果:
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 23:22:22+0800)
Maven home: /opt/java/apache-maven-3.1.1
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: /opt/java/jdk1.8.0_45/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-431.23.3.el6.x86_64", arch: "amd64", family: "unix"
表示安装成功
安装MySql数据库
一、安装YUM Repo
1、由于CentOS 的yum源中没有mysql,需要到下载yum repo配置文件
下载命令:
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
2、然后进行repo的安装:
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
执行完成后会在/etc/yum.repos.d/目录下生成两个repo文件mysql-community.repo mysql-community-source.repo
二、使用yum命令即可完成安装
注意:必须进入到 /etc/yum.repos.d/目录后再执行以下脚本
1、安装命令:
yum install mysql-server
2、启动msyql:
systemctl start mysqld #启动MySQL
3、获取安装时的临时密码(在第一次登录时就是用这个密码):
grep 'temporary password' /var/log/mysqld.log
4、倘若没有获取临时密码
1、删除原来安装过的mysql残留的数据
rm -rf /var/lib/mysql
2.再启动mysql
systemctl start mysqld #启动MySQL
三、登录MySql
mysql -u root -p
然后输入密码(刚刚获取的临时密码)
四、创建数据库,添加用户和授权登录
1. 创建数据库jjhuzhu,并制定默认的字符集是utf8
mysql> CREATE DATABASE IF NOT EXISTS jjhuzhu DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
2. 创建用户
mysql> CREATE USER 'jjhuzhu'@'%' IDENTIFIED BY 'jjhuzhu';
3. 刷新系统
mysql> flush privileges;
4. 授权用户
mysql> grant all on jjhuzhu.* to 'jjhuzhu'@'%' identified by 'jjhuzhu';
5. 刷新系统
mysql> flush privileges;
五、其他配置
1、设置安全选项:
mysql_secure_installation
2、关闭MySQL
systemctl stop mysqld
3、重启MySQL
systemctl restart mysqld
4、查看MySQL运行状态
systemctl status mysqld
5、设置开机启动
systemctl enable mysqld
6、关闭开机启动
systemctl disable mysqld
7、配置默认编码为utf8:
vi /etc/my.cnf #添加 [mysqld] character_set_server=utf8 init_connect='SET NAMES utf8'
其他默认配置文件路径:
配置文件:/etc/my.cnf 日志文件:/var/log//var/log/mysqld.log 服务启动脚本:/usr/lib/systemd/system/mysqld.service socket文件:/var/run/mysqld/mysqld.pid
8、查看版本
select version();
安装SVN
运行命令:yum install subversion
安装nginx
运行命令:yum install nginx
启动:service nginx start
重新加载:service nginx reload
安装redis
运行命令:yum install redis
启动:service redis start
重新启动:service redis restart
配置防火墙
1.安装iptables服务
# yum install -y iptables-services
2.写入过滤规则
# vi /etc/sysconfig/iptables
3.启动iptables服务
# service iptables start
4.查看当前iptables规则:iptables -L -n
5.查看当前监听端口:netstat –tnlp
------------------------------------------------------------
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -s 127.0.0.1/32 -j ACCEPT
-A INPUT -p tcp --dport 22 -j ACCEPT
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT
-A INPUT -p tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp --dport 23450 -j ACCEPT
-A INPUT -m state --state INVALID -j DROP
-A FORWARD -m state --state INVALID -j DROP
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -i lo -p all -j ACCEPT
-A INPUT -j REJECT
COMMIT
----------------------------------------------------------
- 0
- 0
-
赞助
赞赏 -
分享