在没有接触服务器之前,一直以为服务器是个高大上的东西。
刚开始作为一个纯小白,不怕诸位笑话,就连接windows服务器都不会,还没有琢磨明白windows服务器,公司已经开始使用Linux服务器,所幸身处资源共享的年代,很多好的学习资料对我的帮助很大。
这里感谢各位大佬的技术分享。
由于很久没有配置服务器环境,刚好遇到腾讯云服务器有活动,便入手一台练练手,进行Linux服务器配置,这里做一个记录。
首先,花巨资70元大钞购买的轻量级服务器,必须安排上炫下配置,放两三个网站页面妥妥没问题,要用自身稳稳的土豪气质闪亮诸位的大眼。
一.修改服务器密码
1.找到服务器的实例 -> 选择更多
2.选择管理
3.选择重置密码
4.进行密码重置
二.连接服务器
1.进入Xshell 7
文件 -> 新建会话
名称:根据自身需求写。
主机:服务器的IP
然后选择连接
输入登录用户
输入登录密码,然后确定。
2.连接成功之后的提示
三.静态页面的Nginx环境配置
1.手动配置Nginx
1.配置Nginx代理
进入nginx网站: nginx.org/en/download…
点击中间的版本就是Linux
下载完成之后,使用Xftp进行上传
这里我先找到Home, 使用 mkdir 创建目录,用来存放压缩文件。
上传成功之后,ls 查看下文件
开始解压文件:
执行Linux命令: tar -zxvf nginx-1.20.2.tar.gz
安装成功之后进入目录查看
配置configure: ./configure 自动配置
执行的时候报错:
./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre= option.
安装pcre-devel解决问题
执行命令:yum -y install pcre-devel
安装好pcre-devel之后,再次 ./configure 成功了
如果报错是:make: *** No rule to make target build', needed by default'. Stop.
-
安装下面配置 yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel
-
验证
./configure
configure成功之后,make下。(编译 make的过程是把各种语言写的源码文件,变成可执行文件和各种库文件)
稳妥一步执行下安装 make install
Nginx安装成功后,修改端口号和启动
执行:whereis nginx 找到nginx的位置
cd /usr/local/nginx
执行 ll 查看
端口号的配置再conf中
cd conf/ 进入conf文件中 找到nginx.conf配置文件
使用cat nginx.conf 查看文件
这里我将文件传输到桌面查看。
配置中默认是80端口,我改成8081.
改好后替换原来的文件,同时再腾讯云的防护墙开放端口,阿里云在安全组开放端口
开始启动nginx
cd sbin
执行 nginx
./nginx
IP:8081 端口号,成功打开就行了
可以开始正式部署官网了:
开始为了测试,所以将80改为8081,现在改回:80
location / {
root /home/guanWang/fxgyPC;
index index.html;
}
/home/guanWang/fxgyPC 是项目所在的位置(一般新建一个文件夹存放项目)
修改完之后重新替换nginx.conf文件。
先关闭已开启的nginx:
查看运行的进程 ps -ef|grep nginx
关闭进程:kill -9 53614
然后重新启动 ./nginx
浏览器打开网站,这里的域名已经解析到服务器上了,所以直接打开就行。
注:不要打开这个网址,部署成功之后就删除解析,看不到页面。
如果要部署多个二级域名
server_name 对应域名
location / { root /home/guanWang/web/fxgyPC; index index.html; }
root 对应项目地址
server {
listen 80;
server_name ap.lemonforever.top;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/guanWang/web/fxgyPC;
index index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
四.宝塔部署网站
选择Linux面板
点击立即安装会出现对应的命令
我这里选择: yum install -y wget && wget -O install.sh download.bt.cn/install/ins… && sh install.sh
成功之后会给你访问地址,账号,密码。
登录之前一定要在腾讯云或阿里云开启宝塔的默认端口号:8888
进入之后需要简单的注册下,就可以使用了
找到软件商店,选择需要安装的东西
找到apache,进行安装
选择需要的版本和安装方式。
进入安装
安装成功
找到网站 添加站点
输入域名信息
将代码内容进行上传
打开成功
五.静态页面的tomcat环境配置
进入tomcat官网:tomcat.apache.org/
选择对应版本进入,下载对应系统的tomcat
我这里下载的是8.5版本
通过Xftp将包输入到目录下
解压 apache-tomcat-9.0.8.tar.gz
执行命令:tar -zxvf apache-tomcat-9.0.8.tar.gz
进入解压好的tomcat文件中,进行配置。
找到conf里的server文件
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
prot改为80
修改域名配置
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
将name="localhost" 换成 name="www.lemonforever.top"
加入
docBase="/home/GuanWang/apache-tomcat-8.5.63/webapps/ce" 是项目所在的地址
添加二级域名配置
<!--二级域名ap.lemonforever.top-->
<Host name="ap.lemonforever.top" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="/home/GuanWang/apache-tomcat-8.5.63/webapps/fxgyPC" debug="0" reloadable="true" />
</Host>
docBase="/home/GuanWang/apache-tomcat-8.5.63/webapps/fxgyPC"是项目所在的地址
项目放在apache-tomcat-8.5.63 中的webapps 文件中
修改完替换原来的配置文件
现在开启tomcat,试试网站是否可以打开
进入bin文件下
./startup.sh
报错了: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program
没有安装JDK,找不到环境变量,所以无法启动.
这里说明下,有人跟我说运行tomcat,不需要jdk。所以这里就顺便实践下,事实说明要装jdk。
下面开始安装jdk
传入jdk-8u271-linux-x64.rpm
检测JDK版本信息 rpm -ga|grep jdk
有就卸载,重新装。
卸载命令: rpm -e --nodeps jdk_版本号
新的服务器没有我这里就直接安装了
rpm -ivh jdk-8u271-linux-x64.rpm
安装完毕之后检测是否成功
java -version
安装好之后进行环境配置
进入etc目录 找到profile文件。
我这里的习惯还是导出来,在编译器中修改,方便。
加入以下配置
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_181 (注意:jdk1.8.0_271-amd64安装的目录在 /usr/java) export PATH=PATH
重新加载配置文件
命令 source /etc/profile
java -version
如果出现版本号证明环境配置成功
下面就是开启tomcat
./startup.sh
开启成功,打开页面瞅瞅
再次提醒,成功之后就删除配置了,网站打不开。
有不对的地方欢迎大佬们指正,后面会记录下有后端的环境配置。