当前位置:网站首页>云服务器上部署仿牛客网项目
云服务器上部署仿牛客网项目
2022-06-30 08:10:00 【Kevin_Opt】
云服务器上部署仿牛客网项目

内存最好有4g,才能跑起来。Nginx起到反向代理的作用,正向代理是代理浏览器,反向代理是代理服务器。Tomcat是用Java开发的,因此安装Tomcat之前要安装JRE;希望在服务器上打包程序,因此安装Maven,如果有环境差异,在windows打包再传过去可能会有问题,因此最好在服务器上打包。真实的生产环境下,一个软件可以部署多个实例,例如Tomcat,MySQL,Redis等。学习中,就部署到一个服务器上。访问Linux虚拟机可以用Putty。
命令行传文件:
pscp 文件名 [email protected]地址:/test
用Bitvise或者Xftp等软件传也行。
下载unzip,先cd到根目录,在用yum搜
cd /
yum list unzip*
yum install -y unzip.x86_64 java-1.8.0-openjdk.x86_64
java -version
安装JRE
注意项目需要JDK12才能运行。
yum list java*
yum install -y
安装Maven
去官网下载3.6.3版本的安装包,下载后安装到/opt目录下
wget -i -c 链接
tar -xzvf apache-maven-3.6.3-bin.tar.gz -C /opt
#配置环境变量到/etc/profile
vim /etc/profile
#在后面追加,保存退出
export PATH=$PATH:/opt/apache-maven-3.6.3
#刷新
source /etc/profile
#打印PATH
echo $PATH
#查看版本
mvn -version
#修改源,进入conf文件夹
vim settings.xml
在mirrors中加入:
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
安装MySQL
这里已经装过了,要安装可以参考另外一篇博客。也可以先去官网下载yum对应的库文件,再用yum安装库文件,就能用yum下载最新的MySQL,安装mysql-community-server.x86_64。
yum install -y 库文件名
启动mysql:
systemctl start mysqld
查看Mysql版本:
mysql -V
查看生成的临时密码:
grep 'password' /var/log/mysqld.log
登录之后,修改密码:
alter user root@localhost identified by '新密码';
给mysql导入数据
unzip -d /test/sql init-sql.zip
登录mysql,执行sql文件
create database community;
use community;
#导入文件
source /test/sql/init_schema.sql;
source /test/sql/init_data.sql;
source /test/sql/tables_mysql_innodb.sql;
show tables;
下面需要把header_url中的localhost的url改成网络能访问到的。
select id,username,header_url from user;
update user set header_url = 'http://images.nowcoder.com/head/492t.png' where header_url like '%localhost%';
安装Redis
cd /
yum list redis*
yum install -y redis.x86_64
systemctl start redis
systemctl status redis
测试redis
redis-cli
keys *
exit
安装kafka
tar -xzvf kafka_2.12-2.3.0.tgz -C /opt
#进入到config文件夹下
vim zookeeper.properties
vim server.properties
基本上只要保存路径符合linux路径规范就行。
先进入kafka安装路径,不要进入bin目录。因为是服务器,需要用后台方式启动。
启动zookeeper
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
启动kafka
nohup bin/kafka-server-start.sh config/server.properties 1>/dev/null 2>&1 &
测试是否成功启动kafka
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
如果显示报错:
关闭tomcat,然后执行上面命令重启,并测试。
shutdown.sh
安装ElasticSearch
tar -xzvf elasticsearch-6.8.23.tar.gz -C /opt
unzip -d /opt/elasticsearch-6.8.23/plugins/ik elasticsearch-analysis-ik-6.8.23.zip
#进入config目录
vim elasticsearch.yml
设置集群名字,数据和日志存放位置:
修改jvm设置,可以根据内存大小设置占用空间
vim jvm.options

