rehat-server7常見服務安裝與配置總結

 
 

1、基礎配置

從RHEL7開始,使用systemctl工具來管理服務程序,包括了service和chkconfig [root@rhel7 ~]# systemctl list-unit-files|grep enabled 啓動一個服務: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;echo $? 查看已啓動的服務列表:systemctl list-unit-files|grep enabled 1、安裝 經過iso文件進行安裝,最小安裝時,ifconfig等命令是不可以使用的。能夠經過「ip link show」、「ip address」等命令查看IP地址。 (一)網卡的配置 RedHat7對網卡的命名有了很大不一樣,能夠參考以下命名規則: 本人在虛擬機上安裝RedHat Server7.1後,網卡被命名爲enp0s3,網卡的配置文件爲/etc/sysconfig/network-scripts/ifcfg -enp0s3。所以IP地址、子網掩碼、網關、dns等都可在這個文件中進行配置。下圖展現了一個配置文件:
當前是static(靜態IP地址),若是要使用dhcp,則修改: BOOTPROTO=dhcp ONBOOT=yes #開啓自動啓用網絡鏈接,若是設置爲no,則啓動系統後網卡不能連接 IPADDR=172.28.14.220 #設置IP地址 PREFIX=27 #設置子網掩碼 GATEWAY=172.28.14.193 #設置網關 DNS1=222.172.220.68 #設置主DNS DNS2=xxx.xxx.xxx.xxx #設置備DNS 完成後service network restart #重啓網絡 (二)ssh啓動 #/bin/systemctl start sshd.service (三)添加用戶 #groupadd webmanager ‘添加管理網站的組 ‘添加用戶名爲:webmanager,屬組:webmanage,密碼:nts20080808, 主目錄:/home/website/www.eq.hh.cn #useradd webmanger -g webmanage  –p nts20080808  -d /home/website/www.eq.hh.cn 修改用戶登陸名: #usermod -l webmanager webmanger ‘將用戶名webmanger修改成webmanager 修改用戶webmanger登陸密碼: #passwd webmanger (四)設置iso文件爲本地安裝源 1.上傳iso文件 將radHat Server7的iso文件rhel-server-7.1-x86_64-dvd.iso上傳到服務器的/home/website/download/iso目錄下。 2.掛載iso文件 將iso文件掛載爲/media/cdrom #mkdir /media/cdrom

# cd  /media/cdromphp

#ls   ‘能夠看到鏡像中的文件已經存在了,說明掛載成功css

備註:umount  /media/cdrom  #卸載系統鏡像html

3.設置開機自動掛載系統鏡像文件

vi /etc/fstab   #添加代碼(/home/website……)。實現開機自動掛載node

:wq! #保存退出mysql

備註:iso9660使用df  -T 查看設備linux

4.配置本地yum源

#cd /etc/yum.repos.dnginx

#touch rhel-media.repo    ‘創建yum配置文件c++

#vi rhel-media.repoweb

添加如下內容:sql

[rhel-media]

name=Red Hat Enterprise Linux 7.1   #自定義名稱

baseurl=file:///media/cdrom #本地光盤掛載路徑

enabled=1   #啓用yum源,0爲不啓用,1爲啓用

gpgcheck=1  #檢查GPG-KEY,0爲不檢查,1爲檢查

gpgkey=file:///media/cdrom/RPM-GPG-KEY-redhat-release   #GPG-KEY路徑

以下圖所示:

#:wq  保存退出

5.使用yum安裝軟件

#yum clean all   ‘清除yum緩存

#yum makecache  ‘緩存本地yum源中的軟件包信息

#yum install 軟件包名稱  (如:yum install httpd)

(五)設置本地字符集

#vi  /etc/environment

添加:

LC_ALL=」zh_CN.GBK」

LANG=」zh_CN.GBK」

wq保存退出

#source  /etc/environment

2、SSH升級及配置

(一)升級openssh

系統自帶的openssh是6.6版的,如今準備升級到最新的6.8版。先到openssh下載最新版。

