(1) Master the most basic usage of Linux server - understand the basic usage and common commands of Linux server.

1. Introduction to Linux system

slightly 

2. Server remote connection method

1. SSH remote terminal, Windows can use xshell software, MacOS comes with SSH service.

2. PuTTY is mainly used to connect to the server remotely. The disadvantage is that it has a single function. It is just a client. It is rarely used, but it is also used in some specific situations.

3. SecureCRT is commonly used, but does not include Mac systems.

VNC uses a client-server model and is connected to VNC server software running on a remote computer over a network.

"vncserver: port number" command to start; "vncserver –kill: port number" command to destroy (must)

4. TeamViewer: TeamViewer is a software for remote control, desktop sharing and file transfer. TeamViewer can establish connections between computers with different operating systems and supports operating systems such as Windows, Mac, Linux, iOS and Android.
5. It is recommended to use VS code. VS code is a cross-platform code editor.

3. Code management software

 Here are some common code management software you can use to manage and collaborate on code development:

1. Git: Git is the most commonly used distributed version control system. It can perform version control, branch management, and merge operations on code. Git can be integrated with various code hosting platforms (such as GitHub, GitLab and Bitbucket) to facilitate team collaboration and development.

2. SVN: Subversion (SVN for short) is a centralized version control system that can also perform version control and management of code. SVN is relatively simple to use and suitable for small teams or individual developers.

3. Mercurial: Mercurial is another distributed version control system, similar to Git. It has similar functions and commands to Git and is suitable for individual developers and small teams.

4. Perforce: Perforce is a powerful centralized version control system that is widely used in large-scale projects and enterprise-level development. It provides efficient code management and collaboration capabilities and supports large-scale team development.

5. TFS: Team Foundation Server (TFS) is a set of application life cycle management tools developed by Microsoft, including version control, collaboration and project management functions. TFS is highly integrated with Visual Studio and is suitable for development teams on the Microsoft technology stack.

4. Linux server configuration

1. Introduction to various directories:

bin is the abbreviation of Binary, which stores binary files.

When installing the system, the boot directory is a bit critical.


There are many things placed in etc:

In Linux systems, the /etc directory is used to store system configuration files and related parameter settings.

The following are some common files and directories that may appear in the /etc directory:

        1. /etc/passwd: stores user account information.
        2. /etc/group: stores user group information.
        3. /etc/shadow: Stores the encrypted form of user passwords.
        4. /etc/hosts: used to configure the mapping relationship between IP addresses and host names.
        5. /etc/resolv.conf: used to configure the settings of the DNS (Domain Name System) resolver.
        6. /etc/network/interfaces or /etc/sysconfig/network-scripts/ifcfg-*: used to configure network interface settings.
        7. /etc/fstab: used to define mounting information of file systems and devices.
        8. /etc/ssh/sshd_config: used to configure the settings of the SSH (Secure Shell) server.
        9. /etc/sudoers: Authorization file that defines superuser permissions.
        10. /etc/cron.d or /etc/cron.daily, /etc/cron.weekly, etc.: configuration files and directories for scheduled tasks.
        11. /etc/apt/sources.list: used to configure the software sources of the apt package manager.
        12. /etc/nginx/nginx.conf: used to configure the settings of the Nginx web server.
        13. /etc/apache2/apache2.conf: used to configure the settings of the Apache web server.

These are just some of the common files and directories. In fact, depending on the installed software and system configuration, there may be more files and subdirectories under the /etc directory.

lib is more critical.
dev stores device files.

When a system failure occurs, var is very critical, and system logs are stored in var.

2. Check the software and hardware:

Ishw Ishw (List Hardware) lists detailed information about all hardware devices in the system.
Iscpu The lscpu command is used to display CPU-related information, including processor type, number of cores, number of threads, etc.
lsbk The lsbk command is used to list information about block devices (such as hard disks and partitions), including device name, type size, etc.
lspci The Ispci command is used to list device information on the PCI bus, including graphics cards, network adapters, etc.
df

