centos7一些基础优化

1、修改主机名的命令 hostnamectl

hostnamectl set-hostname --static alanPan

2、firewalld打开关闭防火墙与端口(active是启动状态,inactive是关闭状态)

systemctl status firewalld.service

centos7一些基础优化_第1张图片

systemctl stop firewalld.service    --关闭此服务

systemctl list-unit-files |grep firewalld    --查看firewalld是否开机自动启动

在这里插入图片描述
(1)设置开机启用防火墙:

systemctl enable firewalld.service

(2)设置开机禁用防火墙:

systemctl disable firewalld.service

(3)启动防火墙:

systemctl start firewalld

(4)关闭防火墙:

systemctl stop firewalld

(5)检查防火墙状态:

systemctl status firewalld

(6)查看防火墙状态:

firewall-cmd --state

(7)重新加载配置:

firewall-cmd --reload

(8)查看开放的端口:

firewall-cmd --list-ports

(9)开启防火墙端口:
(备注:–zone #作用域–add-port=80/tcp #添加端口,格式为:端口/通讯协议–permanent #永久生效,没有此参数重启后失效)

firewall-cmd --zone=public --add-port=80/tcp --permanent

3、关闭selinux(临时和永久关闭Selinux)
3.1临时关闭

getenforce
setenforce 0

centos7一些基础优化_第2张图片
etenforce是Linux的selinux防火墙配置命令 执行setenforce 0 表示关闭selinux防火墙。
setenforce命令是单词set(设置)和enforce(执行)连写,另一个命令getenforce可查看selinux的状态

3.2永久关闭

vim /etc/sysconfig/selinux

centos7一些基础优化_第3张图片
SELINUX=enforcing 改为 SELINUX=disabled
重启服务reboot
4、网络配置

systemctl stop NetworkManager        --停止服务
systemctl status NetworkManager    --查看状态,确认为关闭了
systemctl disable NetworkManager    --设置为开机不自动启动
vim /etc/sysconfig/network-scripts/ifcfg-eth0xxxxx    --(注意:网卡名如果不一样,自己找对应的文件)
cd /etc/sysconfig/network-scripts/
ll

centos7一些基础优化_第4张图片
centos7一些基础优化_第5张图片
centos7一些基础优化_第6张图片
5、yum配置
5.1进入yum 目录

cd /etc/yum.repos.d/
ll

-rw-r--r--. 1 root root 1664 Dec  9  2015 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Dec  9  2015 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Dec  9  2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  290 Dec  9  2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Dec  9  2015 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Dec  9  2015 CentOS-Sources.repo
-rw-r--r--. 1 root root 1952 Dec  9  2015 CentOS-Vault.repo

5.2 备份 yum文件

tar -zcvf yum180919.tar.gz *

-rw-r--r--. 1 root root 2060 Sep 19 03:30 yum180919.tar.gz

5.3 删除 yum 文件

[root@alanPan yum.repos.d]# rm -rf *.repo
[root@alanPan yum.repos.d]# ll
total 4
-rw-r--r--. 1 root root 2060 Sep 19 03:30 yum180919.tar.gz

5.4 新建 local.repo 文件
vim local.repo

[local]
name=local
baseurl=file:///yum
enabled=1
gpgcheck=0

5.5 配置163的centos源(cd /etc/yum.repos.d/ 在这个目录)

wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

centos7一些基础优化_第7张图片
CentOS7-Base-163.repo 文件

[base]
name=CentOS-$releasever - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

(yum 设置有问题,后续搞定 再更新 o( ̄︶ ̄)o)

6、时间同步

yum install ntp  ntpdate    --安装ntp时间同步相关软件包
下载过程中 y 就好
yum install ntp  ntpdate
Loaded plugins: fastestmirror, langpacks
base                                                                                                                                                                                                                                                   | 3.6 kB  00:00:00     
extras                                                                                                                                                                                                                                                 | 3.4 kB  00:00:00     
updates                                                                                                                                                                                                                                                | 3.4 kB  00:00:00     
(1/4): extras/7/x86_64/primary_db                                                                                                                                                                                                                      | 187 kB  00:00:05     
(2/4): updates/7/x86_64/primary_db                                                                                                                                                                                                                     | 5.2 MB  00:00:06     
(3/4): base/7/x86_64/group_gz                                                                                                                                                                                                                          | 166 kB  00:00:06     
(4/4): base/7/x86_64/primary_db                                                                                                                                                                                                                        | 5.9 MB  00:00:07     
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.cn99.com
 * updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-22.el7.centos will be updated
---> Package ntp.x86_64 0:4.2.6p5-28.el7.centos will be an update
--> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.2)(64bit) for package: ntp-4.2.6p5-28.el7.centos.x86_64
---> Package ntpdate.x86_64 0:4.2.6p5-22.el7.centos will be updated
---> Package ntpdate.x86_64 0:4.2.6p5-28.el7.centos will be an update
--> Running transaction check
---> Package openssl-libs.x86_64 1:1.0.1e-42.el7.9 will be updated
--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-42.el7.9 for package: 1:openssl-1.0.1e-42.el7.9.x86_64
---> Package openssl-libs.x86_64 1:1.0.2k-12.el7 will be an update
--> Running transaction check
---> Package openssl.x86_64 1:1.0.1e-42.el7.9 will be updated
---> Package openssl.x86_64 1:1.0.2k-12.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================================================================
 Package                                                            Arch                                                         Version                                                                     Repository                                                  Size
