Linux上搭建项目的环境基础(一)
(做个笔记,自己以后忘了方便查找,会持续更新…)
重要提示
建议安装顺序:jdk → maven → 更新yum → gcc-c++ → zlib → pcre → python3 → tomcat
安装排序原因:因为很多配置需要依赖其他配置才能完成编译和安装,否则会安装失败
例如:python3安装需要先有zlib,pcre安装需要先有gcc-c++
一、JAVA环境部署(JDK)
重要程度 ✮✮✮✮✮
1.下载解压
下载链接:https://pan.baidu.com/s/1YQygkGlMj_i04MA6CBwGFw
提取码:ncrk
解压到安装目录:/data/base/jdk(我的目录做个举例,请按照自己的需要调整)
tar -zxvf jdk-8u201-linux-x64.tar.gz
2.配置环境变量,vi /etc/profile,在文件的最后面添加一下内容:
export JAVA_HOME=/data/base/jdk
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib/:$JAVA_HOME/lib/tools.jar
3.让配置立即生效
source /etc/profile
4.java环境验证
执行java –version能看到jdk的版本,则java环境搭建成功
[root@linshi-test ~]# java -version
openjdk version "1.8.0_201"
OpenJDK Runtime Environment (build 1.8.0_201-b09)
OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode)
二、maven安装
重要程度 ✮✮✮✮
1.下载解压
官网下载:https://maven.apache.org/download.cgi
解压到安装目录:/opt/server/(这是我的目录做个举例,请按照自己的需要调整)
[root@localhost base]# cd /opt/server/
[root@localhost server]# ll
total 8472
-rw-r--r--. 1 root root 8673123 Mar 17 00:07 apache-maven-3.8.5-bin.tar.gz
[root@localhost server]# tar -zxvf apache-maven-3.8.5-bin.tar.gz
apache-maven-3.8.5/README.txt
apache-maven-3.8.5/LICENSE
apache-maven-3.8.5/NOTICE
apache-maven-3.8.5/lib/
apache-maven-3.8.5/lib/commons-cli.license
......省略
2.配置环境变量
公共文件/etc/profile中保存Maven的环境变量:
###### maven ######
export M2_HOME=/opt/server/apache-maven-3.8.5
export PATH=$PATH:$M2_HOME/bin
使配置的环境变量生效
source /etc/profile
3.检验是否安装成功
[root@localhost apache-maven-3.8.5]# mvn -version
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /opt/server/apache-maven-3.8.5
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /data/base/jdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.59.1.el7.x86_64", arch: "amd64", family: "unix"
三、更新yum到最新版本
重要程度 ✮✮✮✮
这样一来,再安装其他组件就会选择最新的,可避免大部分yum命令安装失败的情况
[root@localhost base]# yum -y update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package GeoIP.x86_64 0:1.5.0-11.el7 will be updated
yelp-xsl.noarch 0:3.28.0-1.el7 yum.noarch 0:3.4.3-168.el7.centos yum-plugin-fastestmirror.noarch 0:1.1.31-54.el7_8
yum-utils.noarch 0:1.1.31-54.el7_8 zenity.x86_64 0:3.28.1-1.el7 zlib.x86_64 0:1.2.7-19.el7_9
-----------------------------------内容较多,省略展示------------------------------------
Replaced:
NetworkManager.x86_64 1:1.4.0-12.el7 caribou.x86_64 0:0.4.16-1.el7 caribou-gtk2-module.x86_64 0:0.4.16-1.el7 caribou-gtk3-module.x86_64 0:0.4.16-1.el7
gnome-tweak-tool.noarch 0:3.14.3-2.el7 grub2.x86_64 1:2.02-0.44.el7.centos grub2-tools.x86_64 1:2.02-0.44.el7.centos iwl7265-firmware.noarch 0:22.0.7.0-49.el7
pyatspi.noarch 0:2.14.0-2.el7 pygobject3.x86_64 0:3.14.0-3.el7 pygobject3-base.x86_64 0:3.14.0-3.el7 python-caribou.noarch 0:0.4.16-1.el7
rdma.noarch 0:7.3_4.7_rc2-5.el7 urw-fonts.noarch 0:2.4-16.el7 usbmuxd.x86_64 0:1.0.8-11.el7
Complete!
四、gcc-c++安装
重要程度 ✮✮✮✮
直接使用yum安装,方便快捷
root超级管理员
yum install -y gcc-c++
普通用户
sudo yum install -y gcc-c++
[root@localhost base]# yum install -y gcc-c++
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package gcc-c++.x86_64 0:4.8.5-44.el7 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-44.el7 for package: gcc-c++-4.8.5-44.el7.x86_64
--> Running transaction check
---> Package libstdc++-devel.x86_64 0:4.8.5-44.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================================================================================
Installing:
gcc-c++ x86_64 4.8.5-44.el7 base 7.2 M
Installing for dependencies:
libstdc++-devel x86_64 4.8.5-44.el7 base 1.5 M
Transaction Summary
=====================================================================================================================================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 8.7 M
Installed size: 25 M
Downloading packages:
(1/2): gcc-c++-4.8.5-44.el7.x86_64.rpm | 7.2 MB 00:00:00
(2/2): libstdc++-devel-4.8.5-44.el7.x86_64.rpm | 1.5 MB 00:00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 24 MB/s | 8.7 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libstdc++-devel-4.8.5-44.el7.x86_64 1/2
Installing : gcc-c++-4.8.5-44.el7.x86_64 2/2
Verifying : gcc-c++-4.8.5-44.el7.x86_64 1/2
Verifying : libstdc++-devel-4.8.5-44.el7.x86_64 2/2
Installed:
gcc-c++.x86_64 0:4.8.5-44.el7
Dependency Installed:
libstdc++-devel.x86_64 0:4.8.5-44.el7
Complete!
如果你执行出现如下报错
[root@lssssswQ base]# yum install -y gcc-c++
CentOS Linux 8 - AppStream 33 B/s | 38 B 00:01
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
错误原因:Centos8于2021年年底停止了服务,大家再在使用yum源安装时候就会出现这个错误
解决办法:更新yum源为阿里镜像
1、进入yum的repos目录
cd /etc/yum.repos.d/
2、修改所有的CentOS文件内容
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
3、更新yum源为阿里镜像
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
yum clean all
yum makecache
至此,完成了yum源的更换,可以接着愉快的安装了
[root@lssssswQ yum.repos.d]# yum install -y gcc-c++
Repository extras is listed more than once in the configuration
Last metadata expiration check: 0:06:00 ago on Fri 19 Aug 2022 05:49:07 PM CST.
Dependencies resolved.
====================================================================================================================================================================================================
Package Architecture Version Repository Size
====================================================================================================================================================================================================
Installing:
gcc-c++ x86_64 8.5.0-4.el8_5 AppStream 12 M
Installing dependencies:
cpp x86_64 8.5.0-4.el8_5 AppStream 10 M
gcc x86_64 8.5.0-4.el8_5 AppStream 23 M
glibc-devel x86_64 2.28-164.el8 base 1.0 M
glibc-headers x86_64 2.28-164.el8 base 480 k
isl x86_64 0.16.1-6.el8 AppStream 841 k
libmpc x86_64 1.1.0-9.1.el8 AppStream 61 k
libstdc++-devel x86_64 8.5.0-4.el8_5 AppStream 2.0 M
libxcrypt-devel x86_64 4.1.1-6.el8 base 25 k
.....省略...........
五、zlib安装
重要程度 ✮✮✮✮
1.下载解压
链接:https://pan.baidu.com/s/1elR6_BTDK0ifNl1NwZC48A
提取码:rmo9
解压到安装目录:/data/base/(我的目录做个举例,请按照自己的需要调整)
tar -zxvf zlib-1.2.11.tar.gz
2.执行./configure
安装包自带的configure配置文件,主要的作用是对即将安装的软件进行配置,检查当前的环境是否满足要安装软件的依赖关系
./configure
[root@localhost zlib-1.2.11]# ./configure
Checking for gcc...
Checking for shared library support...
Building shared library libz.so.1.2.11 with gcc.
Checking for size_t... Yes.
Checking for off64_t... Yes.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.
3.编译安装
make
make install
[root@localhost zlib-1.2.11]# make
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -c -o example.o test/example.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o adler32.o adler32.c
-----------------------------------太多省略--------------------------------------------
minigzip64.o test/minigzip.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o minigzip64 minigzip64.o -L. libz.a
[root@localhost zlib-1.2.11]# make install
rm -f /usr/local/lib/libz.a
cp libz.a /usr/local/lib
-----------------------------------太多省略--------------------------------------------
cp zlib.h zconf.h /usr/local/include
chmod 644 /usr/local/include/zlib.h /usr/local/include/zconf.h
六、pcre安装
重要程度 ✮✮✮
1.下载解压
链接:https://pan.baidu.com/s/1gDtXwuC-6DsOqVv0KVv6mg
提取码:swa3
解压到安装目录:/data/base/(我的目录做个举例,请按照自己的需要调整)
tar -zxvf pcre-8.44.tar.gz
2.执行./configure
安装包自带的configure配置文件,主要的作用是对即将安装的软件进行配置,检查当前的环境是否满足要安装软件的依赖关系
./configure
[root@localhost pcre-8.44]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
省略...
3.编译安装
make
make install
[root@localhost pcre-8.44]# make
rm -f pcre_chartables.c
ln -s ./pcre_chartables.c.dist pcre_chartables.c
make all-am
make[1]: Entering directory `/data/base/pcre-8.44'
CC pcretest-pcretest.o
省略...
[root@localhost pcre-8.44]# make install
make install-am
make[1]: Entering directory `/data/base/pcre-8.44'
make[2]: Entering directory `/data/base/pcre-8.44'
/usr/bin/mkdir -p '/usr/local/lib'
/bin/sh ./libtool --mode=install /usr/bin/install -c libpcre.la libpcreposix.la
省略...
七、Python3环境搭建
重要程度 ✮✮✮✮
1.下载python3
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
2.解压Python-3.6.8.tgz
tar -zxvf Python-3.6.8.tgz
3.执行配置文件,编译,编译安装
cd Python-3.6.8
./configure --prefix=/usr/local/python3
make && make install
4.建立软连接
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3
5.python3环境验证
[root@mini Python-3.6.8]# python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.>>> print("hello world!")
hello world!>>> exit()
[root@mini Python-3.6]# pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
八、Tomcat环境搭建
重要程度 ✮✮✮
1.下载
下载链接:https://pan.baidu.com/s/1_WAlgtbKEZBU4kkTTYLfoA
提取码:t88b
解压到安装目录:/data/base/(我的目录做个举例,请按照自己的需要调整)
tar -zxvf apache-tomcat-9.0.45.tar.gz
2.启动
在tomcat的部署目录bin下启动脚本./startup.sh
[root@localhost bin]# ./startup.sh
Using CATALINA_BASE: /data/base/tomcat
Using CATALINA_HOME: /data/base/tomcat
Using CATALINA_TMPDIR: /data/base/tomcat/temp
Using JRE_HOME: /data/base/jdk
Using CLASSPATH: /data/base/tomcat/bin/bootstrap.jar:/data/base/tomcat/bin/tomcat-juli.jar
Tomcat started.
3.安装验证
浏览器输入localhost:8080,进入tomcat界面