df is used to display file system usage, including disk space, usage and free space.

Example usage:

Usage: df[options][directory]
Example:
df-h: Display the disk space usage of all mount points.
df-T: Display the file system type of all mount points.
df-i: Displays the inode usage of all mount points.
df-×<file system type>: exclude file systems of the specified type

3. Install the management package:

Package management Ubuntu  Use APT (Advanced Package Tool) and dpkg package management system to allow users to easily install, update and uninstall software packages.
Centos and RHEL Similar software package management functions are also provided using YUM (Yellowdog Updater, Modified) and RPM package management systems.
Default desktop environment Ubuntu The GNOME desktop environment is used by default, providing an intuitive user interface and user experience. This aspect is stronger than Centos.
 Centos By default, a lighter-weight desktop environment is used, suitable for server environments.
Linux system configuration-system software information Check release version information

lsb_release -a
cat /etc/os-release

cat /etc/issue

Check kernel information  uname -a
(displays all information, including kernel name, version, host name, system architecture, etc.)
View hostname hostname
Debian/Ubuntu (using APT package management) View the list of installed packages dpkg --list
Find if a specific package is installed  dpkg -l/grep <package-name>
Red Hat/CentOS/Fedora (use YUM or DNF package management)    View the list of installed packages

      yum list installed

or dnf list installed

Find if a specific package is installed  yum list installed <package-name>
Software installed manually Use which command For example, which <executable>, where <executable> is the name of the executable file you are looking for.
 Use find command For example, find /usr/local/bin -name <executable>, where /usr/local/bin is the default installation directory. (May require administrator rights)

4.  Environment variable configuration:

What are environment variables?

Environment variables are a setting in the operating system that are used to store configuration information for various systems and applications, as well as specify specific paths, variable parameters, etc. Environment variables are widely used in command lines, scripts, and programs to affect a program's behavior, search paths, default settings, and more.
Types of environment variables:
System-level environment variables: affect the entire operating system and are visible to all users and processes.

. In Linux, these variables are usually located in the /etc/environment or /etc/profile files

User-level environment variables: only affect the current user's sessions and processes.

In Linux, user-level environment variables are usually located in ~/.bashrc/.bash profile, ~/profile and other files.

Common environment variables:

PATH: 指定可执行文件的查找路径,让系统能够找到运行的命令。
LD_LIBRARY_PATH: 指定共享库 (也称为动态链接库)的查找路径。编译时用的最多。

CPATH/用于指定编译器在查找头文件时的默认路径。涉及C语言或C++的头文件时会用。

LANG: 指定默认的语言环境(可以不用修改)。

EDITOR: 默认文本编辑器。

JAVA HOME: Java 的安装路径。

PYTHONPATH: Python 模块的查找路径。人工智能、大数据开发的话,就很重要了。
查看环境变量:
echo $<环境变量名>

环境变量的配置步骤:
临时配置: 临时配置环境变量只在当前终端会话中生效,关闭终端后会失效。这种方式适用于次性的设置和测试。
export PATH-/usr/bin:$PATH(有的时候环境变量的顺序是很重要的。$PATH一般放在最后会比较好)

临时配置时,建议除了你自己找的路径,也要把别人的环境变量路径也添加一下。
永久配置: 永久配置环境变量会在每次登录时都生效,使配置对所有终端会话都可见。这种方式适用于长期的设置和使用。
修改环境变量配置文件-一般在文件未尾添加环境变量修改命令
重新启动系统或使用source命令使环境变量修改生效。

5、添加管理员权限

添加管理员权限(一):

/etc/sudoers  文件是 Linux 系统中用于配置 sudo 命令权限的重要文件。

通过编辑此文件,可以指定哪些用户、组或主机可以以管理员权限执行 sudo 命令。(需要管理员权限)

