Linux tutorial 2 - centos 基本配置

本文介绍了CentOS系统的基础配置步骤,包括语言环境、时区、防火墙、SELinux等核心组件的设置方法,以及如何使用常见命令进行系统维护。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上一篇尝试了win10 hyper-v里面安装centos虚拟机,并配置了网络,用xshell进行连接,并把系统更新到了最新版本。这里就学习一下linux的基本操作。

上一篇使用了xshell连接,这一篇试试putty连接,以下截图都是putty中的截图。

1. Linux常识

linux系统已经有了,现在对其基础知识做个简单了解。

1.1 版本

  • Linux系统一般有4个主要部分:内核、Shell、文件系统和应用程序。内核、Shell、文件系统一起形成了基本的操作系统结构。
  • Linux有内核Kernel版本和发行Distribution版本之分。
  • Kernel版本是在Linus领导下的开发小组开发出的系统内核版本;内核版本号由3个数字组成,即r.x.y:
    r: kernel主版本号
    x: 偶数表示稳定版本;奇数表示开发中的版本;
    y:错误修补的次数
  • Distribution版本是一些组织或厂家将Linux系统内核与应用软件和文档包装起来,并提供一些安装界面和系统设定管理工具的一个软件包的集合。

1.2 帮助命令:

  • help 内置命令(eg: help history):查看内置命令的使用方法
  • 命令名 –help(eg: ls –help):查看摘要和参数列表
  • whatis 命令名(eg: whatis ls):查看简要功能描述
  • man命令名(eg: man ls):查看该命令的手册
  • info命令名(eg: info ls):查看命令的GNU项目文档
  • man -k <关键字>(eg: man -k selinux):列出所有与关键字匹配的命令

1.3 命令执行时的查找路径顺序

  • 1)用户给出了命令的路径,Shell按给定路径查找,若找到则调入内存执行,若没找到则输出提示信息
  • 2)用户没有给出命令的路径,Shell在环境变量PATH所指定的路径中依次进行查找,若找到则调入内存执行,没有找到则输出提示信息

2. 配置语言环境

  • 查看系统支持的语言环境:localectl list-locales | egrep “zh_CN|en_US”
    这里写图片描述
  • 查看当前系统的语言环境:cat /etc/locale.conf
  • 更改语言环境,下次登录时生效:localectl set-locale LANG=”en_US.UTF-8”

3. 配置时区

  • Linux中有RTC(real time clock)硬件时钟和system clock(系统时钟)两种。
  • RTC是主板上的电池供电的硬件时钟设备,也就是通常在BIOS画面设定的时钟; 系统时钟指Linux Kernel中的时钟。
    Linux启动时,系统时钟会读取硬件时钟的设定,之后系统时钟就独立运行。
  • 所有Linux指令和函数都使用系统时钟设定。
  • 系统时钟总是使用世界标准时间UTC(coordinated universal
    time),且在需要时,由APP根据当前的时区设置和是否启用了日光节约时间DST(daylight saving time,也叫夏令时)来转换本地时间。
  • RTC既可以使用UTC也可以使用本地时间,建议使用UTC作为硬件时钟。

3.1 查看日期/时间/时区:timedatectl

这里写图片描述

3.2 设置日期和/或时间:timedatectl set-time

timedatectl set-time 21:14:00
timedatectl set-time 2018-10-01
timedatectl set-time '2018-10-10 23:10:08'

3.3 查看系统支持的时区:timedatectl list-timezones | grep Asia

检索支持的亚洲时区
这里写图片描述

grep:检索目标行命令

3.4 设置时区(立即生效):timedatectl set-timezone Asia/Shanghai

3.5 查看当前时间:date

这里写图片描述

3.5 查看时区全局配置文件:ls -l /etc/localtime

这里写图片描述

3.6 使用远程时间服务器同步本机系统时间

yum -y install ntp
timedatectl set-ntp yes

4. 配置防火墙

防火墙默认允许外界访问本机ssh服务(端口号22)

4.1 关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

4.2 查看端口放行

这里写图片描述
firewall-cmd –query-port=8080/tcp

4.3 端口放行

这里写图片描述
firewall-cmd –permanent –zone=public –add-port=8080/tcp
firewall-cmd –reload

5. 配置SELinux

RHEL/CentOS 5开始支持SELinux安全机制,且默认是开启的。但SELinux配置相对复杂且很少在生产环境中使用,可以通过如下命令关闭。特别注意:SELinux经常导致其它电脑无法访问centos上的服务。

(将配置文件/etc/selinux/config中的SELINUX=enforcing改为SELINUX=disabled)
sed -i ‘s/SELINUX=.*/SELINUX=disabled/’ /etc/selinux/config

也可以直接去修改 /etc/selinux/config 文件:
这里写图片描述

6. 关机与重启

  • 关机:
    systemctl poweroff
    poweroff
    shutdown -h now
  • 停机:
    systemctl halt
    halt
    shutdown -H now
  • 重启:
    systemctl reboot
    reboot
    shutdown -r now
  • 警告所有登录用户系统将在10分钟后重新启动
    shutdown -r +10 “system will be rebooted in 5 minutes, please save your work.”

上一篇:Linux tutorial 1 - 安装centos 7 in hyper-v step by step
下一篇:Linux tutorial 3 - centos Shell

### CentOS 7 FTP Server Configuration Example Tutorial #### Update SELinux Boolean Values for FTP Service To ensure that the FTP service operates correctly under Security-Enhanced Linux (SELinux), modify the necessary boolean settings. This allows home directories to be used as FTP roots. ```bash setsebool -P ftp_home_dir on ``` This command updates the SELinux booleans permanently so that changes persist after a reboot[^1]. #### Install Required Packages Before configuring an FTP server, install vsftpd which is one of the most popular FTP servers available: ```bash sudo yum install vsftpd ``` Ensure all packages are up-to-date before proceeding with further configurations. #### Configure Firewall Rules Edit `/etc/sysconfig/iptables-config` using `vi`, ensuring the FTP module loads properly by setting `IPTABLES_MODULES="ip_conntrack_ftp"` within this file. After editing, save and close it[^5]. Then restart iptables or firewalld services depending upon what firewall management tool has been configured on your system. For systems utilizing Firewalld instead of Iptables, add rules allowing passive mode connections through the following commands: ```bash firewall-cmd --permanent --add-service=ftp firewall-cmd --reload ``` These steps permit traffic related specifically to FTP operations while maintaining security policies intact. #### Adjust Nginx Configuration If Necessary If reverse proxying via Nginx is part of the setup requirements, open its main configuration file located at `/etc/nginx/nginx.conf`. Modify relevant sections according to specific needs but generally no direct interaction between these two services exists unless explicitly designed otherwise[^4]. #### Setting Up Users For The FTP Service Create dedicated user accounts intended solely for accessing files over FTP without shell access rights. Follow best practices when creating such users including disabling login shells where possible and restricting their environment strictly to only those areas required for performing tasks associated with managing remote transfers securely. --related questions-- 1. How does modifying SELinux booleans impact overall system security? 2. What alternatives exist besides VSFTPD for running secure FTP services on CentOS 7? 3. Can you provide more details about securing FTP against unauthorized access attempts? 4. Is there any way to integrate SFTP into existing setups rather than traditional FTP protocols? 5. Why might someone choose not to use Nginx alongside an FTP solution despite potential benefits offered from doing so?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值