本次安裝須要zlib、openssl庫。所以須要先將這些軟件的最新版上傳到服務器。

1.zlib安裝

先到http://www.gzip.org/zlib/下載最新的zlib-1.2.8.tar.gz安裝包,並上傳到服務器,並解壓。

#tar –zxvf zlib-1.2.8.tar.gz

#./configure - -prefix=/usr/local/zlib1.2.8

#make

#make install

以上命令是將zlib安裝到/usr/local/zlib1.2.8目錄。

2.升級openssl到1.0.2a版本

先到http://www.openssl.org/下載最新的openssl-1.0.2a.tar.gz,上傳到安裝服務器並解壓。

#tar –zxvf openssl-1.0.2a.tar.gz

#cd openssl-1.0.2a

#./config –prefix=/usr/local/openssl1.0.2a --shared

 必定記得加上--shared選項, 不然openssh編譯的時候會找不到新安裝的openssl的library, 會報錯: openssl的 header和library版本不匹配

#make

#make test

#make install

make test(這一步很重要哦!是進行 SSL 加密協議的完整測試,若是出現錯誤就要必定先找出哪裏的緣由,不然一味繼續,可能最終致使 SSH 不能使用,後果很嚴重的!)

vi /etc/profile,添加

PATH=/usr/local/openssl1.0.2a/bin:$PATH

export PATH

添加完成後保存,source /etc/profile

#openssl version –a

能夠看到,openssl已是最新版了。

3. 安裝升級openssh6.8

安裝新版以前先檢測一下系統原來的版本,而後將其刪除。

#rpm –qa | grep openssh

#rpm –e openssh –-nodeps

#rpm –e openssh-clients –nodeps

#rpm –e open-server –nodeps

刪除完成後,到官方網站下載最新的openssh-6.8p1.tar.gz,上傳到服務器並解壓縮。

先將zlib、openssl1.0.2的庫文件路徑添加到庫搜索路徑中。

#echo  「/usr/local/zlib1.2.8/lib」 >>  /etc/ld.so.conf.d/dyninst-x86_64.conf

#echo  「/usr/local/openssl1.0.2a/lib」 >>  /etc/ld.so.conf.d/dyninst-x86_64.conf

#sudo ldconfig     這步很從新,必定不要忘記執行

安裝openssh6.8p1:

#tar –zxvf openssh-6.8p1.tar.gz

#cd openssh-6.8p1

執行配置命令後,顯示:

#make & make install

以上安裝方法是將openssl安裝到/usr/local/openssh6.8.p1目錄下,配置文件是/etc/ssh/sshd_config。

提示沒有sshd這個服務。下面咱們將其添加到service服務中進行管理。

進入用openssh6.8的源文件目錄,即以前解壓的目錄,執行:

#cp –p contrib/redhat/ sshd.init  /etc/init.d/sshd (redhat系統)

#chmod +x /etc/init.d/sshd

#chkconfig --add sshd

通過以上處理,若是仍然不能啓動sshd,則複製libcrypto.so.1.0.0到/usr/lib64/dyninst,不然啓動sshd時會提示找不到這個庫。

#cp  /usr/local/openssl1.0.2a/lib/libcrypto.so.1.0.0  /usr/lib64/dyninst/

#service sshd start  啓動sshd服務。

若是啓動過程沒有反應或沒有成功提示,則vi  /etc/init.d/sshd,將SSHD的值設置爲實際安裝Openssh的目錄。以下:

3、jdk8u45的安裝

#tar  -zxvf  jdk-8u45-linux-x64.tar.gz

#mv  jdk1.8.45  /usr/local

#vi /etc/profile

添加:

JAVA_HOME=/usr/local/jdk1.8.0_45

JRE_HOME=$JAVA_HOME/jre

CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH

PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

Export JAVA_HOME JRE_HOME CLASSPATH PATH

#source /etc/profile

4、MySql5.6.24的安裝與配置

