天天看點

Centos7伺服器運維服務系統安裝過程中遇到的問題總結

1.1 作業系統

Centos7伺服器運維服務系統安裝過程中遇到的問題總結

centos伺服器運維

由于我們Sinesafe的客戶要求網站的伺服器要裝Centos7版本是以給大家分享下安裝的過程與經驗,如果需要深入的伺服器運維服務也可以找我們。

機器域名 機器别名

xxx.xxx.xxx.xxx bigdata1 xxx.xxx.xxx.xxx bigdata2 xxx.xxx.xxx.xxx bigdata3

3台機器使用者名和密碼:

使用者名 密碼

root xxxx bigdata xxxxx

1.1.1 裝機注意事項

一、 U盤安裝的時候報錯的解決方案

二、修改/etc/resolv.conf,将配置中的值改成

nameserver 202.xxx.xxx.xx 前面兩個要和測試伺服器上的這兩個nameserver保持一緻

nameserver 202.xxx.xxx.xx 這兩個用于聯網使用

nameserver 8.8.8.8 下面這兩個必須有,否則在使用yum的時候使用不了

nameserver 8.8.4.4

三、修改/etc/sysconfig/network-scprits/ifcfg-*,内容如下:

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="enp3s0"

UUID="xxxxxxxxxxxxxxxxxxxxxxxx"

DEVICE="enp3s0"

ONBOOT="yes"

IPADDR="xxx.xxx.xxx.xxx"

IPADDR1="xxx.xxx.xxx.xxx" #這裡是虛拟ip

PREFIX="24"

GATEWAY="xxx.xxx.xxx.xxx"

IPV6_PRIVACY="no"

DNS1=xxx.xxx.xxx.xxx

DNS2=xxx.xxx.xxx.xxx

DNS3=8.8.8.8

DNS4=8.8.4.4

修改完成之後,執行重新開機網絡配置指令:

service network restart

四、修改hosts,hostname.效果如下:

[root@bigdata3 ~]# cat /etc/hosts (3台伺服器的這個配置一緻)

#127.0.0.1 localhost localhost.localdo:wqmain localhost4 localhost4.localdomain4

#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.18.140 bigdata1

192.168.18.141 bigdata2

192.168.18.142 bigdata3

[root@bigdata3 ~]#

[root@bigdata1 ~]# cat /etc/hostname

bigdata1

[root@bigdata2 ~]# cat /etc/hostname

bigdata2

[root@bigdata3 ~]# cat /etc/hostname

bigdata3

五、為了讓服務能夠被遠端工具連接配接,配置/etc/ssh/sshd_config中監聽的端口和ip位址

Port 22 這裡可以不放開,預設是22端口

PermitRootLogin yes

PasswordAuthentication yes

即:将/etc/ssh下的sshd_config檔案中的,關于監聽端口、監聽位址前的#号去除。

六、centos yum報錯Loaded plugins: fastestmirror

vim /etc/yum/pluginconf.d/fastestmirror.conf

enabled = 0

vim /etc/yum.conf

plugins=0

yum clean dbcache

如果發現還是不可以使用yum指令安裝各種軟體,這時候說明是DNS的配置有問題

解決辦法是:

A:修改vim /etc/sysconfig/network-scripts/ifcfg-eth

添加如下内容:

ONBOOT=yes

MM_CONTROLLED=no 這個若沒有添加上去

DNS1=8.8.8.8

DNS2=8.8.4.4

上面的dns名稱不能重複

同時在/etc/resolv.conf中添加:

nameserver 8.8.8.8

然後重新開機項目即可

六、安裝wget

yum –y install wget

七、更新安裝vim,安裝vim增強包

yum –y install vim-enhanced

八、解決netstat:command not found問題

yum install net-tools

九、Centos7防火牆配置:

将預設Firewall改為iptables防火牆

關閉firewall:

service network restart #重新開機網絡

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止Firewall開啟啟動

