centos7 優化設定 安全 常用套件 腳本
CentOS 7 是一個穩定可靠的 Linux 操作系統,但是在使用時需要進行一些優化設定以達到更好的性能和安全性。以下是一些常用的優化設定、安全和常用套件以及腳本。
- 優化設定
1.1 調整網路設定
編輯 /etc/sysctl.conf,加入以下內容,以提高網路性能和安全性:
net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_keepalive_time = 1200 net.ipv4.tcp_syncookies = 1 net.ipv4.ip_forward = 0 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.all.send_redirects = 0
1.2 調整文件系統設定
編輯 /etc/fstab,將 noatime 和 nodiratime 加入到需要調整的文件系統中,以減少對硬盤的讀寫操作:
UUID=xxx / ext4 defaults,noatime,nodiratime 0 1
1.3 調整記憶體設定
編輯 /etc/sysctl.conf,調整 vm.swappiness 的值為 10,以減少交換分區的使用:
vm.swappiness = 10
- 安全性設定
2.1 安裝 SELinux
SELinux 是一個強制存取控制系統,可以加強系統的安全性。使用以下命令安裝 SELinux:
yum install selinux-policy selinux-policy-targeted
2.2 設定防火牆
CentOS 7 預設使用 firewalld 作為防火牆系統。使用以下命令設定 firewalld 防火牆:
systemctl start firewalld systemctl enable firewalld firewall-cmd --zone=public --add-service=http --permanent firewall-cmd --zone=public --add-service=https --permanent firewall-cmd --reload
- 常用套件
3.1 安裝 Nginx
Nginx 是一個高性能的 Web 伺服器和反向代理伺服器。使用以下命令安裝 Nginx:
yum install nginx
3.2 安裝 MariaDB
MariaDB 是一個 MySQL 的分支,提供更好的性能和安全性。使用以下命令安裝 MariaDB:
yum install mariadb mariadb-server
3.3 安裝 PHP
PHP 是一個流行的伺服器端語言,支援多種資料庫和網路協議。使用以下命令安裝 PHP:
yum install php php-fpm php-mysql
- 腳本
4.1 安裝 LAMP 環境腳本
以下是一個自動安裝 LAMP 環境的腳本:
#!/bin/bash yum install -y httpd systemctl start httpd systemctl enable httpd firewall-cmd --zone=public --add-service=http --permanent firewall-cmd --zone=public --add-service=https --permanent firewall-cmd --reload yum install -y mariadb mariadb-server systemctl start mariadb systemctl enable mariadb mysql_secure_installation yum install -y php php-fpm php-mysql systemctl start php-fpm systemctl enable php-fpm
4.2 安裝 LEMP 環境腳本
以下是一個自動安裝 LEMP 環境的腳本:
#!/bin/bash yum install -y nginx systemctl start nginx systemctl enable nginx firewall-cmd --zone=public --add-service=http --permanent firewall-cmd --zone=public --add-service=https --permanent firewall-cmd --reload yum install -y mariadb mariadb-server systemctl start mariadb systemctl enable mariadb mysql_secure_installation yum install -y php php-fpm php-mysql systemctl start php-fpm systemctl enable php-fpm
以上是 CentOS 7 的優化設定、安全和常用套件以及腳本。使用這些設定和腳本可以提高 CentOS 7 的性能和安全性,並且方便快速地安裝常用的伺服器軟體。
原文地址: https://www.cveoy.top/t/topic/3tY 著作权归作者所有。请勿转载和采集!