(一)Cmake的安裝

因爲安裝MySql5.6.24須要用到cmake程序,所以須要安裝cmake。到http://www.cmake.org/download/ 下載最新版的cmake-3.2.2.tar.gz,上傳到服務器。

#tar  -zxvf cmake-3.2.2.tar.gz

#cd cmake-3.2.2

若是原來沒有安裝過cmake,則:

#./bootstrap

#gmake

#gmake install

安裝過程當中出現以下錯誤:

缺乏gcc,gcc++環境

#yum –y install gcc

#yum -y install gcc-c++

再次bootstrap,正常了。

若是本機上存在cmake,想安裝一個新版本,則:

#cmake .

#gmake

#gmake install

(二)安裝Mysql-5.6.24

1.源碼安裝Mysql5.6.24

#tar –zxvf mysql-5.6.24.tar.gz

#cd mysql-5.6.24

用源碼編譯安裝Mysql5.6.24:

#cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_DATADIR=/home/mysql/data \

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306    \

-DENABLE_DOWNLOADS=1

此過程當中出現「Curses library not found.  Please install appropriate package,」,說明缺乏curses-devel包,咱們須要安裝它們。下載以下rpm包,注意它們的版本要一致,不然沒法安裝(若是配置了本地yum源,則能夠用:yum –y install ncurses-devel安裝)。

先檢查系統是否安裝有相應的包:

#rpm –qa | grep ncurses

有的話一一刪除。而後再進行安裝

#rpm –ivh ncurses-base-5.9-12.20130511.fc20.noarch.rpm

#rpm –ivh ncurses-libs-5.9-12.20130511.fc20.x86_64.rpm

#rpm –ivh ncurses-devel-5.9-12.20130511.fc20.x86_64.rpm

#rm CMakeCache.txt 刪除以前生成的文件

而後再cmake編譯安裝Mysql5.6.24:

#cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_DATADIR=/home/mysql/data \

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306    \

-DENABLE_DOWNLOADS=1

此次編譯終於經過了。

#make

#make install

注意:若是須要重裝mysql,在/usr/local/src/mysql-5.6.12在執行下make install就能夠了,不須要再cmake和make

2.清除安裝臨時文件

# make clean

3.修改目錄擁有者

# chown -Rf mysql:mysql /usr/local/mysql-5.6.24

# chown -Rf mysql:mysql /home/mysql

4.進入mysql執行程序的安裝路徑

# cd /usr/local/mysql-5.6.24

5.執行初始化配置腳本,建立系統自帶的數據庫和表(注意路徑/home/mysql/data須要換成你自定定義的數據庫存放路徑)

# scripts/mysql_install_db --user=mysql --datadir=/home/mysql/data

執行以上命令時出現:scripts/mysql_install_db: /usr/bin/perl: 壞的解釋器: 沒有那個文件或目錄錯誤,緣由是:系統是64位,而mysql是32位。解決辦法:安裝32位環境,或者安裝64位myql。

或者:yum   -y  install perl perl-devel,再執行scripts/mysql_install_db……,出現如下錯誤提示:

FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:

則yum  -y install perl-Module-*

問題終於解決。

#初始化腳本在/usr/local/mysql/下生成了配置文件my.cnf,須要更改該配置文件的全部者:

# chown -Rf mysql:mysql /usr/local/mysql

注意:

(1)Tips:在啓動MySQL服務時,會按照必定次序搜索my.cnf,先在/etc目錄下找,找不到則會搜索mysql程序目錄下是否有my.cnf";

(2)須要注意CentOS 6.4版操做系統的最小安裝完成後,即便沒有安裝mysql,在/etc目錄下也會存在一個my.cnf文件,建議將此文件改名爲其餘的名字,不然該文件會干擾源碼安裝的MySQL的正確配置,形成沒法啓動。修改/etc/my.cnf操做以下:

# mv /etc/my.cnf /etc/my.cnf.bak

# 固然也能夠刪除掉/etc/my.cnf這個文件:

# rm /etc/my.cnf

(3)若是你須要用於生產環境,不要急着作下面的mysql啓動操做。建議把上一步驟中mysql初始化生成的/usr/local/mysql/mysql.cnf刪除,而後把你優化好的mysql配置文件my.cnf放到/etc下。(這是我作mysql主從複製和mysql優化的經驗!)

6.複製服務啓動腳本

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

7.啓動MySQL服務

# service mysql start

8.設置開機自動啓動服務

# chkconfig mysql on

9.登陸並修改MySQL用戶root的密碼

#vi  /etc/profile

將/usr/local/mysql-5.6.24/bin添加至PATH中。

#source  /etc/profile

# mysql -u root

mysql> use mysql;

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";

mysql> update user set Password = password('123456') where User='root';

mysql> flush privileges;

mysql> exit;

10.檢測下上一步MySQL用戶root密碼是否生效:

[root@yimiju etc]# mysql -u root –pnts20080808

 執行:

再次登陸,輸入正常密碼後終於成功了。

 [root@yimiju ~]# mysql -u root -p

Enter password: ——這裏提示時輸入你設置的mysql root賬號密碼

#登陸成功有以下提示:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 422

Server version: 5.6.12-log Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

11.(可選)運行安全設置腳本,強烈建議生產服務器使用:

[root@yimiju ~]# /usr/local/mysql/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

 

In order to log into MySQL to secure it, we'll need the current

password for the root user.  If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n                   ---------------這裏輸入n

 ... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] Y                   ---------------這裏輸入Y

 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n                         ---------------這裏輸入n

 ... skipping.

By default, MySQL comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] Y                        ---------------這裏輸入Y

 - Dropping test database...

ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist

 ... Failed!  Not critical, keep moving...

 - Removing privileges on test database...

 ... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] Y                          ---------------這裏輸入Y

 ... Success!

All done!  If you've completed all of the above steps, your MySQL

installation should now be secure.

Thanks for using MySQL!

Cleaning up...

12.重啓服務器,檢測mysql是否能開機自動啓動

[root@yimiju ~]# reboot

5、安裝配置Nginx

(一)安裝Nginx

http://nginx.org下載最新的1.9.0版。

#tar –zxvf nginx

注意:

以上配置中的—with-pcre、--with-openssl、--with-zlib後的文件夾是源碼文件夾,不是安裝文件夾,若是改爲安裝文件夾,make時會出現錯誤。

#make

#make install

(二)配置Nginx

#vi /usr/local/nginx-1.9.0/conf/nginx.conf

worker_processes 8    #設置跟cpu核數同樣就行

worker_rlimit_nofile 309600;

events {

        worker_connections  309600;

        use epoll;

}

    server {

        listen       80;

        #server_name  localhost;

             server_name 172.28.14.220; 這裏根據狀況填寫,如www.eq.hh.cn

        charset utf-8;

        #access_log  logs/host.access.log  main;

        location / {

            #配置web站點在服務器上的文件位置

            root /home/website/www.eq.hh.cn;

            index index.html index.htm index.jsp shouye.jsp index.action;

        }

        #動態文件交由resin或tomcat處理

        location ~.(jsp|jspx|action|do)?$ {

            proxy_set_header Host $host;

            proxy_set_header X-Real-IP $remote_addr;

            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_pass http://127.0.0.1:8080;  #resin服務的位置,若是是tomcat也行

        }

        #靜態文件緩存時間

        location ~.*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|docx|ppt|xls|xlsx|mp3|wma)$

        {

            expires 30d;

        }

        location ~.*.(js|css)?$

        {

            expires 1h;

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}

}

6、rhel7的防火牆配置

1.添加tcp端口

#firewall-cmd  --zone=public  --add-port=8080/tcp

以上這種添加的方法只是暫時的,從新啓動系統後無效。添加參數permanent後,能夠變成永久生效。

#firewall-cmd  --zone=public  --permanent  --add-port=8080/tcp