firewall-cmd –state #檢視預設防火牆狀态(關閉後顯示notrunning,開啟後顯示running)

配置iptable防火牆

vi /etc/sysconfig/iptables #編輯防火牆配置檔案

# sampleconfiguration for iptables service

# you can edit thismanually or use system-config-firewall

# please do not askus to add additional ports/services to this default configuration

*filter <!-- 本行請檢視下面備注-->

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT[0:0]

:OUTPUT ACCEPT[0:0]

-A INPUT -m state--state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p icmp -jACCEPT

-A INPUT -i lo -jACCEPT

-A INPUT -p tcp -mstate --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -jACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080-j ACCEPT

-A INPUT -j REJECT--reject-with icmp-host-prohibited

-A FORWARD -jREJECT --reject-with icmp-host-prohibited

COMMIT

:wq! #儲存退出

備注:這裡使用80和8080端口為例

filter

以上部分一般添加到下行的上面或者下面

切記不要添加到最後一行,否則防火牆重新開機後不生效

systemctl restart iptables.service #最後重新開機防火牆使配置生效systemctl enable iptables.service #設定防火牆開機啟動

它防火牆參數配置:

其修改防火牆配置檔案之前,需要對之前防火牆做好備份

重新開機防火牆後,需要确認防火牆狀态和防火牆規則是否加載,若重新開機失敗或規則加載失敗,則所有請求都會被防火牆

firewall-cmd --state

#檢視firewall的狀态

firewall-cmd --list-all

#檢視防火牆規則(隻顯示/etc/firewalld/zones/public.xml中防火牆政策)

firewall-cmd --list-all-zones

#檢視所有的防火牆政策(即顯示/etc/firewalld/zones/下的所有政策)

firewall-cmd --reload

#重新加載配置檔案

2、關閉firewall:

systemctl disable firewalld.service #禁止firewall開機啟動

firewall-cmd --state #檢視預設防火牆狀态(關閉後顯示notrunning,開啟後顯示running)

1、firewalld的基本使用

啟動: systemctl start firewalld

檢視狀态: systemctl status firewalld

停止: systemctl disable firewalld

禁用: systemctl stop firewalld

2.systemctl是CentOS7的服務管理工具中主要的工具,它融合之前service和chkconfig的功能于一體。

啟動一個服務:systemctl start firewalld.service

關閉一個服務:systemctl stop firewalld.service

重新開機一個服務:systemctl restart firewalld.service

顯示一個服務的狀态:systemctl status firewalld.service

在開機時啟用一個服務:systemctl enable firewalld.service

在開機時禁用一個服務:systemctl disable firewalld.service

檢視服務是否開機啟動:systemctl is-enabled firewalld.service

檢視已啟動的服務清單:systemctl list-unit-files|grep enabled

檢視啟動失敗的服務清單:systemctl --failed

3.配置firewalld-cmd

檢視版本: firewall-cmd --version

檢視幫助: firewall-cmd --help

顯示狀态: firewall-cmd --state

檢視所有打開的端口: firewall-cmd --zone=public --list-ports

更新防火牆規則: firewall-cmd --reload

檢視區域資訊: firewall-cmd --get-active-zones

檢視指定接口所屬區域: firewall-cmd --get-zone-of-interface=eth0

拒絕所有包:firewall-cmd --panic-on

取消拒絕狀态: firewall-cmd --panic-off

檢視是否拒絕: firewall-cmd --query-panic

那怎麼開啟一個端口呢

添加firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,沒有此參數重新開機後失效)

重新載入firewall-cmd --reload

檢視firewall-cmd --zone= public --query-port=80/tcp

删除firewall-cmd --zone= public --remove-port=80/tcp --permanent

因為在/usr/lib/firewalld/services/中事先定義了ssh.xml的相應的規則

十、關閉selinux

關閉selinux:修改/etc/selinux/config檔案中的SELINUX="" 為 disabled ,然後重新開機

1.2 下載下傳軟體

軟體清單:

jdk-8u73-linux-x64.tar.gz Java JDK1.8+環境

apache-maven-3.3.9-bin.tar.gz Maven安裝檔案

apache-tomcat-8.5.12.tar.gz Tomcat安裝包

MySQL-5.7.21-linux-glibc2.12-x86_64.tar.gz MySQL5.7

zookeeper-3.4.11.tar.gz Zookeeper安裝軟體

hadoop-3.0.0.tar.gz Hadoop安裝軟體

apache-hive-2.3.2-bin.tar.gz 資料倉庫之hive

apache-flume-1.8.0-bin.tar.gz 日志收集架構二進制

sqoop-1.4.7.tar.gz 關系型資料庫和hdfs資料之間轉換的工具

apache-storm-1.2.1.tar.gz 實時資料處理之storm安裝包

azkaban-master-source.zip 任務排程所需的源碼包

spark-2.3.0-bin-hadoop2.7.tgz Spark之針對hadoop2.7版本的安裝包

scala-2.13.0-M3.zip Spark編寫所需的scala語言包

hbase-1.4.2-bin.tar.gz Hbase安裝包

elasticsearch-6.2.2.rpm ES之Linux rpm安裝包

elasticsearch-6.2.2.tar.gz ES值Linux tar安裝包

logstash-6.2.2.rpm ELK之logstash日志收集架構

logstash-6.2.2.tar.gz ELK之logstash日志收集架構tar包

kibana-6.2.2-linux-x86_64.tar.gz ELK套件之視圖展示用架構

kibana-6.2.2-x86_64.rpm ELK套件之視圖展示用架構rpm安裝包

redis-3.2.9.tar.gz redis安裝包

kylin Apache Kylin™是一個開源的分布式分析引擎,提供Hadoop/Spark之上的SQL查詢接口及多元分析(OLAP)能力以支援超大規模資料

presto Presto是一個開源的分布式SQL查詢引擎,适用于互動式分析查詢,資料量支援GB到PB位元組.

Presto的設計和編寫完全是為了解決像Facebook這樣規模的商業資料倉庫的互動式分析和處理速度的問題

1.3 上傳安裝包

将安裝檔案上傳到:/home/bigdata/software

1.4 3台伺服器間的免密登入

在bigdata1、bigdata2、bigdata3下執行:

ssh-keygen -t rsa (這個過程中一緻打enter)

ssh-copy-id bigdata1

ssh-copy-id bigdata2

ssh-copy-id bigdata3

執行完成上面的指令之後,分别bigdata1、bigdata2、bigdata3上執行:

ssh bigdata1

ssh bigdata2

ssh bigdata3

按照如果最後能夠免密碼登入進去,說明免密登入成功

1.5 搭建ntp時間伺服器

讓Linux上的時間和網絡時間保持一緻,避免一些時間不一緻的問題(必須在root指令下執行)

[root@bigdata1 ~]# yum install -y ntp

[root@bigdata1 ~]# ntpdate pool.ntp.org && hwclock -w

1.6 常見指令

檢視常見指令

檢視機器上運作端口

netstat –tunlp

檢視某個端口運作在哪個位置

ps –ef | grep PID (PID即上面netstat –tunlp中檢視出來的PID)

centos7下檢視哪些端口開放了

firewall-cmd –list-ports

防火牆開放端口:

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

指令含義:

–zone #作用域

–add-port=80/tcp #添加端口,格式為:端口/通訊協定

–permanent #永久生效,沒有此參數重新開機後失效

firewall-cmd --reload #重新開機firewall

通過iptables的方式檢視開放的端口:

/etc/init.d/iptables status

檢視某個檔案夾下含有某個字元串的指令:

grep -rl 'mysqld' ./

安裝telnet

[root@bigdata3 ~]# yum install net-tools

專注于安全領域 解決網站安全 解決網站被黑 網站被挂馬 網站被篡改

網站安全、伺服器安全提供商-www.sinesafe.com --專門解決其他人解決不了的網站安全問題.