首页 > 数据库 >Linux 虚拟机环境安装(jdk/mysql/redis/tomcat/nginx/挂载)

Linux 虚拟机环境安装(jdk/mysql/redis/tomcat/nginx/挂载)

时间:2024-12-31 20:52:26浏览次数:5  
标签:tomcat jdk ----------------------------------------------------------------- 虚拟机


=================================================================  
准备工作
=================================================================
yum install wget
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
yum install chkconfig
yum install vim
yum install net-tools

yum -y install pcre-devel
yum -y install openssl openssl-devel

yum install open-vm-tools open-vm-tools-desktop
=================================================================  
1、安装JDK(以jdk-8u431-linux-x64.tar.gz为例)
================================================================= 
cd /usr/local
mkdir jdk
cd jdk
tar -xzvf jdk-8u431-linux-x64.tar.gz
将解压后文件夹重命名为jdk1.8.0_431

#配置环境变量
vi /etc/profile
-----------------------------------------------------------------
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_431
export PATH=$JAVA_HOME/bin:$PATH
-----------------------------------------------------------------
source /etc/profile
java -version

=================================================================  
2、安装mysql(以mysql-8.0.39-linux-glibc2.28-x86_64.tar.xz为例)
================================================================= 
cd /usr/local
mkdir mysql
cd mysql
tar -xvf mysql-8.0.39-linux-glibc2.28-x86_64.tar.xz
将解压后文件夹重命名为mysql8.0.39

#添加命令路径到系统中
vi /etc/profile
-----------------------------------------------------------------
export PATH=$PATH:/usr/local/mysql/mysql8.0.39/bin
export PATH=$PATH:/usr/local/mysql/mysql8.0.39/support-files
-----------------------------------------------------------------
source /etc/profile

#创建用户
groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql /usr/local/mysql/mysql8.0.39

cd bin
./mysqld --user=mysql --basedir=/usr/local/mysql/mysql8.0.39 --datadir=/usr/local/mysql/mysql8.0.39/data/ --initialize
*得到并记录root临时密码 yYjHjAmBh7#p

#创建data文件夹 存储文件
#mkdir /usr/local/mysql/mysql8.0.39/data
#编辑my.cnf文件
vi /etc/my.cnf
-----------------------------------------------------------------
[mysqld]
basedir=/usr/local/mysql/mysql8.0.39/
datadir=/usr/local/mysql/mysql8.0.39/data/
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
-----------------------------------------------------------------
#添加mysqld服务到系统
cp -a ../support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
service mysqld status

#将mysql命令添加到服务
#ln -s /usr/local/mysql/mysql8.0.39/bin/mysql /usr/bin

#登录mysql
mysql -uroot -p
输入临时密码

#修改root账号密码为123456
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
mysql> flush privileges;

#修改远程连接并生效
#mysql> update user set host='%' where user='root';
#mysql> flush privileges;
-----------------------------------------------------------------
------------------------mysqld开机自启动-------------------------
-----------------------------------------------------------------
chkconfig --level 345 mysqld on
chkconfig --list
reboot

================================================================= 
3、安装redis(以redis-6.2.6.tar.gz为例)
================================================================= 
cd /usr/local
mkdir redis
cd redis
tar -xzvf redis-6.2.6.tar.gz
将解压后文件夹重命名为redis6.2.6