--增長zone public開放http service

[root@localhost zones]# firewall-cmd --zone=public --add-service=http

success

 [root@localhost zones]# firewall-cmd --permanent --zone=internal --add-service=http

success

[root@localhost zones]# firewall-cmd --reload

success

[root@localhost zones]# firewall-cmd --zone=internal --add-port=443/tcp

success

 [root@localhost zones]# firewall-cmd  --zone=internal  --list-services

dhcpv6-client http ipp-client mdns samba-client ssh

防火牆中的一切都與一個或者多個區域相關聯。

配置以後,RHEL 7服務器正常會在公共區域,可是你也許會想將它放置在另外一個網絡配置防火牆訪問。這時使用firewall-cmd –get-default-zone命令,該命令顯示你的服務器在哪個網絡。若是你想查看配置特定網絡的詳細信息,你可使用列表2中的firewall-cmd –zone=zonename –list-all命令。

列表2.

root@rhelserver ~]# firewall-cmd –get-default-zone

public

[root@rhelserver ~]# firewall-cmd –get-zones

  block dmz drop external home internal public trusted work

  [root@rhelserver ~]# firewall-cmd –zone=public –list-all

  public (default, active)

  interfaces: ens33

  sources:

  services: dhcpv6-client sander ssh

  ports:

  masquerade: no

  forward-ports:

  icmp-blocks:

  rich rules:

改變當前區域並不難:使用firewall-cmd –set-default-zone=home命令,該命令可用於從公共網絡到家庭網絡制定一個默認網絡。

服務和其餘構件

在區域中有一些基本的構件塊,其中服務是最重要的。防火牆使用管理員建立在/usr/lib/firewalld/services(系統默認服務) 和/etc/firewalld/services文件下的XML文件,配置的自身服務集。XML文件時經過列表3中的例子建立的。

列表3.

[root@rhelserver services]# cat ftp.xml

<?xml version=」1.0″ encoding=」utf-8″?>

<service>

  <short>FTP</short>

  <description>FTP is a protocol used for remote file transfer. If you plan to make your FTP server publicly available, enable this option. You need the

vsftpd package installed for this option to be useful.</description>

  <port protocol=」tcp」 port=」21″/>

  <module name=」nf_conntrack_ftp」/>

</service>

每個服務定義都須要一個簡短的名字、描述和端口網絡用於指定須要使用的協議、端口和模塊名。

列表4.如下是建立防火牆服務的例子

[root@rhelserver services]# cat sander.xml

<?xml version=」1.0″ encoding=」utf-8″?>

<service>

  <short>Sander</short>

  <description>Sander is a random service to show how service configuration works.</description>

  <port port=」666″ protocol=」tcp」/>

</service>

一旦你有了正確的服務文件,使用如下代碼複製它。firewall-cmd –list-services命令顯示從你服務器上的全部能夠找到的服務列表。若是要增長服務則輸入firewall-cmd –add-service yourservice將服務放到默認網絡上,或者是使用–zone=zonename選擇特定網絡。

下面描述了它如何工做:

1.使用firewall-cmd –zone=public –list-all命令,顯示當前公共區域配置。

  [root@rhelserver ~]# firewall-cmd –zone=public –list-all

  public (default, active)

  interfaces: ens33

  sources:

  services: dhcpv6-client ssh

  ports:

  masquerade: no

  forward-ports:

  icmp-blocks:

  rich rules:

2.命令firewall-cmd –zone=public –add-service=ftp,在Linux防火牆的公共區域上添加FTP服務。

3.重複步驟1檢查FTP服務是否成功添加,你將看到服務列表。

4.重啓服務器,執行步驟1.你將看到FTP服務消失了,在防火牆中,沒有永久的事物,除非你使用了permanent選項。

5.將FTP服務添加到公共網絡上,並設爲永久設置,該步驟使用firewall-cmd  –permanent –zone=public –add-service=ftp命令。重啓以後該設置生效。

