centos7纯净版安装教程

这篇教程详细介绍了如何在Linux系统中重装CentOS和配置静态IP,包括修改网卡配置文件、设置网络代理、配置yum源,并提供了安装Python和Nginx的步骤。此外,还讲解了如何配置网络代理和Nginx服务。
摘要由CSDN通过智能技术生成

一、下载系统镜像,形成启动盘

重装windows系统与linux系统教程
https://blog.csdn.net/qq3434569/article/details/118704223?spm=1001.2014.3001.5501

二、配置网络代理

当我们安装完一个纯净的CentOS系统之后,一般ip是选用 dhcp方式连接,这种随机分配的方式不利于后期的实验,重启之后 ip就会更换了,所以我们需要一个固定的 ip。

1)打开网卡配置文件,路径一样,文件名可能不一样

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

2)修改网卡信息内容

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=75fa294a-0aa3-47e8-8a7c-8280fb5e8028
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.170.130 #自己ip
NETMASK=255.255.255.0
GATEWAY=192.168.170.2
DNS1=114.114.1.1

重要参数信息:
BOOTPROTO=static #配置静态 ip选项,默认为 dhcp模式

ONBOOT=yes #启动网卡

IPADDR=192.168.170.130 #静态 ip
NETMASK=255.255.255.0 #子网掩码
GATEWAY=192.168.170.2 #网关,需要在虚拟机网络编辑中 NAT模式查看到
DNS1=114.114.114.114 #DNS

3)修改完上述步骤之后,重启网络服务

[root@node1 ~]# systemctl restart network

4)验证网络是否正常

ping www.baidu.com
ifconfig
ip addr

在这里插入图片描述

三、网络代理配置(如果是在内网,不是则忽略)

编辑文件**/etc/profile**,如果只想给自己的账户设置,则编辑**~/.bashrc**即可

export http_proxy="http://127.0.0.1:808"   #根据实际代理名称填写
export https_proxy="http://www.baidu.com:808"
export ftp_proxy=$http_proxy

然后source /etc/profile 或者source ~/.bashrc即可行:

四、配置yum镜像源(0.6不支持,国外下载慢)

1 备份(针对所有CentOS可用,备份文件在当前路径下)

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2.下载新的CentOS-Base.repo 到/etc/yum.repos.d/

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

  1. 安装 wget
yum isntall wget

五、安装python (不用可以忽略)

1.准备环境

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel

2.下载并解压python

wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
tar -zxvf Python-3.7.5.tgz
cd Python-3.7.5
./configure
make&&make install

3.配置软连接(不能替换python 会影响yum等相关依赖)

错误操作:

mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/bin/python3 /usr/bin/python

正确操作:

ln -s /usr/local/bin/python3 /usr/bin/python3

实际项目使用env,虚拟环境:
https://juejin.cn/post/6844903567711535118

4.pip 镜像源

pip3 install pip -U
pip3  config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

7、安装nginx

相关依赖下载(已有则忽略)

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

1、下载nginx安装包

wget http://nginx.org/download/nginx-1.9.9.tar.gz  
tar -zxvf  nginx-1.9.9.tar.gz
./configure
make
make install
  1. 配置nginx,/usr/local/nginx/conf/

配置资料:https://www.nginx.cn/nginx-how-to
学习更多:https://docs.nginx.com/nginx/
参考配置:

#user  nobody;
worker_processes  1; #工作进程:数目。根据硬件调整,通常等于cpu数量或者2倍cpu数量。
 
#错误日志存放路径
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid; # nginx进程pid存放路径
 
 
events {
    worker_connections  1024; # 工作进程的最大连接数量
}
 
 
http {
    include       mime.types; #指定mime类型,由mime.type来定义
    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  logs/access.log  main; #用log_format指令设置日志格式后,需要用access_log来指定日志文件存放路径
					
    sendfile        on; #指定nginx是否调用sendfile函数来输出文件,对于普通应用,必须设置on。
			如果用来进行下载等应用磁盘io重负载应用,可设着off,以平衡磁盘与网络io处理速度,降低系统uptime。
    #tcp_nopush     on; #此选项允许或禁止使用socket的TCP_CORK的选项,此选项仅在sendfile的时候使用
 
    #keepalive_timeout  0;  #keepalive超时时间
    keepalive_timeout  65;
 
    #gzip  on; #开启gzip压缩服务
 
    #虚拟主机
    server {
        listen       80;  #配置监听端口号
        server_name  localhost; #配置访问域名,域名可以有多个,用空格隔开
 
        #charset koi8-r; #字符集设置
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
        #错误跳转页
        #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$ { #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
        #    root           html; #根目录
        #    fastcgi_pass   127.0.0.1:9000; #请求转向定义的服务器列表
        #    fastcgi_index  index.php; # 如果请求的Fastcgi_index URI是以 / 结束的, 该指令设置的文件会被附加到URI的后面并保存在变量$fastcig_script_name中
        #    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;
        #}
    }
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;  #监听端口
    #    server_name  localhost; #域名
 
    #    ssl_certificate      cert.pem; #证书位置
    #    ssl_certificate_key  cert.key; #私钥位置
 
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m; 
 
    #    ssl_ciphers  HIGH:!aNULL:!MD5; #密码加密方式
    #    ssl_prefer_server_ciphers  on; # ssl_prefer_server_ciphers  on; #
 
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
}
  1. 配置成服务
    在/usr/lib/systemd/system目录下创建nginx.service文件,内容如下:
    vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx service
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
  1. 相关指令
启动nginx服务

systemctl start nginx.service          

停止服务

systemctl stop nginx.service          

重新启动服务

 systemctl restart nginx.service       

查看服务当前状态

#systemctl status nginx.service 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值