ElasticSearch不允许root用户启动,需要创建一个用户,并用这个用户启动
groupadd nowcoder
useradd nowcoder1 -p 设置密码 -g nowcoder
cd /opt
chown -R nowcoder1:nowcoder *
cd /tmp
chown -R nowcoder1:nowcoder *
su - nowcoder1
#进入elasticsearch安装目录后,后台启动ES
bin/elasticsearch -d
su
#测试是否安装成功
curl -X GET "localhost:9200/_cat/health?v"
Wkhtmltopdf
cd /
yum list wkhtmlyopdf*
yum install -y wkhtmltopdf.x86_64
需要gui支持,安装虚拟gui程序
yum install -y xorg-x11-server-Xvfb.x86_64
#测试
xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltoimage https://www.baidu.com 1.png
每次都这样写命令很麻烦,因此可以包装一下
cd /opt
vim wkhtmltoimage.sh
#添加
xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltoimage "[email protected]"
chmod +x wkhtmltoimage.sh
cd /test
/opt/wkhtmltoimage.sh https://www.baidu.com 2.png
安装tomcat
tar -xzvf apache-tomcat-9.0.64.tar.gz -C /opt
vim /etc/profile
#在后面追加
export PATH=$PATH:/opt/apache-tomcat-9.0.64/bin
source /etc/profile
echo $PATH
启动tomcat
startup.sh
安装nginx
yum list nginx*
yum install -y nginx.x86_64
vim /etc/nginx/nginx.conf
把这一段注释掉
在这段后面加上:
upstream myserver {
server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name 49.232.164.108;
location / {
proxy_pass http://myserver;
}
}
启动nginx
systemctl start nginx
部署代码
由于没有处理根路径,因此访问/时要等价与访问/index,一个方法是访问/时重定向到/index,另外一个方法
可以把webapps中的都删去,再加上自己的项目。
对代码进行调整:
1、在application.properties中把/community改成空。
2、在global.js中把/community改成空
3、在HomeController中加上
@RequestMapping(path = "/", method = RequestMethod.GET)
public String root(){
return "forward:/index";
}
4、在pom.xml中修改打包方式和打包名字

5、通过设置,选定使用哪个配置文件,并且修改相应项
修改成服务器ip
6、tomcat本身有main函数,一个Java程序不可能有两个main函数,因此重写方法
重建CommunityServletInitializer类,继承SpringBootServletInitializer,重写方法:
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(CommunityApplication.class);
}
tomcat从这个类访问。
使用maven的clean把target删除,并传送整个项目文件到云服务器。
unzip -d /test community.zip
#第一次下载maven并执行打包,会下载相关依赖,需要一些时间
#进入community中打包
mvn package -Dmaven.test.skip=true
如果出现报错:[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
yum install java-devel
再复制到tomcat中:
mv ROOT.war /opt/apache-tomcat-9.0.64/webapps/
linux区分大小写,先登录MySQL数据库
show variables like '%case%';
vim /etc/my.cnf
#加上
lower_case_table_names=1
#重启
service mysqld restart
这个对于mysql8不行。手动修改表名为大写。
边栏推荐
- Sword finger offer II 074 Merge interval (sort, array)
- Introduction to opencv (II): image color space conversion and image saving
- [notes] polygon mesh processing learning notes (10)
- Emoji icons supported by markdown
- At the end of June, you can start to make preparations, otherwise you won't have a share in such a profitable industry
- Unity 基础光照模型
- Go 数据类型篇之字符串及底层字符类型
- Dlib database face
- 1. Problems related to OpenGL window and environment configuration
- [tensorflow GPU] building of deep learning environment under windows11
猜你喜欢

Sword finger offer II 076 The kth largest number in the array (use heap to solve TOPK problem)

What management improvements can CRM bring to enterprises

Final review -php learning notes 2-php language foundation

Redis 的过期数据如何处理,淘汰机制都有那些?

vulfocus入门靶机

Deep learning - brnn and DRNN

How to handle the expired data of redis and what are the elimination mechanisms?

【NVMe2.0b 14-5】Firmware Download/Commit command

Palindrome substring, palindrome subsequence

Full stack performance testing theory - Summary
随机推荐
Deep learning - goal orientation
C. Fishingprince Plays With Array
Deep learning - embedding matrix and learning word embedding andword2vec
1. Problems related to OpenGL window and environment configuration
电流探头电路分析
领域驱动下cloud项目中单个服务的示例
CRM&PM如何帮助企业创造最优销售绩效
Opencv image
MySQL cannot connect to the intranet database
JS代码案例
Camera
想问问,炒股怎么选择证券公司?网上开户安全么?
Deep learning -- using word embedding and word embedding features
Vulfocus entry target
This point in JS
At the end of June, you can start to make preparations, otherwise you won't have a share in such a profitable industry
Why don't you know what to do after graduation from university?
Dlib library blink
Graffiti Wi Fi & ble SoC development slide strip
Summary and common applications of direction and angle operators in Halcon