cd /usr/local/redis/redis6.2.6
make
make PREFIX=/usr/local/redis/redis6.2.6 install
-----------------------------------------------------------------
#将redis.conf文件 移动到/usr/local/redis/redis6.2.6/bin目录下
cp ./redis.conf /usr/local/redis/redis6.2.6/bin/
cd bin
#备份
cp redis.conf redis.conf.bak
#支持外网访问daemonize修改为yes
vim redis.conf
-----------------------------------------------------------------
./redis-server redis.conf
./redis-cli -p 6379
ps -aux|grep redis
netstat -lanp|grep 6379
netstat -tnap
#关闭redis
./redis-cli shutdown
-----------------------------------------------------------------
------------------------redis开机自启动--------------------------
-----------------------------------------------------------------
vi /etc/systemd/system/redis.service
-----------------------------------------------------------------
[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
# 这行配置内容要根据redis的安装目录自定义路径
ExecStart=/usr/local/redis/redis6.2.6/bin/redis-server /usr/local/redis/redis6.2.6/bin/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target
-----------------------------------------------------------------
systemctl daemon-reload
systemctl start redis
systemctl status redis
systemctl enable redis
reboot

================================================================= 
4、安装tomcat(以apache-tomcat-9.0.98.tar.gz为例)
================================================================= 
cd /usr/local
mkdir tomcat
cd tomcat
tar -xzvf apache-tomcat-9.0.98.tar.gz
将解压后文件夹重命名为tomcat9.0.98

#为server.xml文件添加参数配置 useBodyEncodingForURI="true" URIEncoding="UTF-8"
cd tomcat9.0.98/conf
#备份
cp server.xml server.xml.bak
vi server.xml
-----------------------------------------------------------------
------------------------tomcat开机自启动-------------------------
-----------------------------------------------------------------
vi /etc/systemd/system/tomcat.service
-----------------------------------------------------------------
[Unit]
Description=Tomcat Server
After=network.target

[Service]
Type=forking
Environment="JAVA_HOME=/usr/local/jdk/jdk1.8.0_431"
ExecStart=/bin/bash /usr/local/tomcat/tomcat9.0.98/bin/startup.sh
ExecStop=/usr/local/tomcat/tomcat9.0.98/bin/shutdown.sh
User=root
Group=root

[Install]
WantedBy=multi-user.target
-----------------------------------------------------------------
systemctl daemon-reload
systemctl start tomcat
systemctl status tomcat
systemctl enable tomcat
reboot

================================================================= 
5、安装nginx(以nginx-1.26.2.tar.gz为例) https://www.cnblogs.com/orangebooks/p/12058830.html
================================================================= 
cd /usr/local
#这里不在/usr/local/下创建nginx文件夹原因是 后续nginx安装默认位置即/usr/local/nginx
mkdir java
cd java
tar -xzvf nginx-1.26.2.tar.gz
将解压后文件夹重命名为nginx1.26.2

#进入Nginx的根目录执行 ./configure 命令
cd nginx1.26.2
./configure
make && make install
编译安装完后,在 /usr/local/ 目录下会自动生成一个 nginx 目录,代表安装成功!
-----------------------------------------------------------------
#nginx常用命令
cd /usr/local/nginx/sbin      首先进入 sbin 目录
./nginx                       启动 Nginx
./nginx -s stop               停止 Nginx
./nginx -s reload             重新加载 Nginx
./nginx -v                    查看 Nginx 版本
#firewall常用命令
firewall-cmd --zone=public --add-port=80/tcp --permanent        开放80端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent      开放8080端口
firewall-cmd --zone=public --remove-port=8080/tcp --permanent   关闭8080端口
firewall-cmd --reload                                           更新配置信息(这样就不需要重启防火墙了)
firewall-cmd --list-ports                                       查看开放的端口
systemctl list-unit-files | grep enabled                        查看所有开机自启的服务
-----------------------------------------------------------------
#虚拟机/Windows域名 模拟DNS;分别给linux和windows 配置hosts
参考资料:https://blog.csdn.net/The_SkyUzi/article/details/144689350
192.168.119.128 test.xiaoming.com
192.168.119.128 api.example.com
192.168.119.128 admin.example.com

C:\Windows\System32\drivers\etc\hosts
vi /etc/hosts
-----------------------------------------------------------------
------------------------nginx开机自启动--------------------------
-----------------------------------------------------------------
vi /etc/systemd/system/nginx.service
-----------------------------------------------------------------
[Unit]
Description=nginx -  web server
After=network.target remote-fs.target nss-lookup.target
  
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target
-----------------------------------------------------------------
systemctl daemon-reload
systemctl start nginx
systemctl status nginx
systemctl enable nginx
reboot

================================================================= 
6、其他
================================================================= 
#关闭mysqld服务
service mysqld stop
#关闭redis服务
systemctl stop redis
#关闭tomcat服务
systemctl stop tomcat
#关闭nginx服务
systemctl stop nginx
#查看虚拟机已启服务
netstat -tnap

================================================================= 
7、VMware挂载本地Windows系统目录 https://www.cnblogs.com/pxblog/p/16972620.html
================================================================= 
centos
编辑虚拟机设置-->选项-->共享文件夹 选择 总是启动-->选择共享文件夹

#查看当前虚拟机配置的挂载名称
vmware-hgfsclient
#将挂载名称share挂载到linux服务器 /var/www/share/ 文件夹上
mkdir -p /var/www/share
vmhgfs-fuse .host:/share /var/www/share/ -o allow_other
-----------------------------------------------------------------
-----------------vmhgfs-fuse挂载开机自启动-----------------------
-----------------------------------------------------------------
vim /etc/rc.d/rc.local
#添加执行命令
vmhgfs-fuse .host:/share /var/www/share/ -o allow_other
#添加权限
chmod +x /etc/rc.d/rc.local
#测试是否生效
sudo /etc/rc.local
-----------------------------------------------------------------

#查看开机自启动service
systemctl list-units --type=service

 

标签:tomcat,jdk,-----------------------------------------------------------------,虚拟机
From: https://www.cnblogs.com/huakaiyoushi/p/18644768

相关文章

  • Docker技术相对于虚拟机技术的优劣势对比!
    成长路上不孤单......
  • Linux上安装jdk
    在线环境的话,通过命令下载,离线环境的话,组要自行去oracle官网下载后上传wget--no-check-certificate--no-cookies--header"Cookie:oraclelicense=accept-securebackup-cookie"http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa8016......
  • 安装虚拟机设置
    在Windows10上安装虚拟机需要进行一些特定的设置,以确保虚拟机能够正常运行。以下是详细的步骤和注意事项:1.启用虚拟化支持虚拟化是运行虚拟机的基础,需要确保你的CPU支持虚拟化,并且在BIOS/UEFI中启用它。检查CPU虚拟化支持打开任务管理器(按 Ctrl+Shift+Esc)。切换到“......
  • windows如何安装JDK8?附安装包
    前言大家好,我是小徐啊。我们在开发Java的时候,第一步就是需要安装JDK,今天,小徐来介绍下Java开发中,最流行的JDK8的安装方式。文末附获取方式。如何安装JDK8首先,双击JDK8的安装包,开始安装。然后,会弹出JavaSE8的一些说明,查看一下,然后点击下一步按钮即可。然后,我们需要选择要安......
  • centos6虚拟机异常关闭,启动网络报错device eth0 does not seem to be present,delayin
    centos6虚拟机所在主机直接关机,导致虚拟机异常关闭,启动虚拟机网络报错deviceeth0doesnotseemtobepresent,delayingnitialization1、查看虚拟机的mac地址 2、修改eth0的mac地址修改完成后查看文件内容,more/etc/sysconfig/network-scripts/ifcfg-eth0  3、修改70-......
  • 解决在虚拟机中安装Jupyter Notebook,无法从宿主机防问的问题
    解决方案:主要原因是JupyterNotebook默认绑定到127.0.0.1了默认情况下,JupyterNotebook仅监听127.0.0.1(本地主机),只能在虚拟机内部访问。解决方法:修改JupyterNotebook的启动方式,使其监听虚拟机的网络接口。修改启动命令:jupyternotebook--allow-root--ip=0.0.0.0......
  • 【详解】解决Eclipse发布到Tomcat丢失依赖jar包的问题
    目录解决Eclipse发布到Tomcat丢失依赖jar包的问题问题原因解决方案自动化构建考虑结论代码概述代码的基本组成示例代码(Python)解决Eclipse发布到Tomcat丢失依赖jar包的问题在Web开发过程中,使用Eclipse作为IDE并将项目发布到Tomcat服务器上是常见的操作。然而,有时在......
  • 折腾笔记[3]-迁移U盘的ubuntu到虚拟机
    摘要使用clonezilla工具迁移安装到U盘中的ubuntu18.04系统到vmware虚拟机.关键信息clonezillaubuntu18.04cpu:x86_64vmware:17.6.0ubuntu引导方式:UEFI+GRUB2windows11原理简介clonezilla简介[https://clonezilla.org/][https://linux.cn/article-3888-1.html]再......
  • 尝试 vmware 16.0.0 过虚拟化 过xf虚拟机检测
    前言最新想在vmware虚拟机上玩xf,网上找了不少教程,于是打算自己尝试下。如果可以修改成功的话,其价值嘛不可估量。环境vmware版本是16.0.0,已安装VMwareToolsvmware版本是16.1.2,已安装VMwareTools虚拟镜像cn_windows_7_professional_with_sp1_vl_build_x64_dvd_u_677816回......
  • windows与虚拟机linux通过ssh进行连接并上传文件
    windows与虚拟机linux通过ssh进行连接并上传文件windows配置以管理员打开powershell下载和启动安装ssh客服端Add-WindowsCapability-Online-NameOpenSSH.Server~~~~0.0.1.0Add-WindowsCapability-Online-NameOpenSSH.Client~~~~0.0.1.0Start-ServicesshdSet-Servic......