Skip to content
WONGCW 網誌
  • 首頁
  • 論壇
  • 微博
  • 壁紙下載
  • 免費圖床
  • 視頻下載
  • 聊天室
  • SEO工具
  • 支援中心
  • 表格製作
  • More
    • 在線名片
    • 網頁搜索
    • 天氣預報
    • 二維碼生成器
  • Search Icon

WONGCW 網誌

記錄生活經驗與點滴

Centos7 初始化配置

Centos7 初始化配置

2018-09-27 Comments 0 Comment

Centos7 初始化配置

[toc]

标签: Centos


安装EPEL源

yum install epel-release

修改epel源

[epel]
name=Extra Packages for Enterprise Linux 7 - basearch baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=basearch failovermethod=priority enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7  [epel-debuginfo] name=Extra Packages for Enterprise Linux 7 - basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/basearch/debug #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - basearch - Source baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

升级系统

yum update -y

update和upgrade的区别:
两者的作用都是将软件包升级到最新版。可是upgrade会考虑取代关系,如果有个包foo改名为foo2,那么upgrade会将foo升级为foo2并将foo删除!如果你的系统已经存在运行中的服务,且服务正常运行着,没重大的安全隐患不要使用upgrade升级系统。

升级系统而不升级内核

yum update --exclude=kernel* -y

安装常用包

Centos7 最小化安装很多命令都没有,比如ifconfig , netstat, 这时需要安装一些工具包,包括源码编译安装软件时的依赖

yum install -y pcre-devel openssl-devel libxslt* perl-ExtUtils-Embed at gcc-c++ python subversion gperf make rpm-build git curl bzip2-devel libcurl-devel gd gd-devel t1lib t1lib-devel libmcrypt libmcrypt-devel libtidy libtidy-devel GeoIP-devel libatomic_ops-devel zlib-devel unzip libstdc++* net-snmp net-snmp* gmp gmp-devel openldap openldap-devel libpcap-devel glib2-devel GeoIP-devel libxml2-devel libxml2-devel redis vim wget git htop iftop libtool make automake mlocate openssl-devel pam-devel unzip gcc screen openssl openssl-devel iptables-services bash-completion* pcre-devel openssl-devel libxslt* perl-ExtUtils-Embed at gcc-c++ python subversion gperf make rpm-build git curl bzip2-devel libcurl-devel gd gd-devel t1lib t1lib-devel libmcrypt libmcrypt-devel libtidy libtidy-devel GeoIP-devel libatomic_ops-devel zlib-devel unzip libstdc++* net-snmp net-snmp* gmp gmp-devel openldap openldap-devel net-tools

关闭一些程序

selinux

具体也不知道干嘛的,据说是美国的什么安全的什么鬼东西,具体去百度。启用了这个有些服务莫名其妙不能启动,索性关掉。

#打开selinux的配置文件
vim /etc/selinux/config

#将第7行的enforcing改为disabled
SELINUX=disabled

#保存退出
#这时需要重启才会生效,可以使用命令临时关闭
setenforce 0

firewalld

默认防火墙,CentOS7与CentOS6的区别之一使用firewalld替代了之前一直使用iptables,个人觉得iptables用起来更加顺手。

#禁止开机启动
systemctl disable firewalld

#立即停止服务
systemctl stop firewalld

使用 iptables

启用iptables

#设置iptables为开机启动
systemctl enable iptables

#立即启动iptables
systemctl start iptables

#禁止IPv6的ip6tables开机启动
systemctl disable ip6tables

#立即停止IPv6的ip6tables
systemctl stop ip6tables

设置iptables

  • 查看防火墙规则
#通过以下命令查看iptables现有的规则,包含INPUT,FORWARD,OUTPUT
iptables -L -vn --line-number

#通过以下命令查看iptables现有nat的规则,包含PREROUTING,INPUT,OUTPUT,POSTROUTING
iptables -L -vn -t nat --line-number
  • 修改iptables

iptables配置文件路径/etc/sysconfig/iptables

iptables 文件修改完成后需要重启服务器

配置SSH

无论你的服务器是用在外网还是内网,默认的SSH端口都必须更改。安全是最重要的。同时使用证书登陆,那就更好了。

#编辑sshd_config文件
vim /etc/ssh/sshd_config

#修改端口,在#Port 22这一行下添加,端口号请自行选择。
Port 9099

#修改PasswordAuthentication字段为no
PasswordAuthentication no

#保存退出

生成ssh key

#通过以下命令生成key(密钥对)
ssh-keygen -t rsa -b 4096

#这里回车即可
Enter file in which to save the key (/root/.ssh/id_rsa):

#这里请为你的key设置一个密码,用key登录的时候需要密码才能解锁key。这是保护key的一种有效的方法。
#密码留空并回车即为空密码,不安全!
Enter passphrase (empty for no passphrase):

#重命名密钥,有些主机以内置密钥,覆盖前请确认。
mv .ssh/id_rsa.pub .ssh/authorized_keys

#查看key并保存到本地,然后删除。
cat .ssh/id_rsa

#留密钥在服务器内就足够了,key删掉以保安全。前提是你已经保存到本地!要不然你将不能通过SSH登陆服务器!
rm -f .ssh/id_rsa

重启SSH服务

systemctl restart sshd