==============================================================================================================================================================================================================================================================================
Updating:
 ntp                                                                x86_64                                                       4.2.6p5-28.el7.centos                                                       base                                                       549 k
 ntpdate                                                            x86_64                                                       4.2.6p5-28.el7.centos                                                       base                                                        86 k
Updating for dependencies:
 openssl                                                            x86_64                                                       1:1.0.2k-12.el7                                                             base                                                       492 k
 openssl-libs                                                       x86_64                                                       1:1.0.2k-12.el7                                                             base                                                       1.2 M

Transaction Summary
==============================================================================================================================================================================================================================================================================
Upgrade  2 Packages (+2 Dependent packages)

Total download size: 2.3 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for base
warning: /var/cache/yum/x86_64/7/base/packages/ntpdate-4.2.6p5-28.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY                                                                                             ]  0.0 B/s |  39 kB  --:--:-- ETA 
Public key for ntpdate-4.2.6p5-28.el7.centos.x86_64.rpm is not installed
(1/4): ntpdate-4.2.6p5-28.el7.centos.x86_64.rpm                                                                                                                                                                                                        |  86 kB  00:00:06     
(2/4): ntp-4.2.6p5-28.el7.centos.x86_64.rpm                                                                                                                                                                                                            | 549 kB  00:00:07     
(3/4): openssl-1.0.2k-12.el7.x86_64.rpm                                                                                                                                                                                                                | 492 kB  00:00:00     
(4/4): openssl-libs-1.0.2k-12.el7.x86_64.rpm                                                                                                                                                                                                           | 1.2 MB  00:00:00     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                         306 kB/s | 2.3 MB  00:00:07     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) "
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-2.1511.el7.centos.2.10.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:openssl-libs-1.0.2k-12.el7.x86_64                                                                                                                                                                                                                        1/8 
  Updating   : ntpdate-4.2.6p5-28.el7.centos.x86_64                                                                                                                                                                                                                       2/8 
  Updating   : ntp-4.2.6p5-28.el7.centos.x86_64                                                                                                                                                                                                                           3/8 
  Updating   : 1:openssl-1.0.2k-12.el7.x86_64                                                                                                                                                                                                                             4/8 
  Cleanup    : ntp-4.2.6p5-22.el7.centos.x86_64                                                                                                                                                                                                                           5/8 
  Cleanup    : ntpdate-4.2.6p5-22.el7.centos.x86_64                                                                                                                                                                                                                       6/8 
  Cleanup    : 1:openssl-1.0.1e-42.el7.9.x86_64                                                                                                                                                                                                                           7/8 
  Cleanup    : 1:openssl-libs-1.0.1e-42.el7.9.x86_64                                                                                                                                                                                                                      8/8 
  Verifying  : ntpdate-4.2.6p5-28.el7.centos.x86_64                                                                                                                                                                                                                       1/8 
  Verifying  : ntp-4.2.6p5-28.el7.centos.x86_64                                                                                                                                                                                                                           2/8 
  Verifying  : 1:openssl-1.0.2k-12.el7.x86_64                                                                                                                                                                                                                             3/8 
  Verifying  : 1:openssl-libs-1.0.2k-12.el7.x86_64                                                                                                                                                                                                                        4/8 
  Verifying  : 1:openssl-libs-1.0.1e-42.el7.9.x86_64                                                                                                                                                                                                                      5/8 
  Verifying  : ntp-4.2.6p5-22.el7.centos.x86_64                                                                                                                                                                                                                           6/8 
  Verifying  : ntpdate-4.2.6p5-22.el7.centos.x86_64                                                                                                                                                                                                                       7/8 
  Verifying  : 1:openssl-1.0.1e-42.el7.9.x86_64                                                                                                                                                                                                                           8/8 

Updated:
  ntp.x86_64 0:4.2.6p5-28.el7.centos                                                                                                  ntpdate.x86_64 0:4.2.6p5-28.el7.centos                                                                                                 

Dependency Updated:
  openssl.x86_64 1:1.0.2k-12.el7                                                                                                      openssl-libs.x86_64 1:1.0.2k-12.el7                                                                                                     

Complete!
[root@localhost yum.repos.d]# 
vim /etc/ntp.conf        --确认配置文件里有下列的时间同步源
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
systemctl enable ntpd        --设置开机自动启动ntpd
systemctl start ntpd        --立即启动ntpd服务
systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@localhost yum.repos.d]# systemctl start ntpd
[root@localhost yum.repos.d]# 

7、命令的参数可以自动补全

yum install bash-completion

8、设置默认启动级别为图形模式(相当于以前的5级别)

systemctl get-default            --查看当前的运行模式
systemctl set-default graphical.target    --设置图形模式为默认模式
systemctl set-default multi-user.target       --设置命令行模式为默认模式
[root@localhost yum.repos.d]# clear
[root@localhost yum.repos.d]# systemctl get-default
graphical.target
[root@localhost yum.repos.d]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
[root@localhost yum.repos.d]# 

centos7一些基础优化_第8张图片

你可能感兴趣的:(Linux)