网站建设公司怎么样,网站维护能自己做吗,网站权重不够高 导致,php做网站需要啥技术我们刚接手一台刚安装好服务器系统之后#xff0c;可以对系统进行一些基础优化#xff1a;
常规设定#xff1a;
centos:
1.关闭 iptables
2.关闭 selinux
3.设定 ChronyUbuntu:
4. /etc/security/limits.conf
5. /etc/sysctl.conf1.首先使用国内阿里云的yum源#xff08…我们刚接手一台刚安装好服务器系统之后可以对系统进行一些基础优化
常规设定
centos:
1.关闭 iptables
2.关闭 selinux
3.设定 ChronyUbuntu:
4. /etc/security/limits.conf
5. /etc/sysctl.conf1.首先使用国内阿里云的yum源默认是国外的yum源仓库 中间会经过很多路由器到国内所速度慢效率不高所以换成国内的 把原来官方默认的源先不要删除做个备份; 或者直接再写个repo源再清除重新生成新的缓存
[rootclient7 ~]# cd /etc/yum.repos.d
[rootclient7 yum.repos.d]# mkdir backup
[rootclient7 yum.repos.d]# mv *.backup
[rootclient7 yum.repos.d]# ll
total 4
drwxr-xr-x. 2 root root 220 Mar 20 2021 backup
-rw-r--r--. 1 root root 2552 Mar 20 2021 base.repo[rootclient7 yum.repos.d]# cat base.repo
[base]
namebase
baseurlhttps://mirrors.aliyun.com/centos/$releasever/os/$basearch/ https://mirrors.huaweicloud.com/centos/$releasever/os/$basearch/ https://mirrors.cloud.tencent.com/centos/$releasever/os/$basearch/https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/http://mirrors.163.com/centos/$releasever/os/$basearch/http://mirrors.sohu.com/centos/$releasever/os/$basearch/
gpgcheck1
gpgkeyfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever[epel]
nameepel
baseurlhttps://mirrors.aliyun.com/epel/$releasever/$basearch/https://mirrors.huaweicloud.com/epel/$releasever/$basearch/https://mirrors.cloud.tencent.com/epel/$releasever/$basearch/https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/$basearch/
gpgcheck1
gpgkeyhttps://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-$releasever[extras]
nameextras
baseurlhttps://mirrors.aliyun.com/centos/$releasever/extras/$basearch/https://mirrors.huaweicloud.com/centos/$releasever/extras/$basearch/https://mirrors.cloud.tencent.com/centos/$releasever/extras/$basearch/https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/http://mirrors.163.com/centos/$releasever/extras/$basearch/http://mirrors.sohu.com/centos/$releasever/extras/$basearch/
gpgcheck1
gpgkeyfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever[updates]
nameupdates
baseurlhttps://mirrors.aliyun.com/centos/$releasever/updates/$basearch/https://mirrors.huaweicloud.com/centos/$releasever/updates/$basearch/https://mirrors.cloud.tencent.com/centos/$releasever/updates/$basearch/https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/http://mirrors.163.com/centos/$releasever/updates/$basearch/http://mirrors.sohu.com/centos/$releasever/updates/$basearch/
gpgcheck1
gpgkeyfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever[centosplus]
namecentosplus
baseurlhttps://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/https://mirrors.huaweicloud.com/centos/$releasever/centosplus/$basearch/https://mirrors.cloud.tencent.com/centos/$releasever/centosplus/$basearch/https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/http://mirrors.163.com/centos/$releasever/centosplus/$basearch/http://mirrors.sohu.com/centos/$releasever/centosplus/$basearch/
gpgcheck1
gpgkeyfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever2.安装常用的软件工具包
CentOS: 存在即忽略 yum install -y tree nmap sysstat gcc gcc-c make telnet lrzsz tree screen tmux man-pages strace tmux man-pages strace autoconf glibc glibc-devel pcre pcre-devel openssl openssl-devel mailx systemd-devel zlib-devel vim lsof tcpdump net-tools bc bzip2 zip unzip nfs-utils apr* redhat-rpm-config bash-completion bash-completion epel-release chrony dos2unix wgetUbuntu: 存在即忽略apt purge ufw lxd lxd-client lxcfs liblxc-commonapt install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev vim ntpdate traceroute gcc g make libsensors4 openssh-server iotop unzip zip3.关闭SELinux
SELinux 是什么
Security-Enhanced Linux是由美国国家安全局NSA和Linux社区共同开发的它是一种访问控制体系在这种访问控制体系下进程只能访问进程任务中需要的文件。因为Linux中的权限管理是针对文件的而不是针对进程所以root启动了某个进程这个进程是可以操作任何文件而seLinux在Linux文件权限之外增加了对进程的进程的限制蓑衣进程只能在进程允许的范围内进行操作。-临时关闭SElinux可在命令行执行如下命令
[rootClient7 ~]# setenforce #表示 0启动1关闭
usage: setenforce [ Enforcing | Permissive | 1 | 0 ][rootClient8 ~]# getenforce #[| 1 | 0 ]
setenforce: SELinux is disabled说明数字0表示Permissive相当于disabled ;数字1表示开启selinux
提示修改配置SELinux后要想使生效必须要重启系统。因此可配合使用 setenforce 0 这个临时关闭
命令这样在重启前后都可以使得SELinux关闭生效了也就是无需立刻重启服务器了因为在生产环境下Linux服务器不能随意重启- 修改配置文件使得关闭SELinux永久生效
vim /etc/selinux/config 修改#SELINUXenforcing改为SELINUXdisabled,即可
sed -i s/enforcing/disabled/g /etc/selinux/config4.修改网卡名ens33 为标准网卡名称 eth0
[rootCentos7 ~]# cat /etc/default/grub #修改完网卡参数后增加内核参数
GRUB_TIMEOUT5
GRUB_DISTRIBUTOR$(sed s, release .*$,,g /etc/system-release)
GRUB_DEFAULTsaved
GRUB_DISABLE_SUBMENUtrue
GRUB_TERMINAL_OUTPUTconsole
GRUB_CMDLINE_LINUXcrashkernelauto spectre_v2retpoline rd.lvm.lvcentos/root net.ifnames0 biosdevname0 rd.lvm.lvcentos/swap rhgb quiet
GRUB_DISABLE_RECOVERYtrue
[rootCentos7 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg #运行命令5.关闭防火墙 关闭防火墙的目的 是为了初学者学习更方便将来学了iptables技术后再统一开启。再企业实际环境中一般配置外网IP的Linux服务器才需要开启防火墙但即使有外网IP对于高并发高流量的业务服务器仍然不能开启因为会有较大性能损失会导致网站访问很慢这种情况只能在前端加更好的硬件防火墙了。
[rootqll251 ~]# iptables -F
[rootqll251 ~]# /etc/init.d/iptables stop
iptables将链设置为政策 ACCEPTfilter [确定]
iptables清除防火墙规则 [确定]
iptables正在卸载模块 [确定][rootqll251 ~]# chkconfig iptables off
[rootqll251 ~]# service iptables stop
-----------------------------------
或者版本6
1\关闭防火墙永久生效重启后不能复原:
永久关闭chkconfig iptables off 永久开启chkconfig iptables on
查看状态chkconfig --list iptables2\即时生效重启后能复原:
关闭service iptables stop 开启service iptables start
重启service iptables restart 查看service iptables status版本7
1\暂时关闭防火墙 2\永久关闭防火墙
systemctl stop firewalld systemctl disable firewalld
3\重启防火墙 4\永久关闭后重启
systemctl enable firewalld chkconfig iptables on //暂时还没有试过 版本8
1\永久禁用CentOS 8中的防火墙 2\验证防火墙状态是否已经被永久关闭systemctl disable firewalld systemctl status firewalld
3\ 屏蔽防火墙守护进程服务systemctl mask --now firewalld开启/关闭ubuntu防火墙方法
先安装sudo apt-get install ufw
使用方法:
启用sudo ufw enable 或者 sudo ufw default deny
关闭sudo ufw disable 查看状态sudo ufw status(inactive状态是防火墙关闭状态active是开启状态)精简集开机系统启动的服务 Linux 服务器在运行过程中会有很多默认的服务在运行而且这些服务通常是没有用的这些服务占用了系统资源严重存在安全隐患可以关闭这些没用的服务。 A、但是系统必须开启的这五项服务 1sshd:远程连接服务必须需要开启要不然无法远程连接Linux。 2crond: 定时任务非必须但是很重要一次性计划任务at 周期计划任务crontab 3rsyslog:是操作系统中提供的一种机制系统的守护程序通常会使用rsyslong将各种信息写到系统日志文件中 4sysstat:该服务包括监控系统性能及效率的一组工具。这些工具对于收集系统的性能数据很有帮助核心工具包ostat:cpu使用率及硬盘吞吐效率工具、 mpstat:提供单个或者多个处理器的数据、 sar负责收集报告并存储系统活跃的信息 、network系统启动时若想关闭或者激活各个网络接口就必须启动该服务 5**network**系统启动时若想关闭或者激活各个网络接口就必须启动该服务 . chkconfig 是管理系统服务(service)的命令行工具。所谓系统服务(service)就是随系统启动而启动随系统关闭而关闭的程序。
chkconfig --list ; egrep -v sshd;network;rsyslog;sysstat;crond ;grep 3:on ;awk{print chkconfig,$1,off};bash
或 chkconfig --list | grep 3:on | grep -vE sshd|rsyslog|network|crond|sysstat | awk {print chkconfig,$1,off} | bash验证以上5个服务是否开机自启
chkconfig --list ; egrep sshd;network;rsyslong;sysstat;crondB、删除特殊的用户和用户组 Linux当中有很多系统默认的用户是可以删除的可以删除的用户组adm.lp,news, uucp,games,dip 等。
# head -n 13 /etc/passwd |tail -n 10adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin7.最小化原则安装 最小化原则 对Linux系统安全来说极其重要具体包括如下几个基本方面
*安装Linux系统最小化即选包最小化yum安装软件包也要最小化无用的包不装
*开机自启动服务最小化即无用的服务不开启。
*操作命令最小化。例如能用“rm -f test.txt” 就不用“rm -fr test.txt”.
*登陆linux用户最小化。平台没有特殊需求不登陆root用普通用户登录即可。
*普通用户授权权限最小化即只给用户必须的管理系统的命令不能啥都可以干。
*Linux系统文件及目录的权限设置最小化禁止随意创建更改删除文件
*程序服务运行最小化即程序服务运行应尽量不用root身份运行。8.更改SSH服务端远程登录的配置 #vi /etc/ssh/sshd_config 配置完sshd生效 /etc/init.d/sshd restart service sshd restart systemctl restart sshd.service
参数说明
(1#Port 22 端口不要使用22 Port 端口号默认是22,我们可以随意改但尽量不要使用0到1024之间的端口号因为port的取值范围是 0 - 65535(即2的16次方)这里我改为了10680。
(2#UseDNS no 是否使用DNS默认yes,设置为no之后登录速度会快
(3#PermitRootLogin no //设置不允许root登录PermitRootLogin 是否允许使用ssh服务root登录默认yes改为no。
(4#GSSAPIAuthentication no //解决ssh链接慢的问题
(5#PasswordAuthentication yes //密码验证是必须的默认yes
(6#PermitEmptyPasswords no //检查空密码是否允许登录PermitEmptyPasswords 是否允许空密码默认no
(7#LoginGraceTime 2m //当使用者连接上ssh server的时候会出现输入密码的画面在这个画面中多久没有成功连接上就强迫断线9.设置Linux服务器的时间同步
1.傻瓜式定时任务配置
echo */5 * * * * /usr/sbin/ntpdate time.nist.gov /dev/null 21 /var/spool/cron/root2.chrony.conf 文件加入公共时钟
rootcentos8 ~]#vi /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
尾部添加 格式server XXXXX iburst
server ntp.aliyun.com iburst
server time.cloud.tencent.com iburst
server 210.72.145.44 iburst10.加大服务器文件描述符 简单说在Unix/Linux里面你的服务只要开启了一个进程就要占用文件描述符的。Linux默认为1024.如果描述符少了访问量多了你的服务器是支撑不了所以要把描述符加大。
#临时修改文件
[rootCentOS8 ~]#ulimit -n
1024
[rootCentOS8 ~]#ulimit -HSn 65535
[rootCentOS8 ~]#ulimit -n
65535#永久修改需要改配置文件 vim /etc/security/limits.conf这里直接追加即可echo * - nofile 65535/etc/security/limits.conf
tail -l /etc/security/limits.conf #这里不用ulimit -n tail显示尾端
#* soft core 0
#* hard rss 10000
#student hard nproc 20
#faculty soft nproc 20
#faculty hard nproc 50
#ftp hard nproc 0
#student - maxlogins 4# End of file
* - nofile 65535
[rootUbuntu1804 ~#logout #注销重新启用账户11、禁止ping
echo net.ipv4.icmp_echo_ignore_all 1 /etc/sysctl.conf
sysctl -p12.设置命令行提示符颜色以区分生产环境和测试环境
echo PS1\[\e[1;33m\][\u\h \W]\\$\[\e[0m\] /etc/profile.d/env.sh
source /etc/profile.d/env.sh13、将服务器新加普通用户及强密码
用户密码一般情况下要求大于8位数尽量使用强密码含有数字大小写及特殊符号三部分组成。尽量不使用root用户登录避免权限过大可以把普通用户变为root用户
useradd gaosh 例如 增加个普通用户gaosh
passwd gaosh ; 已创建的用户gaosh设置密码#修改 /etc/passwd文件
root限制登录
root:x:0:0:root:/root:/bin/bash
改为
root:x:0:0:root:/root:/sbin/nologin #普通用户改为root用户
gaosh:x:1012:1010::/home/gaosh:/bin/bash
改为
gaosh:x:0:0::/home/gaosh:/bin/bash 14.隐藏Linux版本信息 系统版本信息的保存位置
#cat /etc/issue
CentOS Linux release 8.2.2004 (Core)
\S
Kernel \r on an \m
#cat /etc/issue.net
CentOS Linux release 8.2.2004 (Core)
\S
Kernel \r on an \m
所以执行以下命令清除系统版本信息
# /etc/issue
# /etc/issue.net15.内核参数优化 关于CentOS7
# cat /etc/sysctl.conf
#CTCDN系统优化参数#关闭ipv6
net.ipv6.conf.all.disable_ipv6 1
net.ipv6.conf.default.disable_ipv6 1# 避免放大攻击
net.ipv4.icmp_echo_ignore_broadcasts 1# 开启恶意icmp错误消息保护
net.ipv4.icmp_ignore_bogus_error_responses 1#关闭路由转发
net.ipv4.ip_forward 0
net.ipv4.conf.all.send_redirects 0
net.ipv4.conf.default.send_redirects 0#开启反向路径过滤
net.ipv4.conf.all.rp_filter 1
net.ipv4.conf.default.rp_filter 1#处理无源路由的包
net.ipv4.conf.all.accept_source_route 0
net.ipv4.conf.default.accept_source_route 0#关闭sysrq功能
kernel.sysrq 0#core文件名中添加pid作为扩展名
kernel.core_uses_pid 1# 开启SYN洪水攻击保护
net.ipv4.tcp_syncookies 1#修改消息队列长度
kernel.msgmnb 65536
kernel.msgmax 65536#设置最大内存共享段大小bytes
kernel.shmmax 68719476736
kernel.shmall 4294967296#timewait的数量默认180000
net.ipv4.tcp_max_tw_buckets 6000
net.ipv4.tcp_sack 1
net.ipv4.tcp_window_scaling 1
net.ipv4.tcp_rmem 4096 87380 4194304
net.ipv4.tcp_wmem 4096 16384 4194304
net.core.wmem_default 8388608
net.core.rmem_default 8388608
net.core.rmem_max 16777216
net.core.wmem_max 16777216#每个网络接口接收数据包的速率比内核处理这些包的速率快时允许送到队列的数据包的最大数目
net.core.netdev_max_backlog 262144#限制仅仅是为了防止简单的DoS 攻击
net.ipv4.tcp_max_orphans 3276800#未收到客户端确认信息的连接请求的最大值
net.ipv4.tcp_max_syn_backlog 262144
net.ipv4.tcp_timestamps 0#内核放弃建立连接之前发送SYNACK 包的数量
net.ipv4.tcp_synack_retries 1#内核放弃建立连接之前发送SYN 包的数量
net.ipv4.tcp_syn_retries 1#启用timewait 快速回收
net.ipv4.tcp_tw_recycle 1#开启重用。允许将TIME-WAIT sockets 重新用于新的TCP 连接
net.ipv4.tcp_tw_reuse 1
net.ipv4.tcp_mem 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout 1#当keepalive 起用的时候TCP 发送keepalive 消息的频度。缺省是2 小时
net.ipv4.tcp_keepalive_time 30#允许系统打开的端口范围
net.ipv4.ip_local_port_range 1024 65000#修改防火墙表大小默认65536
#net.netfilter.nf_conntrack_max655350
#net.netfilter.nf_conntrack_tcp_timeout_established1200# 确保无人能修改路由表
net.ipv4.conf.all.accept_redirects 0
net.ipv4.conf.default.accept_redirects 0
net.ipv4.conf.all.secure_redirects 0
net.ipv4.conf.default.secure_redirects 0————————————————以上完毕感谢观看