Featured image of post VPS开箱

VPS开箱

搬瓦工VPS折腾记

前端时间购买了Banwagong提供位于洛杉矶的服务器,也算是部署得差不多了,总结一下过程。

准备

下载Termius

VPS安装Nginx

使用Termius连接到VPS主机

安装GCC与dev库

1
2
3
4
5
6
7
8
yum update -y # 更新包信息

yum upgrade -y # 更新包

yum install gcc gcc-c++ \ 
pcre pcre-devel \
zlib zlib-devel \
openssl openssl-devel 

下载Nginx源码

我这里使用的是/opt目录,可以根据需要更改为指定的目录,使用
wget -o nginx.tar.gz http://nginx.org/download/nginx-{version}.tar.gz
对源码进行下载

执行configure

为了方便了解部分选项含义,注明了用到的参数及其含义:

表头表头
–prefix=PATHNginx安装的路径
–sbin-path=PATH指定Nginx二进制文件路径,默认和prefix关联
–conf-path=PATHconfig文件路径
–error-log-pah=PATH错误日志路径
–pid-path=PATH存储master的进程号
–http-client-body-temp-path客户端请求临时位置
–http-proxy-temp-path代理文件临时文件目录
–user=USERworker进程运行的用户
–group=GROUPworker进程运行的用户组
–with-file-aio启用异步I/O
–with-threads开启线程池
–with-http_addition_module在response前后追加内容
–with-http_auth_request_module判断子请求是否为2xx状态码
–with-http_mp4_module支持mp4视频流
–with-http_realip_module获取反向代理的真实IP
–with-http_secure_link_module检查链接是否真实有效
–with-http_slice_module将请求拆分为子请求
–with-http_ssl_module启用https支持
–with-http_sub_module替换response数据
–with-http_v2_module启用http2支持
–with-stream四层TCP/UDP协议的转发、代理、负载均衡
–with-stream_realip_module获取stream转发的真实ip
–with-stream_ssl_modulestream开启https支持
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--config-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_mp4_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_v2_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module

执行安装&配置系统服务

1
make &$ make install

/usr/lib/systemd/system下新建nginx.service,文件内容:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
[Unit]
Description=Nginx A web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStartPost=/bin/sleep 1
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

使用systemctl status nginx查看服务状态,检查是否有错误。如果出现Failed to start Startup script for nginx service使用fuser -k 80/tcp && fuser -k 443/tcp杀死占用端口的进程。

systemctl enable nginx开启服务开机自启动,systemctl start nginx开启服务。

访问IP地址,正常会出现如下结果:

OK

至此VPS就开箱好了。

引申: Nginx的优点

高扩展性:由不同模块组成,可以对单一模块进行修改或升级,专注于模块自身。
高可靠性:采用master+worker的进程模型,worker进程间相对独立,可以快速拉起worker进程。
热部署:得益于Nginx优秀的进程模型设计,Nginx可以不停机就更新配置项,命令:nginx -signal

Licensed under CC BY-NC-SA 4.0
最后更新于 Sep 14, 2022 19:30 UTC
comments powered by Disqus
Built with Hugo
主题 StackJimmy 设计