SUSE Linux 15 sp5上Nginx安装&配置&升级

1.安装SUSE linux 15 SP5
图形化界面安装很简单,选择最小安装,安装好后,使用vim编辑配置文件,结果提示"bash: vim: command not found"。
最简安装把一些常用命令都整没有了,于是又重新选择了Server Applications Module 和 Web and scripting Module安装。
终于可以使用vim命令了,继续往下操作。
安装时没有设置IP地址,/etc/sysconfig/network下没有找到生成的ifcfg-eth0,于是用yast设置IP和网关


2.安装Nginx
localhost:/etc/sysconfig/network # zypper search nginx
Loading repository data...
Reading installed packages...
S | Name             | Summary                                                     | Type
--+------------------+-------------------------------------------------------------+--------
  | dehydrated-nginx | Nginx Integration for dehydrated                            | package
  | nginx            | A HTTP server and IMAP/POP3 proxy server                    | package
  | nginx-macros     | Just some macros to make packaging nginx and modules easier | package
  | nginx-source     | The nginx source                                            | package

Note: For an extended search including not yet activated remote resources please use 'zypper   search-packages'.
#安装
localhost:/etc/sysconfig/network # zypper in nginx
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:  nginx
1 new package to install.
Overall download size: 703.3 KiB. Already cached: 0 B. After the operation, additional 2.3 MiB will be used.
Continue? [y/n/v/...? shows all options] (y): y
Retrieving: nginx-1.21.5-150400.3.3.1.x86_64 (sle-module-server-applications)                                                                                                                                                                             (1/1), 703.3 KiB    
Checking for file conflicts: ...........................................................................................................................................................................................................................................[done]
/usr/sbin/useradd -r -c User for nginx -d /var/lib/nginx -U nginx -s /usr/sbin/nologin
(1/1) Installing: nginx-1.21.5-150400.3.3.1.x86_64 .....................................................................................................................................................................................................................[done]
#启用
localhost:/etc/sysconfig/network # systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
#开启服务
localhost:/etc/sysconfig/network # systemctl start nginx
#查看启动状态
localhost:/etc/sysconfig/network # systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
     Active: active (running) since Thu 2024-06-13 13:06:32 CST; 38s ago
    Process: 8487 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
   Main PID: 8489 (nginx)
      Tasks: 2
     CGroup: /system.slice/nginx.service
             ├─ 8489 "nginx: master process /usr/sbin/nginx -g daemon off;"
             └─ 8490 "nginx: worker process" "" "" "" "" "" "" "" "" ""

Jun 13 13:06:32 localhost systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jun 13 13:06:32 localhost nginx[8487]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jun 13 13:06:32 localhost nginx[8487]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jun 13 13:06:32 localhost systemd[1]: Started The nginx HTTP and reverse proxy server.
#查看进程
localhost:/etc/sysconfig/network # ps -ef|grep nginx
root      8489     1  0 13:06 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon off;
nginx     8490  8489  0 13:06 ?        00:00:00 nginx: worker process
root      8496  4496  0 13:09 pts/0    00:00:00 grep --color=auto nginx
#查看端口
localhost:/etc/sysconfig/network # ss -tulpn |grep nginx
一切都正常,但是访问http://ip,得到的结果是“无法反问,错误403 Forbidden nginx/1.21.5"
正常情况这里安装好了都是可以打开Nginx的欢迎界面的。
#防火墙设置
localhost:/etc/sysconfig/network # systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
     Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: disabled)
     Active: active (running) since Thu Jun 13 13:09:32 CST; 3h 8min ago
       Docs: man:firewalld(1)
   Main PID: 778 (firewalld)
      Tasks: 2
     CGroup: /system.slice/firewalld.service
             └─ 778 /usr/bin/python3 /usr/sbin/firewalld --nofork --nopid
Jun 13 13:09:32 localhost systemd[1]: Starting firewalld - dynamic firewall daemon...
Jun 13 13:09:32 localhost systemd[1]: Started firewalld - dynamic firewall daemon.
#添加了端口

localhost:/etc/sysconfig/network # firewall-cmd --add-port=80/tcp --permanent
localhost:/etc/sysconfig/network # firewall-cmd --reload
设置了也没有用,原因不在这儿。
#查看错误日志
localhost:/etc/nginx # cat /var/log/nginx/error.log
2024/06/13 13:47:16 [error] 1453#1453: *4 open() "/srv/www/htdocs/index.html" failed (2: No such file or directory), client: 192.168.10.8, server: localhost, request: "GET /index.html HTTP/1.1", host: "192.168.10.39"
"http://192.168.0.39/index.html"
2024/06/13 13:56:43 [error] 2376#2376: *1 directory index of "/srv/www/htdocs/" is forbidden, client: 192.168.10.8, server: localhost, request: "GET / HTTP/1.1", host: "192.168.10.39"
2024/06/13 13:56:47 [error] 2376#2376: *1 directory index of "/srv/www/htdocs/" is forbidden, client: 192.168.10.8, server: localhost, request: "GET / HTTP/1.1", host: "192.168.10.39"
2024/06/13 13:57:00 [error] 2376#2376: *1 directory index of "/srv/www/htdocs/" is forbidden, client: 192.168.10.8, server: localhost, request: "GET / HTTP/1.1", host: "192.168.10.39
里面空空荡荡的,使用SUSE库安装的和从Nginx下载的安装还是有点不同的。
localhost:~ # cd /srv/www/htdocs
localhost:/srv/www/htdocs # ls
50x.html

