新建linux服务器初始化操作

 

1.关闭不需要的服务

首先确定服务器有没有ntsysv命令,如果没有的话,直接使用yum安装即可。

使用ntsysv关闭不需要的服务以节省服务器资源

需要打开的服务如下:

crond:周期性计划任务

network:linux网络服务

sshd:OpenSSH服务守护进程

rsyslog:linux日志系统服务

2.关闭不需要的TTY

centos 7已经默认启用一个TTY,如果使用centos 6系统修改建议参考  https://antoinemaze.wordpress.com/2014/02/26/modify-the-number-of-tty-in-centos-6/

3.对TCP/IP网络参数进行调整

echo 'net.ipv4.tcp_syncookies = 1' >> /etc/sysctl.conf

sysctl -p

4.修改SHELL命令的histor记录数

vim /etc/profile

HISTSIZE=1000

根据工作情况而定,修改完成后执行以下命令

source /etc/profile = . /etc/profile

5.定时校正服务器时间

yum -y install ntp

crontab -e 

*/5 * * * * /usr/sbin/ntpdate ntp.api.bz

6.关闭vip6网络服务

ifconfig 

echo "install vip6 /bin/true" > /etc/modprobe.d/disable-vip6.conf

#每当系统需要加载vip6模块时,强制执行/bin/true来代替实际加载的模块

echo "IPV6INIT=no" >> /etc/sysconfig/network-scripts/ifcfg-eth0

7.调整linux的最大打开文件数

ulimit -n  查看当前打开的最大的文件数

修改配置文件

vim /etc/security/limit.conf

soft nofile 65535

hard nofile 65535

还需要在系统的/etc/rc.local文件里添加如下内容:

ulimit -SHn 65535

8.关闭写磁盘I/O功能

加入此台服务器是一台web服务器,而这台服务器上包含很多的图片文件,那么我们是不需要记录这些小文件的访问时间的,这样的话就可以节省磁盘的I/O

修改系统配置文件/etc/fstab,在包含大量的小文件的分区中使用noatime和nodiratime

/dev/sda5 /data/pics ext3 noatime,nodiartime 0 0

9.配置SSH登录

修改/etc/ssh/sshd_config

禁止使用root用户登录

禁止使用空密码登录

关闭SSH反向查询

10.设置用户sudo权限

对于经常需要管理员权限的用户进行设置,修改/etc/sudoers或者使用visudo命令

admin ALL=(ALL) NOPASSWD:ALL

 

转载于:https://www.cnblogs.com/Cherry-Linux/p/7361175.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个典型的Linux服务器初始化脚本,可以根据自己的需求进行修改和定制。该脚本主要完成以下操作: 1. 设置主机名和IP地址。 2. 安装常用软件包和工具。 3. 配置防火墙和SELinux。 4. 配置SSH服务。 5. 设置时区。 6. 创建普通用户和用户组。 7. 禁用root用户远程登录。 8. 配置日志轮转。 ```bash #!/bin/bash # 设置主机名 echo "请输入主机名:" read hostname hostnamectl set-hostname $hostname # 设置IP地址 echo "请输入IP地址:" read ipaddr nmcli connection modify ens33 ipv4.addresses $ipaddr/24 systemctl restart network # 安装常用软件包和工具 yum update -y yum install -y vim wget curl net-tools lsof telnet tree # 配置防火墙和SELinux systemctl stop firewalld systemctl disable firewalld setenforce 0 sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config # 配置SSH服务 sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config systemctl restart sshd # 设置时区 timedatectl set-timezone Asia/Shanghai # 创建普通用户和用户组 groupadd developers useradd -g developers -m -s /bin/bash developer echo "请输入developer用户的密码:" passwd developer # 禁用root用户远程登录 sed -i 's/#RemoteRootLogin yes/RemoteRootLogin no/g' /etc/ssh/sshd_config systemctl restart sshd # 配置日志轮转 cat << EOF > /etc/logrotate.d/myapp /var/log/myapp/*.log { missingok notifempty sharedscripts delaycompress daily rotate 7 create 0644 root root postrotate systemctl reload myapp endscript } EOF ``` 注意:以上脚本仅为示例,具体的Linux服务器初始化脚本应该根据实际情况进行修改和定制。建议在实际操作中参考官方文档,或者咨询专业的Linux技术人员。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值