##########################firewall 防火墻常用命令#######################
1、firewalld的基本使用
啟動: systemctl start firewalld
查看狀態: systemctl status firewalld?
停止: systemctl disable firewalld
禁用: systemctl stop firewalld
2.systemctl是CentOS7的服務管理工具中主要的工具,它融合之前service和chkconfig的功能于一體。
啟動一個服務:systemctl start firewalld.service
關閉一個服務:systemctlstop firewalld.service
重啟一個服務:systemctlrestart firewalld.service
顯示一個服務的狀態:systemctlstatus firewalld.service
在開機時啟用一個服務:systemctlenable firewalld.service
在開機時禁用一個服務:systemctldisable firewalld.service
查看服務是否開機啟動:systemctlis-enabled firewalld.service
查看已啟動的服務列表:systemctllist-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
查看firewall是否運行,下面兩個命令都可以
systemctl status firewalld.service
firewall-cmd --state
查看當前開了哪些端口
其實一個服務對應一個端口,每個服務對應/usr/lib/firewalld/services下面一個xml文件。
firewall-cmd --list-services
查看還有哪些服務可以打開
firewall-cmd --get-services
查看所有打開的端口:?
firewall-cmd --zone=public --list-ports
更新防火墻規則:?
firewall-cmd --reload
####################################################
#####################安裝semanage####################
yum install semanage ?//錯誤執行下一句
yum provides semanage //這會顯示對應的版本
yum install policycoreutils-python //安裝上一條對應的版本
############################################
#######################更改SSH遠程密碼和默認端口##############
一 更改遠程連接密碼
[root@localhost ~]# passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
二 更改默認端口
使用 root 用戶進入 /etc/ssh/ 目錄:
?cd /etc/ssh/
使用 vi/vim 打開 sshd_config 文件:?
vim sshd_config
在修改端口之前,先添加一個端口,找到 Port 進行修改
# Port 22
Port 10022 ?//表示添加10022 為新端口
修改之后,進行保存
向防火墻中添加修改的端口
firewall-cmd --zone=public --add-port=10022/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --query-port=10022/tcp
向SELinux中添加修改的SSH端口
查看當前ssh的端口
semanage port -l | grep ssh
向 SELinux 中添加 ssh 端口:?
semanage port -a -t ssh_port_t -p tcp 10022
驗證 ssh 端口是否添加成功
semanage port -l | grep ssh
添加成功之后就可以重啟 ssh 服務了
systemctl restart sshd.service
############################################
#########################安裝apache2.4###############
安裝
yum install httpd -y
rpm -qa httpd
啟動
systemctl start httpd.service
虛擬主機配置文件
<VirtualHost *:80>
? ? ServerAdmin admin@amsilence.com
? ? DocumentRoot "/var/www/html/"
? ? ServerName blog.dduan.com
? ? ErrorLog "/var/log/httpd/logs/error_log"
? ? CustomLog "/var/log/httpd/logs/access_log" common
</VirtualHost>
<Directory /var/www/html/>
Require all granted
</Directory>
httpd進程數查詢,prefork模式修改apache最大連接數
ps aux |grep -v grep|grep httpd |wc -l
top -bn 1 |grep httpd |wc -l
都可以查看httpd并發請求進程數(正在處理的進程數)
top -bn 1 |grep httpd |awk '{print $6}'查看每個請求使用內存大小,第六列占用物理內存大小
top -bn 1 |grep httpd |awk '/httpd/{sum+=$6;n++};END{print sum/n}'
查看平均每個請求占用的內存大小,單位是Kb
計算最大httpd請求數,(總內存-系統500M左右)/單個請求占用內存=最大連接數
netstat -an |grep 80 |wc -l
查看與httpd服務建立的tcp連接數
httpd -l
apachectl -l ? ?(apache2.4版本以后,這兩條命令不會顯示prefork模式,需用下兩條命令判斷)
httpd -V
都可以查看apache的運行模式(下有PS介紹apache三種運行模式,workeer,prefork,events)
httpd -M ? ?可以查看apache加載的模塊
httpd -M |grep prefork ?可以查看某個模塊加載詳情。
以prefork模式為例(linux默認prefork,默認最大連接數250)
vim /etc/httpd/conf.modules.d/00-mpm.conf
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
<IfModule mpm_prefork_module>
StartServers ? ? ? ? ?5 #推薦設置:小=默認 中=20~50 大=50~100
MinSpareServers ? ? ? 5 #推薦設置:與StartServers保持一致
MaxSpareServers ? ? ?10 #推薦設置:小=20 中=30~80 大=80~120?
MaxClients ? ? ? ? ?150 #推薦設置:小=500 中=500~1500 大型=1500~3000
ServerLimit ? ? ? ? ?150 ?#該參數最好與MaxClients的值保持一致
MaxRequestsPerChild ? 0 #推薦設置:小=10000 中或大=10000~500000
</IfModule>
#######################################################
#########################安裝php7.2######################
配置YUM源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
1 清理小工作
yum -y remove php*
2 豪華配置安裝php
yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-pecl-redis
3 啟動php-fpm服務
systemctl enable php-fpm.service
systemctl start php-fpm.service
常用命令
systemctl stop php-fpm.service ?
systemctl restart php-fpm.service
####################################################
########################centos 下安裝 Let’s Encrypt 永久免費 SSL 證書##############################
1安裝git?
yum -y install git
2 請求程序包,并進入包
git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
chmod +x letsencrypt-auto
3 安裝證書:
./letsencrypt-auto certonly --email 郵箱 -d 網址
4 配置apache https
<VirtualHost *:443>
?DocumentRoot "/home/www"
?ServerName x.xxxxx.com
?SSLEngine on
?SSLCertificateFile /etc/letsencrypt/live/x.xxxx.com/fullchain.pem //之前生成的證書
?SSLCertificateKeyFile /etc/letsencrypt/live/x.xxxxxx.com/privkey.pem //之前生成的密鑰
?<Directory "/home/www">
?Options FollowSymLinks ExecCGI
?AllowOverride All
?Order allow,deny
?Allow from all
Require all granted
?</Directory>
</VirtualHost>
重啟apache
systemctl restart httpd.service
#######################################################################
————————————————
版權聲明:本文為CSDN博主「weixin_41647577」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/weixin_41647577/article/details/98660498