# User privilege specification

        root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges

        %admin   ALL=(ALL) ALL

# Allow members of group sudo to execute any command

        %sudo   ALL=(ALL:ALL) ALL

        username ALL=(ALL:ALL) ALL

其中,username 是要赋予管理员权限的用户名,ALL 表示允许在任何主机执行,(ALL:ALL) 表示允许在任何用户组的上下文中执行任何命令,最后一个 ALL 表示允许执行任何命令。

添加管理员权限 (二)
还可以将其他用户添加到 sudo 组,使其具有执行管理员操作的权限。确保您用户具有管理员权限后,可以使用 sudo 命令来执行需要管理员权限的操作。
        sudo usermod -aG sudo username
注意:管理员权限可以做很多事情尽量避免直接使用 root 用户进行常规操作,以减少意外错误和风险。

5、Linux系统常用文件

1、Linux系统常用文件-文件权限:

在 Linux 系统中,每个文件和目录都有其自己的权限设置,这些权限决定了谁可以访问、读取写入和执行它们。文件权限通过一系列的权限位来表示,分为所有者、所属组和其他用户三个权限组。
文件权限位:
读权限(r):允许用户读取文件内容。对目录来说,允许列出目录内容读权限 () :
写权限 (w) : 允许用户编辑或修改文件内容。对目录来说,允许在目录中创建、删除文件。执行权限 (x) : 允许用户执行文件,对目录来说,允许用户进入该目录
文件权限组:
所有者权限: 文件的所有者拥有文件的所有权限,并且可以更改文件的权限和所有者所属组权限:文件的所属组中的用户拥有此组权限,这允许文件所属组的成员进行共享访问。其他用户权限: 其他用户是不属于所有者或所属组的用户,他们拥有文件的此组权限。


数字表示法:
读限:4
写权限: 2
执行权限:1
例如,rwxr-xr-- 可以用数字表示为 755。

更改文件权限:
使用chmod将文件的所有者权限设置为读写,可以使用以下命令:
         chmod   urrw file.txt
chmod还可以修改文件夹的权限(推荐这种):
        chmod -R  777  /home/myfile

2、 Linux系统常用文件-系统日志查看

要学会使用系统日志。
在Linux 系统中,系统日志 (Syslog) 是记录系统活动、事件和错误信息的重要工具。系统管理员可以通过查看系统日志来监控系统的运行状况、排查问题以及进行故障排除。Linux 系统使用syslog 守护进程来收集、记录和管理系统日志。
系统日志主要目录 (/var/log)
/var/log
-syslog:整体系统日志,包括系统启动、关机、用户登录等
-auth.log:或 secure: 认证相关的日志,包括用户登录、权限认证等-messages;通用系统消息,包括内核和其他应用程序的消息kern.log:内核相关的日志
daemon.log:守护进程的日志
dmsg:内核环缓冲区的内容,显示系统启动时的详细信息

6、Linux系统常用命令

1、ifconfig  

网络状态:ifconfig   里面会有很多配置选项

ifconfig + [interface] + [option]

Interface

指定要查看或配置的网络接口,如 eth0、enp0s3 等

option可选项:

 -a:显示所有网络接口,包括不活动的接口。

 -s:显示简要的接口信息。

 -up:启用指定接口。

-down:禁用指定接口。

-ip [IP地址]:设置接口的 IP 地址。

-netmask [子网掩码]:设置接口的子网掩码。

-broadcast [广播地址]:设置接口的广播地址。

2、SSH

配置SSH服务器,需要管理员权限。里面会有很多配置选项。

SSH 服务器的配置文件通常位于 /etc/ssh/sshd_config。可以编辑该文件来配置 SSH 服务

器的行为。(需要管理员权限)

常见的配置选项包括:

Port:指定 SSH 服务器监听的端口,默认为 22。 

PermitRootLogin:控制是否允许 root 用户直接登录。

PasswordAuthentication:控制是否允许使用密码进行身份验证。

