码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx(一):安装与常用命令

时间:2020-04-04 22:17:41      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:from   inf   shell   error   一个   三方   main   cti   tar   

简介

??Nginx ("engine x") 是一个高性能的 HTTP 和反向代理服务器,特点是占有内存少,并发能 力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,在高连接并发的情况下,Nginx是Apache服务器不错的替代品。中国大陆使用nginx 网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。

安装

初次安装

[root@localhost ~]# yum install -y nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
No package nginx available.
Error: Nothing to do

原因是nginx位于第三方的yum源里面,而不在centos官方yum源里面

解决方案

#使用 yum-config-manager 软件包命令
[root@localhost ~]# yum install -y yum-utils
#安装wget
[root@localhost ~]#yum install -y wget
#切换到repo配置文件目录
[root@localhost ~]# cd /etc/yum.repos.d/
#备份CentOs-Base.repo源文件
[root@localhost yum.repos.d]# mv CentOs-Base.repo CentOs-Base.repo.bak
#网络下载centos官方和扩展.repo文件
[root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
#安装epel-release
[root@localhost yum.repos.d]# yum install -y epel-release
[root@localhost yum.repos.d]#mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
[root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/repo/epel-7.repo
#清理软件源缓存
[root@localhost yum.repos.d]# yum clean all
#重建缓存
[root@localhost yum.repos.d]# yum makecache
#可选选项,更新系统 可选操作
[root@localhost yum.repos.d]# yum update
# 也可以使用yum-config-manager --add-repo 命令。进行以下操作推荐备份原.repo文件。yum-config-manager命令必要条件: yum install -y yum-utils
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/repo/epel-7.repo

二次安装

[root@localhost ~]# yum install -y nginx
[root@localhost ~]# find / -name ‘nginx‘
/etc/logrotate.d/nginx
/etc/nginx
/var/lib/nginx
/var/log/nginx
/usr/sbin/nginx
/usr/lib64/perl5/vendor_perl/auto/nginx
/usr/lib64/nginx
/usr/share/nginx

校验

# 启动
[root@localhost ~]# cd /usr/sbin/
[root@localhost sbin]# ./nginx 
# 查看状态
[root@localhost sbin]# ps -ef|grep nginx
root      40783      1  0 21:25 ?        00:00:00 nginx: master process ./nginx
nginx     40784  40783  0 21:25 ?        00:00:00 nginx: worker process
nginx     40785  40783  0 21:25 ?        00:00:00 nginx: worker process
nginx     40786  40783  0 21:25 ?        00:00:00 nginx: worker process
nginx     40787  40783  0 21:25 ?        00:00:00 nginx: worker process

技术图片

停止

[root@localhost sbin]# ./nginx -s stop

重载

[root@localhost sbin]# ./nginx -s reload
# 重载指定配置文件
[root@localhost sbin]# ./nginx -s reload -c /etc/nginx/nginx.conf

第二种启动方式

# 启动
[root@localhost ~]# systemctl start nginx
# 查看状态
[root@localhost ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-04-04 21:52:43 CST; 50s ago
  Process: 42188 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 42185 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 42183 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 42191 (nginx)
   CGroup: /system.slice/nginx.service
           ├─42191 nginx: master process /usr/sbin/nginx
           ├─42192 nginx: worker process
           ├─42193 nginx: worker process
           ├─42194 nginx: worker process
           └─42195 nginx: worker process

Apr 04 21:52:43 localhost systemd[1]: Starting The nginx HTTP and reverse proxy server...
Apr 04 21:52:43 localhost nginx[42185]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Apr 04 21:52:43 localhost nginx[42185]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Apr 04 21:52:43 localhost systemd[1]: Started The nginx HTTP and reverse proxy server.
# 停止
[root@localhost ~]# systemctl stop nginx
[root@localhost ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Apr 04 21:48:37 localhost nginx[41953]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Apr 04 21:48:37 localhost systemd[1]: Started The nginx HTTP and reverse proxy server.
Apr 04 21:49:40 localhost systemd[1]: Stopping The nginx HTTP and reverse proxy server...
Apr 04 21:49:40 localhost systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Apr 04 21:52:43 localhost systemd[1]: Starting The nginx HTTP and reverse proxy server...
Apr 04 21:52:43 localhost nginx[42185]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Apr 04 21:52:43 localhost nginx[42185]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Apr 04 21:52:43 localhost systemd[1]: Started The nginx HTTP and reverse proxy server.
Apr 04 21:54:12 localhost systemd[1]: Stopping The nginx HTTP and reverse proxy server...
Apr 04 21:54:12 localhost systemd[1]: Stopped The nginx HTTP and reverse proxy server.

Nginx(一):安装与常用命令

标签:from   inf   shell   error   一个   三方   main   cti   tar   

原文地址:https://www.cnblogs.com/chinda/p/12634634.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!