目录
安装jdk?
安装MySQL?
安装tomcat服务器
安装Nginx反向代理服务器
首先,你得有一个云服务器——随便买一个
以Centos镜像进行说明,做个笔记,所有资源
安装jdk?
这里安装jdk11(资源一)?
在usr/local目录下创建jdk文件夹
将jdk-11.0.14_linux-x64_bin.tar.gz传输到jdk目录下,解压到当前目录
tar -zxvf jdk-11.0.14_linux-x64_bin.tar.gz
配置环境变量
[root@VM-12-8-centos jdk]# vim /etc/profile
。。。。。
if [ -n "${BASH_VERSION-}" ] ; then
if [ -f /etc/bashrc ] ; then
# Bash login shells run only /etc/profile
# Bash non-login shells run only /etc/bashrc
# Check for double sourcing is done in /etc/bashrc.
. /etc/bashrc
fi
fi
//末尾添加
export JAVA_HOME=/usr/local/jdk/jdk-11.0.14
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
"/etc/profile" 89L, 2211C
:wq保存退出后,让其生效
[root@VM-12-8-centos jdk]# source /etc/profile
安装MySQL?
这里安装mysql8.0.29(资源二)
在usr/local目录下创建mysql文件夹
将mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz传输到mysql文件夹下,解压到当前目录
tar xvf mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz
?
?修改目录名
mv mysql-8.0.29-linux-glibc2.12-x86_64 mysql8.0.29
?在目录下创建data文件夹
cd mysql8.0.29/
mkdir data
创建mysql用户,并赋权
groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql /usr/local/mysql/mysql8.0.29
进入bin目录,初始化mysql
cd bin/
./mysqld --user=mysql --basedir=/usr/local/mysql/mysql8.0.29 --datadir=/usr/local/mysql/mysql8.0.29/data/ --initialize
运行结果如下,里面有密码,保存好密码:
[root@VM-12-8-centos bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql/mysql8.0.29 --datadir=/usr/local/mysql/mysql8.0.29/data/ --initialize
2022-05-18T03:17:38.004698Z 0 [System] [MY-013169] [Server] /usr/local/mysql/mysql8.0.29/bin/mysqld (mysqld 8.0.29) initializing of server in progress as process 22024
2022-05-18T03:17:38.021352Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-05-18T03:17:39.300600Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-05-18T03:17:41.163199Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: szhdqpAKo1--
接下来,编辑配置文件
vi /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql/mysql8.0.29
datadir=/usr/local/mysql/mysql8.0.29/data/
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
保存退出后,返回上一级至安装目录下,将mysql添加到服务
cd ..
cp -a ./support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
service mysql start
service mysql status
ln -sf /usr/local/mysql/mysql8.0.29/bin/mysql /usr/bin
登录mysql
mysql -u root -p
若出现错误
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
输入
sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
输入密码,密码为初始化时的密码
进入后,重置密码,设置你想要的密码,并让其生效
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;
设置远程连接
use mysql;
update user set host='%' where user='root';
flush privileges;
开放3306端口,可以让我们通过网络连接到
firewall-cmd --add-port=3306/tcp --permanent
若出现FirewalID is not running,把你的防火墙开开
systemctl start firewalld.service
systemctl enable firewalld.service
开放端口,让其生效
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload
?然后,在你的安全组,或者是防火墙中开放这个端口
?用数据库工具,我用的DBeaver,连接测试一下,通过就可以正常使用了。(资源三)
安装tomcat服务器
这里安装tomcat9.0.63(资源四)
在usr/local目录下创建tomcat文件夹
将apache-tomcat-9.0.63.tar.gz传输到tomcat文件夹下,解压到当前目录
tar -zxvf apache-tomcat-9.0.63.tar.gz
修改目录名
mv apache-tomcat-9.0.63 tomcat9.0.63
配置环境变量
vi /etc/profile
在末尾加上
export CATALINA_HOME=/usr/local/tomcat/tomcat9.0.63
export CATALINA_BASE=/usr/local/tomcat/tomcat9.0.63
export PATH=$PATH:$CATALINA_BASE/bin
export PATH CATALINA_BASE
:wq保存推出
让其生效
source /etc/profile
进入到tomcat的配置文件中,修改tomcat的启动端口
cd /usr/loacl/tomcat/tomcat9.0.63/conf/
vi server.xml
将端口号暂时改为80
?防火墙开放80端口
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
回到bin目录,启动tomcat
./startup.sh
这个时候打开网页,输入ip即可看到tomcat欢迎界面
成功之后,最好把端口换回8080?
安装Nginx反向代理服务器
这里安装nginx1.21.6(资源五)
在usr/local目录下创建nginx1.21.6文件夹
将nginx-1.21.6.tar.gz传输到nginx1.21.6文件夹下,解压到当前目录
tar zxvf nginx-1.21.6.tar.gz
??
进入目录,采用编译安装
cd nginx-1.21.6/
./configure --prefix=/usr/local/nginx
运行结束后,可以看到所缺依赖
?常见的缺少安装
yum install -y gcc
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
安装完成后,重新执行编译安装
接下来执行
make
make install
进入usr/local就可以看到nginx已经安装成功
为nginx创建服务脚本
vi /usr/lib/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
使用脚本启动nginx,启动之前先杀死所有占用80端口的进程
lsof -i :80
kill -9 PID
systemctl start nginx
这个时候打开网页,输入ip即可看到nginx欢迎界面
每次产生修改后,需要重新加载nginx
systemctl reload nginx
使用nginx代理tomcat,tomcat端口已改为8080,以下是常见的配置
worker_processes 1;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#upstream httpds {
# server 192.168.83.102:80 weight=8 ;
# server 192.168.83.103:80 weight=2 ;
# server 192.168.83.104:80 weight=1 backup;
#}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8080;
}
location /public {
root html;
index index.html index.htm;
}
location /static {
root html;
index index.html index.htm;
}
location /logo.ico {
root html;
index index.html index.htm;
}
location /pdf {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
配置完后,重新加载下nginx
systemctl reload nginx
此时打开页面,已变为tomcat欢迎页面?
|