一、安裝與配置
1、系統安裝
# 下載 CentOS 6.7 DVD iso 文件,將其寫入光碟
# 或者使用 dd 命令將其寫入 USB 設備
$ wget -c http://mirrors.aliyun.com/centos/6.7/isos/x86_64/CentOS-6.7-x86_64-bin-DVD1.iso
$ dd if=CentOS-6.7-x86_64-bin-DVD1.iso of=/dev/sdb bs=1M
2、yum 源配置
# 修改 /etc/yum.repos.d/CentOS-Base.repo 文件
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
3、SELinux 配置
# 關閉 SELinux
$ setenforce 0
$ vim /etc/selinux/config
SELINUX=disabled
二、常用的命令與工具
1、yum 命令
# 安裝 nginx
$ yum install nginx
# 搜索包
$ yum search mysql
# 清理緩存
$ yum clean all
2、iptables 命令
# 查看規則
$ iptables -L
# 允許 80 埠流量
$ iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# 允許 443 埠流量
$ iptables -A INPUT -p tcp --dport 443 -j ACCEPT
3、常用工具
# 安裝 net-tools 以便使用 ifconfig 命令
$ yum install net-tools
# 安裝 vim
$ yum install vim
# 安裝 wget
$ yum install wget
三、服務搭建與配置
1、LAMP 環境搭建
# 安裝 apache
$ yum install httpd
# 啟動 apache
$ service httpd start
# 安裝 mysql
$ yum install mysql mysql-server
# 啟動 mysql
$ service mysqld start
# 安裝 php
$ yum install php php-mysql php-gd
# 測試 php
$ vim /var/www/html/phpinfo.php
# 在瀏覽器中訪問 http://localhost/phpinfo.php
2、Nginx + PHP 環境搭建
# 安裝 nginx
$ yum install nginx
# 啟動 nginx
$ service nginx start
# 安裝 php-fpm
$ yum install php-fpm
# 啟動 php-fpm
$ service php-fpm start
# 配置 nginx
$ vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
# 測試 php
$ vim /usr/share/nginx/html/index.php
# 在瀏覽器中訪問 http://localhost
四、安全加固
1、SSH 安全
# 修改 SSH 配置文件
$ vim /etc/ssh/sshd_config
# 禁用 root 登錄
PermitRootLogin no
# 限制登錄用戶
AllowUsers user1 user2
# 禁用密碼登錄
PasswordAuthentication no
# 生成新的 ssh 公鑰
$ ssh-keygen -t rsa -b 4096
2、防火牆策略
# 只允許 80/443/22 埠
$ iptables -A INPUT -p tcp -m multiport --dports 80,443,22 -j ACCEPT
$ iptables -A INPUT -p tcp -j DROP
3、禁用不必要的服務
# 查看運行的服務
$ service --status-all
# 禁用服務
$ chkconfig servicename off
五、系統維護與優化
1、常用系統命令
# 查看系統負載
$ uptime
# 查看 CPU 信息
$ cat /proc/cpuinfo
# 查看內存使用情況
$ free -m
2、磁碟清理
# 查看磁碟使用情況
$ df -h
# 清理 yum 緩存
$ yum clean all
# 清理日誌文件
$ find /var/log -type f -exec truncate {} --size 0 \;
3、性能優化
# 調整內核參數
$ vim /etc/sysctl.conf
# 關閉無用的網路介面
$ vim /etc/sysconfig/network-scripts/ifcfg-eth0
# 升級軟體包
$ yum update
本文介紹了 CentOS 6.7 的安裝、配置、命令與工具、服務搭建與配置、安全加固以及系統維護與優化等多個方面。其中包括了常用的系統命令、yum 命令、iptables 命令、Net-tools 工具、SSH 安全、防火牆策略、性能優化等內容。希望本文能夠幫助讀者更好地管理 CentOS 6.7 系統。
原創文章,作者:VSBKL,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/371069.html