linux 基本操作

113 阅读2分钟

开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第29天,点击查看活动详情 安装nginx

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

tar -zxvf nginx-1.21.3.tar.gz
cd  nginx目录
./configure        --- 用来检测安装平台的目标特征
make                  --- 用来编译( 从Makefile中读取指令,然后编译)
make install        --- 用来安装( 从Makefile中读取指令,安装到指定的位置)

// 更改配置
cd /usr/local/nginx/conf
 
vim nginx.conf
 
cd /usr/local/nginx/sbin
./nginx
 
查看是否启动成功命令:ps -ef | grep nginx

配置命令式启动
vim /usr/lib/systemd/system/nginx.service
chmod +x /usr/lib/systemd/system/nginx.service


[Unit]                                                                                      
Description=nginx - high performance web server              
After=network.target remote-fs.target nss-lookup.target   

[Service]                                                                                 
Type=forking                                                                        
PIDFile=/usr/local/nginx/logs/nginx.pid                               
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf   
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf           
ExecReload=/usr/local/nginx/sbin/nginx -s reload                                                 
ExecStop=/usr/local/nginx/sbin/nginx -s stop                                                       
ExecQuit=/usr/local/nginx/sbin/nginx -s quit                                                        
PrivateTmp=true                                                                  

[Install]
WantedBy=multi-user.target 


//在启动服务之前,需要先重载systemctl命令
systemctl daemon-reload


systemctl status nginx
systemctl start nginx
systemctl stop nginx
systemctl restart nginx


关闭火墙

//查看状态
systemctl status firewalld.service
//停止
systemctl stop firewalld.service

//关闭自启动
systemctl disable firewalld.service
//查看火墙配置
firewall-cmd --list-all

//增加配置
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.21.101" port protocol="tcp" port="80" accept"

开启ssh

systemctl start sshd.service

//开机自启动
systemctl enable sshd.service

链接报错

rm -rf ~/.ssh/known_hosts


配置静态ip

vi /etc/sysconfig/network-scripts/ifcfg-ens33

systemctl restart network

主要修改点:

BOOTPROTO="static" 设置网络为静态IP

IPADDR=192.168.xxx.131 设置静态IP地址

GATEWAY=192.168.249.1 设置静态IP网关

DNS1=8.8.8.8 设置DNS

DNS2=192.168.249.1 设置DNS

NETMASK=255.255.255.0 设置子网掩码

负载均衡

    upstream httpds {
        server 192.168.21.101 weight=3;
        server 192.168.21.102 weight=1;

    }
    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass http://httpds;
            #root   html;
            #index  index.html index.htm;
        }
}

防盗链

         location ~*/(js|css) {
         +   valid_referers none blocked hadoop100 192.168.21.100;
          +      if ($invalid_referer) {
          +    return 403;
          + }
            root   html;
            index  index.html index.htm;
        }
// none 表示没有referer可以
// blocked 允许不是http://开头的,不带协议的请求访问资源;

crul 测试

yum install -y curl
//-I 表示不显示内容,只显示相应头
curl -I 地址
curl -e 地址  -I 地址