Linux上搭建开发环境
Linux安装JDK、MySQL、Tomcat
一:安装前环境,安装包版本准备
1.1:Centos版本
[root@192 ~]# uname -a
Linux 192.168.18.131 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
#查看系统运行内核版本
[root@192 ~]# cat /proc/version
Linux version 3.10.0-1160.42.2.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Tue Sep 7 14:49:57 UTC 2021
[root@192 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
1.2:JDK版本
[root@localhost /]# java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)
1.3:MySQL版本
[root@localhost /]# mysql -V
mysql Ver 14.14 Distrib 5.7.18, for linux-glibc2.5 (x86_64) using EditLine wrapper
二:开始搭建环境
2.1:安装JDK
将jdk-8u281-linux-x64.tar.gz 包上传到
/opt/soft目录下,没有soft则创建一个,该目录将作为暂存三方软件包的位置解压jdk的tar包,
tar -zxvf jdk-8u281-linux-x64.tar.gz -C /usr/local/JAVA目录,没有JAVA目录则自行创建一个配置环境变量,
vim /etc/profile文件,保存退出。#配置JDK JAVA_HOME=/usr/local/JAVA/jdk1.8.0_281 CLASSPATH=$JAVA_HOME/lib/ PATH=$PATH:$JAVA_HOME/bin/ export JAVA_HOME CLASSPATH PATH重新加载配置文件
source /etc/profile验证jdk是否安装成功,分别使用
java -version、java、javac命令#java -version [root@localhost soft]# java -version java version "1.8.0_281" Java(TM) SE Runtime Environment (build 1.8.0_281-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode) #java命令 [root@localhost soft]# java Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) where options include: -d32 use a 32-bit data model if available -d64 use a 64-bit data model if available -server to select the "server" VM The default VM is server. -cp <class search path of directories and zip/jar files> -classpath <class search path of directories and zip/jar files> A : separated list of directories, JAR archives, and ZIP archives to search for class files. -D<name>=<value> set a system property -verbose:[class|gc|jni] enable verbose output -version print product version and exit -version:<value> Warning: this feature is deprecated and will be removed in a future release. require the specified version to run -showversion print product version and continue -jre-restrict-search | -no-jre-restrict-search Warning: this feature is deprecated and will be removed in a future release. include/exclude user private JREs in the version search -? -help print this help message -X print help on non-standard options -ea[:<packagename>...|:<classname>] -enableassertions[:<packagename>...|:<classname>] enable assertions with specified granularity -da[:<packagename>...|:<classname>] -disableassertions[:<packagename>...|:<classname>] disable assertions with specified granularity -esa | -enablesystemassertions enable system assertions -dsa | -disablesystemassertions disable system assertions -agentlib:<libname>[=<options>] load native agent library <libname>, e.g. -agentlib:hprof see also, -agentlib:jdwp=help and -agentlib:hprof=help -agentpath:<pathname>[=<options>] load native agent library by full pathname -javaagent:<jarpath>[=<options>] load Java programming language agent, see java.lang.instrument -splash:<imagepath> show splash screen with specified image See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details. #javac命令 [root@localhost soft]# javac Usage: javac <options> <source files> where possible options include: -g Generate all debugging info -g:none Generate no debugging info -g:{lines,vars,source} Generate only some debugging info -nowarn Generate no warnings -verbose Output messages about what the compiler is doing -deprecation Output source locations where deprecated APIs are used -classpath <path> Specify where to find user class files and annotation processors -cp <path> Specify where to find user class files and annotation processors -sourcepath <path> Specify where to find input source files -bootclasspath <path> Override location of bootstrap class files -extdirs <dirs> Override location of installed extensions -endorseddirs <dirs> Override location of endorsed standards path -proc:{none,only} Control whether annotation processing and/or compilation is done. -processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process -processorpath <path> Specify where to find annotation processors -parameters Generate metadata for reflection on method parameters -d <directory> Specify where to place generated class files -s <directory> Specify where to place generated source files -h <directory> Specify where to place generated native header files -implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files -encoding <encoding> Specify character encoding used by source files -source <release> Provide source compatibility with specified release -target <release> Generate class files for specific VM version -profile <profile> Check that API used is available in the specified profile -version Version information -help Print a synopsis of standard options -Akey[=value] Options to pass to annotation processors -X Print a synopsis of nonstandard options -J<flag> Pass <flag> directly to the runtime system -Werror Terminate compilation if warnings occur @<filename> Read options and filenames from file到此jdk安装结束,
2.2:安装MySQL
将下载的官方tar包上传到
/opt/soft/目录下,先查询系统自带的数据库,查询命令
rpm -qa|grep mariadb或yun list install|grep mariddb#查询自带的数据库 [root@localhost ~]# rpm -qa|grep mariadb mariadb-libs-5.5.68-1.el7.x86_64 [root@localhost ~]# yum list installed |grep mariadb mariadb-libs.x86_64 1:5.5.68-1.el7 @base #卸载自带的数据库 yum -y remove mariadb-libs.x86_64 安装mysql前要先进行检查自带的mysql数据库,如果存在就卸载自带的mysql [root@192 usr]# rpm -qa|grep mariadb mariadb-libs-5.5.68-1.el7.x86_64 #卸载命令 yum -y remove mariadb-libs-5.5.68-1.el7.x86_64解压上传到
/opt/soft/下的mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz压缩包到/usr/local/MySQL,没有则创建MySQLtar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local/MySQL创建mysql用户组
groupadd mysql创建mysql用户及指定该用户所属组
useradd -r -g mysql mysql在MySQL解压目录下创建
data和logs文件夹[root@localhost local]# ls bin etc games include java lib lib64 libexec MySQL sbin share src [root@localhost local]# cd MySQL/ [root@localhost MySQL]# ls mysql-5.7.18-linux-glibc2.5-x86_64 [root@localhost MySQL]# mv mysql-5.7.18-linux-glibc2.5-x86_64/* . [root@localhost MySQL]# ls bin COPYING docs include lib man mysql-5.7.18-linux-glibc2.5-x86_64 README share support-files [root@localhost MySQL]# rm -rf mysql-5.7.18-linux-glibc2.5-x86_64/ [root@localhost MySQL]# ls bin COPYING docs include lib man README share support-files [root@localhost MySQL]# mkdir data mkdir logs [root@localhost MySQL]# ls bin COPYING data docs include lib logs man README share support-files修改
/usr/local/MySQL文件夹所对应用户和组[root@localhost MySQL]# chown -R mysql:mysql /usr/local/MySQL/ [root@localhost MySQL]# ll total 36 drwxr-xr-x. 2 mysql mysql 4096 Sep 13 22:34 bin -rw-r--r--. 1 mysql mysql 17987 Mar 18 2017 COPYING drwxr-xr-x. 2 mysql mysql 6 Sep 13 22:37 data drwxr-xr-x. 2 mysql mysql 55 Sep 13 22:34 docs drwxr-xr-x. 3 mysql mysql 4096 Sep 13 22:33 include drwxr-xr-x. 5 mysql mysql 229 Sep 13 22:34 lib drwxr-xr-x. 2 mysql mysql 6 Sep 13 22:37 logs drwxr-xr-x. 4 mysql mysql 30 Sep 13 22:34 man -rw-r--r--. 1 mysql mysql 2478 Mar 18 2017 README drwxr-xr-x. 28 mysql mysql 4096 Sep 13 22:34 share drwxr-xr-x. 2 mysql mysql 90 Sep 13 22:34 support-files创建初始化配置问价,
vim /etc/my.cnf[mysql] #数据库默认编码 default-character-set=utf8mb4 #通信 socket=/var/lib/mysql/mysql.sock [mysqld] #默认端口 port=3306 socket=/var/lib/mysql/mysql.sock #默认安装路径 basedir=/usr/local/MySQL #默认保存数据路径 datadir=/usr/local/MySQL/data #最大连接数 max_connections=20 #最大等待时间 wait_timeout=3153600 #服务端默认编码 character-set-server=utf8mb4 #默认数据库引擎 default-storage-engine=InnoDB #指定数据库日志文件路径 log-error=/usr/local/MySQL/log/error.log explicit_defaults_for_timestamp=true #跳过密码验证 #skip-grant-tables在
/var/lib目录下创建mysql文件夹,并设置权限mkdir mysql chmod 757 mysql进入到
cd /usr/local/MySQL/目录下,执行初始化,不报错即可[root@localhost MySQL]# bin/mysqld --initialize --user=mysql --datadir=/usr/local/MySQL/data/ --basedir=/usr/local/MySQL/将
/usr/local/MySQL/support-files目录下的mysql.serve复制到/ect/init.d/mysqld[root@localhost support-files]# ls magic mysqld_multi.server mysql-log-rotate mysql.server [root@localhost support-files]# cp mysql.server /etc/init.d/mysqld启动MySQL服务,如果启动报错,查看创建的
data、log目录的权限是否足够[root@localhost MySQL]# service mysqld start Starting MySQL. SUCCESS!配置MySQL的环境变量,
vim /etc/profile#配置MySql PATH=$PATH:/usr/local/MySQL/bin export PATH登录MySQL服务,进行密码修改,首次登录开启密码跳过验证
[root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select host,user,authentication_string from user; +-----------+-----------+-------------------------------------------+ | host | user | authentication_string | +-----------+-----------+-------------------------------------------+ | localhost | root | *0F6CB0C5BCB1146BE855240EB5DFDD427D3330FA | | localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | +-----------+-----------+-------------------------------------------+ 2 rows in set (0.00 sec) mysql> update user set authentication_string ='' ,host='%' where user='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> alter user 'root'@'%' identified by 'root123'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> select host,user,authentication_string from user; +-----------+-----------+-------------------------------------------+ | host | user | authentication_string | +-----------+-----------+-------------------------------------------+ | % | root | *FAAFFE644E901CFAFAEC7562415E5FAEC243B8B2 | | localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | +-----------+-----------+-------------------------------------------+ 2 rows in set (0.00 sec) mysql> exit Bye去掉
vim /etc/my.cnf中的密码跳过验证,重启MySQL服务,进行密码登录#skip-grant-tables #重启服务 [root@localhost ~]# service mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! [root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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> exit Bye开放3306端口,重启防火墙,以便于远程访问
#开放3306端口 firewall-cmd --zone=public --add-port=3306/tcp --permanent [root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent success #重启防火墙服务 systemctl restart firewalld.service [root@localhost ~]# systemctl restart firewalld.service #插卡开放端口信息 firewall-cmd --list-ports [root@localhost ~]# firewall-cmd --list-ports 80/tcp 6379/tcp 3306/tcp #查看所有信息 firewall-cmd --list-all [root@localhost ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: dhcpv6-client ssh ports: 80/tcp 6379/tcp 3306/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:MySQL到此安装结束
2.3:安装Tomcat
下载tomcat的linux对应的压缩包,上传到
/opt/soft目录下解压tomcat压缩包,
tar -zxvf apache-tomcat-8.5.64.tar.gz -C /usr/local/[root@localhost local]# ls bin etc games include java lib lib64 libexec MySQL sbin share src apache-tomcat-8.5.64修改apache-tomcat-8.5.64的名字,
mv apache-tomcat-8.5.64 tomcat8.5[root@localhost local]# ls bin etc games include java lib lib64 libexec MySQL sbin share src tomcat8.5配置环境变量,
vim /etc/profile#配置Tomcat CATALINA_HOME=/usr/local/tomcat8.5 PATH=$PATH:$CATALINA/bin export CATALINA_HOME PATH重新加载配置文件,使其生效
source /etc/profile开放tomcat的8080端口,并重启防火墙
systemctl restart firewalldfirewall-cmd --zone=public --add-port=8080/tcp --permanent运行tomcat启动程序,进入到
cd /usr/local/tomcat8.5/bin/./startup.sh访问tomcat,http://linux主机IP:8080/
http://192.168.18.130:8080/到此tomcat安装完成

浙公网安备 33010602011771号