PubkeyAuthentication:启用公钥身份验证。

AllowUsers 或 AllowGroups:限制允许连接到服务器的用户或用户组。

配置SSH服务器(ssh-server):
​​​​​​​重启SSH服务器/查看SSH服务器状态

在Ubuntu/Debian系统上:

        sudo service ssh restart 

        sudo service ssh status

在CentOS/RHEL系统上:

        sudo systemctl restart sshd

        sudo systemctl status sshd

3、管道"I"

在Linux和 Unix 系统中,管道 (Pipeline) 是 种强大的特性,允许将一个命令的输出作为另一个命令的输入,从而将多个命令连接起来形成一个命令序列。这种方式可以在不创建中间文件的情况下实现数据的传递和处理,从而提高命令行工具的效率和灵活性.
command1  |  command2
command1 的输出会成为 command2 的输入​​​​​​​


4、ls命令

是一个用于列出目录内容的常用命令。可以显示指定目录中的文件和子目录,并提供不同的选项来以不同的格式和详细程序显示信息。
Is命令可以与其他命令(如grep等)结合使用,以更复杂的方式查询和处理文件。

常见选项:
-I: 以长格式(详细信息)显示文件列表。
-a: 显示包括隐藏文件在内的所有文件和目录。
-h: 以人类可读的格式显示文件大小。
-t: 按修改时间进行排序。
-r: 以相反的顺序排列。
-R:递归地显示子目录内容。
-S:按文件大小进行排序。

-- color: 启用彩色输出

-- help:显示帮助信息。

 5、文件、文件夹管理类

cd:        切换当前工作目录。
pwd:     显示当前工作目录的路径。
mkdir:   创建目录
cp:        复制文件或目录
mv:       移动文件或目录,也可用于重命名
rm:        删除文件或目录。使用-r选项可递归删除目录及其内容
cat:       连接文件并打印到标准输出
chown: 修改文件所有者和所属组

 6、grep命令

grep命令是一个用于在文本文件中搜索指定模式的工具。允许在文件中查找包含特定字符串或正则表达式的行,并将匹配的行显示出来。grep是Linux和Unⅸ系统中经常用于文本搜索的命令之一。
                grep[选项]  模式   文件
-i:忽略大小写进行搜索。
-V:显示不匹配的行。
-r:递归地在目录及其子目录中搜索。
-L:仅显示匹配的文件名。
-n:显示匹配行的行号。
-w:仅匹配完整单词。
-E:启用扩展的正则表达式语法。
可以使用不同的选项和正则表达式来实现更精确的搜索,常与管道符“”配合使用。对于系统管理、日志分析和文本处理等任务,grep非常有用。


7、find命令

find命令是Linux和Unix系统中用于在文件系统中搜索文件和目录的功能强大的工具。可以根据多种条件搜索文件,包括文件名、大小、权限、时间戳等,还支持使用正则表达式进行高级搜索。
find [路径]  [选项]  [操作]
■-name pattern:  根据文件名进行搜索,支持通配符。
■-type type:  根据文件类型进行搜索,如-type f(普通文件)、-type d(目录)。
■-size size:  根据文件大小进行搜索,支持c(字节)、k(千字节)、M(兆字节)等后缀。
■-mtime n: 根据文件修改时间进行搜索,n表示n天前的文件。
■-exec command: 对搜索结果执行指定命令。
■-print:将搜索结果输出到标准输出。


8、ps

进程线程是Linux中重要的状态。

ps命令是Linux和Unⅸ系统中用于查看当前运行进程状态的命令。能够列出正在运行的进程,以及相关信息,如进程ID(PID)、状态、CPU使用率、内存占用等。
ps  ef:   以详细格式列出所有进程,包括命令行参数
ps aux:  以详细格式列出所有用户的所有进程
ps一p进程号:显示指定进程号的信息