修改hostname

如果你有多台服务器,那hostname将是区分这些服务器最好的方法。你可以通过以下命令进行修改

hostnamectl set-hostname [your-hostname]

#例如
hostnamectl set-hostname test1

#重启生效

分享此文:

  • 按一下即可分享至 X(在新視窗中開啟) X
  • 按一下以分享至 Facebook(在新視窗中開啟) Facebook
  • 分享到 WhatsApp(在新視窗中開啟) WhatsApp
  • 按一下以分享到 Telegram(在新視窗中開啟) Telegram
  • 分享到 Pinterest(在新視窗中開啟) Pinterest
  • 分享到 Reddit(在新視窗中開啟) Reddit
  • 按一下即可以電子郵件傳送連結給朋友(在新視窗中開啟) 電子郵件
  • 點這裡列印(在新視窗中開啟) 列印

相關


Linux資訊

Post navigation

PREVIOUS
iOS 12.1 beta 1 已开启 eSIM 功能 但还需等运营商
NEXT
更新CentOS7上的内核版本 Update The Version Of Kernel On CentOS7

發表迴響取消回覆

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料。

More results...

Generic filters
Exact matches only
Search in title
Search in content
Search in excerpt
Filter by 分類
網站公告
Featured
赫思醫美
限時免費
Windows 軟件下載
系統軟件
辦公軟件
圖像處理
影音媒體
網絡軟件
應用軟件
Mac 軟件下載
安卓軟件下載
網絡資訊
Mac資訊
Linux資訊
VPS資訊
NASA資訊
WordPress資訊
WeChat資訊
PHP資訊
教學資源
開源程序
網頁工具
SEO工具
醫療健康
其他資訊
Content from
Content to
2018 年 9 月
一 二 三 四 五 六 日
 12
3456789
10111213141516
17181920212223
24252627282930
« 8 月   10 月 »

分類

  • 網站公告
  • 赫思醫美
  • 限時免費
  • Windows 軟件下載
  • 系統軟件
  • 辦公軟件
  • 圖像處理
  • 影音媒體
  • 網絡軟件
  • 應用軟件
  • Mac 軟件下載
  • 安卓軟件下載
  • 網絡資訊
  • Mac資訊
  • Linux資訊
  • VPS資訊
  • NASA資訊
  • WordPress資訊
  • WeChat資訊
  • PHP資訊
  • 教學資源
  • 開源程序
  • 網頁工具
  • SEO工具
  • 醫療健康
  • 其他資訊

彙整

近期文章

  • IGN評歷代超人演員:里夫登頂亨超僅排第五 2025-07-11
  • 足協佈局國足大模型:限價1068萬招標取名為“前進計劃” 2025-07-11
  • RTX 5090原價購買成真NVIDIA發放新一輪優先資格 2025-07-11
  • 服務型遊戲吸走玩家時間分析師稱其威脅大於Game Pass 2025-07-11
  • 科學問答AI哪家強? OpenAI o3奪冠DeepSeek-R1緊跟在後 2025-07-11
  • 曝國行版iPhone 17 Pro新增供應商:京東方供貨 2025-07-11
  • 中科大首次實現小鼠全身「高清全景成像」 單根神經纖維清晰可見 2025-07-11
  • 理想i8上市倒數7月17日預定月底開賣預計35萬起 2025-07-11
  • 本田一代神車思域Type R終極紀念版登場 2025-07-11
  • AI終結傳統軟體產業如同網路終結傳統媒體 2025-07-11

熱門文章與頁面︰

  • 無3C行動電源禁止登機一文看懂到底什麼是3C認證、如何分辨真偽
  • z-sms – 在線免費云短信臨時手機號接碼平台網頁版
  • 您可以在Windows 11 24H2 中找回WordPad
  • 一鍵GHOST v2020.07.20 正式版-硬盤版/光盤版/優盤版/軟盤版
  • 研究人員打造出利用飛鏢發射方式部署傳感器的無人機
  • 曝國行版iPhone 17 Pro新增供應商:京東方供貨
  • YouTube By Click 2.2.86(含:註冊機序列號)
  • 4款家用血糖儀、尿酸儀對比評測
  • CorelDRAW Graphics Suite 2020 v22.1.0.517
  • 中國需要更大太陽能無人機60米級翼展呼之欲出?

投遞稿件

歡迎各界人士投遞稿件到admin@wongcw.com

請提供以下資料:

1.你的名字

2.你的電郵

3.分類目錄

4.文章標題

5.文章摘要

6.文章內容

7.文章來源

 

聯繫我們

查詢,投稿,商務合作:
​admin@wongcw.com
​技術支援:
​support@wongcw.com
​客户服務:
​cs@wongcw.com

QQ群:833641851

赫思醫美

快帆

MALUS

極度掃描

DMCA.com Protection Status

WONGCW 網誌

  • 免責聲明
  • 捐助我們
  • ThemeNcode PDF Viewer
  • ThemeNcode PDF Viewer SC
  • Events

服務器提供

本站使用之服務器由ikoula提供。

聯繫我們

查詢,投稿,商務合作:
​admin@wongcw.com
​技術支援:
​support@wongcw.com
​客户服務:
​cs@wongcw.com

QQ群:833641851

© 2025   All Rights Reserved.