6.輸入firewall-cmd –reload提交全部規則同時重載防火牆。使用permanent設置永久防火牆選項是很是重要的。

打破規則

配置防火牆配置服務是推薦的方式,它能夠垂手可得地提供防火牆的全局概覽。可是若是你想在/etc/firewalld/service文件下本身定義服務,在不使用該文件的狀況下也可添加端口。

使用firewall-cmd –permanent –zone=dmz –add-port=22/tcp命令爲特定網絡指定特定端口,而後使用firewall-cmd –zone=dmz –list-all確認端口已成功添加。這種方式是非兼容方式,使用服務使對不一樣的主機分配類似的規則變得簡單。若是沒有服務,文件就很難被分配,配置文件中的規則分配也變得困難。

對於更多的控制,你不可以使用直接規則。緣由以下:

1.輸入firewall-cmd –direct –add-rule ipv4 filter INPUT 0 -p tcp –dport 80 -j ACCEPT

2.如今輸入firewall-cdm –list-all顯示你的默認網絡的配置,端口80沒有添加任何東西。

  [root@rhelserver ~]# firewall-cmd –list-all

  public (default, active)

  Interfaces: ens33

  sources:

  services: dhcpv6-client ftp ssh

  ports:

  masquerade: no

  forward-ports:

  icmp-blocks:

  rich rules:

輸入完以上命令後,HTTP端口並無發生改變,這是由於直接規則寫給了IP信息包過濾器接口,而不是防火牆。

3.輸入firewall-cmd –direct –get-all-rules,或者使用firewall-cmd –direct –get-all-rules顯示直接規則。

相比於直接規則,使用iptables(列表5)命令能夠寫到防火牆裏。

列表5.Linux防火牆規則實例

firewall-cmd–permanent–zone=public–add-rich-rule=」rule family=」ipv4″ source address=」192.168.4.0/24″ service name=」tftp」 log prefix=」tftp」 level=」info」 limit value=」1/m」 accept」

防火牆規則相似於IP信息包過濾防火牆,提供了大量靈活性。

使用列表5中的一條命令就能夠完成和提交許多任務。它指定了IP家族、源地址、服務名等。可是須要注意規則是怎樣處理登錄的:定義一個特定的登錄前綴、登錄等級信息,以及每分鐘傳遞信息的極限值。

Linux管理員能夠申請監測端口的過濾器,因此規則對於IP地址上的過濾器很是有用。(列表6)

列表6.規則申請Linux防火牆IP地址端口的過濾器

firewall-cmd –permanent –zone=public –add-rich-rule=」rule family=」ipv4″ \

   source address=」192.168.0.4/24″ service name=」http」 accept」

分析區域

firewall-cmd命令是衆多配置防火牆的方法之一。兩者擇一的,你能夠直接編寫網絡配置文件。可是若是語法有誤,將不會獲得任何反饋。但這是一個簡潔簡單的配置文件,容易修改和在多個服務器上分配。

列表7.你能夠經過編寫配置文件配置防火牆

<?xml version=」1.0″ encoding=」utf-8″?>

<zone>

  <short>Public</short>

  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>

  <service name=」dhcpv6-client」/>

   <service name=」ssh」/>

   <rule family=」ipv4″>

    <source address=」192.168.4.0/24″/>

    <service name=」tftp」/>

    <log prefix=」tftp」 level=」info」>

    <limit value=」1/m」/>

    </log>

    <accept/>

  </rule>

</zone>

列表7中包含了添加到先前例子中的全部代碼,能夠直接寫入區域配置文件,其中不包含直接規則,由於直接規則有本身的配置文件。

[root@rhelserver firewalld]# cat direct.xml

<?xml version=」1.0″ encoding=」utf-8″?>

<direct>

  <rule priority=」0″ table=」filter」 ipv=」ipv4″ chain=」INPUT」>-p tcp –dport 80 -j ACCEPT</rule>

</direct>

相關文章
相關標籤/搜索