ps常与grep命令组合使用,可以更精确地查找和监控您感兴趣的进程。
■查找特定进程
■过滤特定用户的进程
■过滤命令行参数
■排除grep进程本身


9、top/htop命令

top命令的功能
■系统的运行时间。
■当前登录的用户数量。
■系统负载情况(1分钟、5分钟和15分钟的平均负载)。
■所有运行中的进程的总数、活跃进程数和睡眠进程数。
■CPU使用率(用户、系统、空闲等)。
■内存使用情况(总内存、已用内存、空闲内存、缓冲和缓存等)。
htop:在Top的基础上,把cpu核也显示出来了。

10、wc命令

wc命令是Linux和Unix系统中用于统计文件中字节数、单词数和行数的命令。它通常用于计算文本文件的基本信息,如文件大小、内容长度和行数等。
基本用法:
wc-c:统计字节数。
wc-w:统计单词数。
wc:统计行数。
高级用法:
统计多个文件的总和,例:“wc-I*.txt”
使用管道结合其他命令,例:统计某个命令的输出行数"Is -I | wc -I”
统计代码行数,例:grep -vE "^\s*($#)"code_file.py | wc  -I
统计代码行数还可以使用工具——cloc(Count Lines of Code)。他统计的更全面,还会统计出注释的行数等等。 


11、文件编辑 -Vi

模式切换:ⅵ编辑器有多种模式,包括命令模式、插入模式和末行模式,通过不同的模式可以进行编辑、插入和保存等操作。
命令模式:默认启动时进入的模式,用于执行编辑命令,如删除、复制、粘贴等。
插入模式:用于输入文本,按下i进入插入模式,按下Esc切换回命令模式。
末行模式:按下:进入未行模式,可以执行保存、退出、查找等操作。
强大的编辑功能:支持文本查找、替换、拷贝、粘贴、撤销等多种编辑操作。

在命令模式下,可以使用各种命令进行编辑,如i进入插入模式,dd删除一行,yy复制一行,p粘贴等。
切换到末行模式,按下:, 可以执行保存(:w)、退出(:q)等操作。
如果要保存并退出,可以组合使用末行命令,如   :wq

12、增强版vim

13、输出重定向">"

 注意:
> 和 >>  会创建或覆盖文件,务必小心操作,以免丢失数据。
2>和2>> 用于处理错误输出,可将错误信息和标准输出分开处理。
&> 和 &>> 将标准输出和错误输出合并到同一个文件中。
使用 >和< 时,需要确保空格的正确使用,如command>  output.txt

14、文件压缩/解压 -tar

平时,tar的使用频率也挺高的。
另外一个命令:

 15、ln命令

 强调一下:ln 的写法:源文件写前面,要生成的目标文件写在后面。否则,源文件被目标文件替换成空白文件,从而无法启动系统!
建议在执行这一命令时,先对源文件备份。​​​​​​​


16、ldd命令

 17、apt安装员的配置方法


​​​​​​​

 18、yum源的配置方法

7、软件源码编译与安装

检查编译工具:
在开始编译之前,确保系统中已安装了编译所需的工具,如编译器(例如gcc)、构建工具(如
make)和开发库(如libc)等。可以通过包管理工具安装这些工具。
配置编译选项:
进入源代码目录,运行配置脚本以配置编译选项。通常,可以使用 ./configure命令来配置,但一些软件可能有自己的配置脚本。您可以使用不同的选项来启用或禁用功能、指定安装路径等。
编译源代码:
运行make命令来编译源代码。这将生成可执行文件和其他必要的文件。这一步很关键。
安装软件:
运行sudo make install命令以将编译后的文件安装到系统中。这将把文件复制到系统的标准安装路径,通常为/usr/local。
如果感兴趣,可以从网上找一些简单的安装的安装包试一试。

8、代码编译安装

在服务器上试一试上面的代码。
 

Guess you like

Origin blog.csdn.net/weixin_48060069/article/details/132269257