3.配置Nginx
配置之前好好看了优化的相关文章,优化的参数太多,就修改了自己中意的几个。
3.1配置参数优化Nginx: vim /etc/nginx/nginx.conf
worker_processes  8;
worker_rlimit_nofile 65536;
events {
    worker_connections  10240;
    use epoll;
}
--高效传输
    sendfile        on;
    tcp_nopush     on;

--压缩
    gzip  on;
    gzip_min_length 1k;
    gzip_buffers 4 32k;
    gzip_comp_level 6;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";


3.2文件句柄限制:vim /etc/security/limits.conf
*               -       nofile          65536
*               soft    nofile          65536
*               hard    nofile          65536
root            soft    nofile          65536
root            hard    nofile          65536


3.3内核参数优化:vim /etc/sysctl.conf
net.core.somaxconn = 40960
fs.file-max = 999999  --同时打开的最大句柄数
net.ipv4.tcp_tw_recycle = 1--快速回收
net.ipv4.tcp_tw_reuse = 1--开启重用
net.ipv4.tcp_syncookies = 0--启用SYNC cookies
net.ipv4.tcp_max_orphans = 3276800

我的目的是让Nginx做请求代理服务器,所以http配置如下
http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;
    gzip  on;
    gzip_min_length 1k;
    gzip_buffers 4 32k;
    gzip_comp_level 6;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";
    upstream srm {
              #sticky;
              ip_hash;
          server  192.168.10.1:82 weight=3 max_fails=2 fail_timeout=36;
          server  192.168.10.2:82 weight=3 max_fails=2 fail_timeout=36;
          server  192.168.10.3:82 weight=3 max_fails=2 fail_timeout=36;
          server  192.168.10.4:82 weight=3 max_fails=2 fail_timeout=36;
                      }
    include conf.d/*.conf;
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        access_log  /var/log/nginx/host.access.log  main;
        location / {
           root   /srv/www/htdocs/;
           index  index.html index.htm;
           proxy_pass         http://srm;
           proxy_set_header   Host             $host:80;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
           client_max_body_size     100m;
           proxy_connect_timeout       15;
           proxy_read_timeout          300;
           proxy_send_timeout          500;
           if (-d $request_filename){ rewrite ^/(.*)([^/])$ /$1$2/ permanent; }
        }


4.防火墙设置允许端口
SuSEfirewall2配置简单,但是将被 firewalld替代,用yast2配置更直观一些。
#启停命令及状态查看
systemctl start firewalld
systemctl enable firewalld
systemctl stop firewalld
systemctl disable firewalld
firewall-cmd --state
#查看安全域
localhost:/etc/sysconfig/network  # firewall-cmd --get-zones
localhost:/etc/sysconfig/network  # firewall-cmd --get-default-zone
#配置多个端口
localhost:/etc/sysconfig/network # firewall-cmd --add-port=80/tcp --add-port=22/tcp --permanent
#配置服务
localhost:/etc/sysconfig/network #firewall-cmd --zone=public --add-service=http
#配置修改后重新加载
localhost:/etc/sysconfig/network #firewall-cmd --reload
#列出安全域允许的服务
localhost:/etc/sysconfig/network #firewall-cmd --list-services --zone=public
#查看配置结果
localhost:/etc/sysconfig/network #firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh
  ports: 80/tcp
  protocols: 
  forward: no
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 


5.升级Nginx失败
localhost:/etc/sysconfig/network # nginx -v
nginx version: nginx/1.21.5
但是官网上的版本都已经1.27了,继续往上升级
找到下载链接,下载解压缩:
localhost:/tmp #wget https://nginx.org/download/nginx-1.27.0.tar.gz
localhost:/tmp #mkdir /usr/nginx
localhost:/tmp #mv nginx-1.27.0.tar.gz /usr/nginx
localhost://usr/nginx #tar -zxf nginx-1.27.0.tar.gz
localhost:/usr/nginx #./configure && make &&make install
结果获得错误:
checking for C compiler ... not found
./configure: error: C compiler cc is not found
localhost:/usr/nginx #whereis gcc
可以看到安装了gcc,怀疑版本问题
localhost:/usr/nginx #zypper install gcc
果然更新后,检查通过,但是遇到新问题了:
./configure error the HTTP rewrite module requires the PCRE library
localhost:/usr/nginx #zypper install pcre
找不到安装包,只能选择跳过
localhost:/usr/nginx #./confgure --without-http_rewrite_module && make && make install
又遇到新错误
./configure error the HTTP Gzip module requires the zlib library
缺失那我就安装
localhost:/usr/nginx #zypper install zlib
可系统提示已经存在,那就继续跳过
localhost:/usr/nginx #./configure --wirhout-http_rewrite_module --with-zlib=/usr/share/man/mann/zbil.n.gz && make && make install
还是错误:
fatal error:zlib.h:No such file or directory
算了,还是老老实实用1.21.5版本。

  • 10
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 以下是SUSE Linux 12 SP5安装步骤: 1. 下载SUSE Linux 12 SP5的ISO镜像文件并将其刻录到DVD或USB驱动器中。 2. 将DVD或USB驱动器插入计算机并启动计算机。 3. 在启动时,选择从DVD或USB驱动器启动。 4. 在启动菜单中选择“安装”选项。 5. 选择您的语言和时区,并单击“下一步”。 6. 阅读并接受许可协议,并单击“下一步”。 7. 选择您的安装类型,例如“桌面”或“服务器”,并单击“下一步”。 8. 选择您的分区方案,例如“手动”或“自动”,并单击“下一步”。 9. 配置您的网络设置,例如IP地址和DNS服务器,并单击“下一步”。 10. 配置您的用户帐户和密码,并单击“下一步”。 11. 确认您的安装设置,并单击“安装”。 12. 等待安装完成,并单击“完成”。 13. 重新启动计算机,并从硬盘驱动器启动。 14. 登录到您的新SUSE Linux 12 SP5系统。 希望这些步骤对您有所帮助! ### 回答2: SUSE Linux是一种开源的Linux操作系统,它旨在为企业用户提供高可用性和稳定性。SUSE Linux 12 SP5是它的最新版本,它包含了许多新的功能和修复了许多已知的问题。以下是SUSE Linux 12 SP5安装步骤: 步骤1:准备安装环境 在你开始安装SUSE Linux 12 SP5之前,你需要准备一个安装环境,它可以是DVD、USB或网络安装源。如果你使用DVD或USB,你需要在计算机上插入它们并重启计算机以从它们启动。如果你使用网络安装源,你需要连接到网络并在启动时选择它。 步骤2:选择安装选项 一旦你启动了安装介质,你将看到一个引导界面。在这里,你可以选择语言、安装模式、时区等选项。你可以选择默认选项或根据需要进行自定义。 步骤3:磁盘分区 在安装SUSE Linux 12 SP5之前,你需要为其分配一个磁盘分区。你可以选择使用默认分区或手动分配分区。如果你选择手动分区,你需要确定要分配给根分区、家目录分区和交换分区的空间大小。 步骤4:安装软件 在磁盘分区之后,你需要选择要安装的软件包。你可以根据需要选择不同的软件模式和软件包。你可以选择服务器、桌面、基本文件、office suite、开发和其他软件包。 步骤5:配置网络 一旦安装完成,你需要配置网络设置。你可以选择DHCP或手动配置IP地址、网关和DNS设置。 步骤6:完成安装 最后,你需要完成SUSE Linux 12 SP5安装。一旦完成,你将被提示重新启动计算机。重启后,你可以使用新安装的系统。 ### 回答3: SUSE Linux是一款基于OpenSUSE的开放源代码操作系统,它是一款非常受欢迎的Linux版本之一,提供了高效的安装和使用体验。要安装SUSE Linux 12 SP5,您需要按照以下步骤操作: 第一步:下载ISO文件 请下载SUSE Linux 12 SP5的ISO文件,并将其从一个USB设备或DVD烧录到安装媒体。 第二步:启动计算机 将安装媒体插入计算机并重新启动计算机。 第三步:选择安装选项 当计算机重新启动时,您将看到一个SUSE Linux 12 SP5安装选项,选择“安装”。 第四步:确认语言和日期设置 您可以选择语言和日期,然后单击“下一步”。 第五步:选择安装源 选择您想要使用的软件源,这将使用网络连接更新系统,单击“下一步”按钮。 第六步:选择目标硬盘 如果您有多个硬盘,请选择SUSE Linux 12 SP5安装位置以及安装Linux操作系统。您可以选择不同的文件系统,根据您的需要更改分区大小,并完成其他相关设置。 第七步:选择网络设置 配置网络设置,并设置防火墙和系统安全策略。 第八步:配置系统用户和管理权限 配置管理员和常规用户的设置,以便访问系统和文件。 第九步:安装软件包 一旦配置完毕,您可以继续安装SUSE Linux 12 SP5的软件包。根据软件包的大小和安装速度,可能需要一段时间才能完成安装。 第十步:完成安装 安装完成后,您可以重新启动计算机,并开始使用SUSE Linux 12 SP5。 总之, SUSE Linux 12 SP5是一款功能强大的操作系统,提供了广泛的工具和应用程序,以及最新的安全更新和补丁,使您的计算机获得更好的性能和稳定性。安装SUSE Linux 12 SP5非常简单,遵循上述步骤,您可以快速地安装配置SUSE Linux 12 SP5,并享受其各种优良功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值