首页 > 技术文章 > centos7系统初始化操作

likecoke 2020-08-24 17:27 原文

系统安装后的初始化操作:

1.关闭ipv6:
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
chkconfig ip6tables off

2.关闭selinux:
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
setenforce 0


3.关闭iptables:
chkconfig iptables off
service iptables stop
systemctl stop firewalld
systemctl disable firewalld

4.配置远程管理ssh服务:
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's/#Port 22/Port 22/' /etc/ssh/sshd_config
systemctl restart sshd
service sshd restart

5.安装必备软件包:
cd /etc/yum.repos.d/
mkdir backup
mv *.repo backup/
curl -s -o ./Centos-7.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all && yum install -y epel-release && yum clean all && yum makecache && yum -y install unzip zip gcc gcc-c++ make autoconf libtool-ltdl-devel gd freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel bison patch unzip ncurses-devel sudo bzip2 mlocate flex lrzsz sysstat lsof setuptool  system-config-network-tui system-config-firewall-tui ntp libaio-devel wget nmap finger elinks tree tcl sysstat vim wget net-tools tree telnet

yum -y install gcc gcc-c++ make autoconf libtool-ltdl-devel gd freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel bison patch unzip ncurses-devel sudo bzip2 mlocate flex lrzsz sysstat lsof setuptool  system-config-network-tui system-config-firewall-tui ntp libaio-devel wget nmap finger elinks tree tcl sysstat 

systemctl stop NetworkManager
systemctl disable NetworkManager
chkconfig NetworkManager off
chkconfig bluetooth off
chkconfig postfix off

6.设置DNS服务器:
echo "nameserver 202.106.0.20" >> /etc/resolv.conf
echo "nameserver 114.114.114.114" >> /etc/resolv.conf

7.设置时间同步:
echo "*/5 * * * * /usr/sbin/ntpdate ntp.tuna.tsinghua.edu.cn > /dev/null 2>&1" >> /var/spool/cron/root
echo "*/5 * * * * /usr/sbin/ntpdate ntp.tuna.tsinghua.edu.cn > /dev/null 2>&1" >> /var/spool/cron/root
service crond restart
systemctl restart crond

8.设置软件硬件资源与内核同时打开文件最大值
#并发连接数
echo "root soft nofile 65535"  >> /etc/security/limits.conf
echo "root hard nofile 65535"  >> /etc/security/limits.conf
echo "* soft nofile 65535"     >>  /etc/security/limits.conf
echo "* hard nofile 65535"     >> /etc/security/limits.conf
echo -e  "root soft nofile 65535\nroot hard nofile 65535\n* soft nofile 65535\n* hard nofile 65535\n"     >> /etc/security/limits.conf
sed -i 's#4096#65535#g' /etc/security/limits.d/20-nproc.conf 

echo "ulimit -SHn 102400" >> /etc/rc.local
cat >> /etc/security/limits.conf << EOF
 *           soft   nofile       102400
 *           hard   nofile       102400
 *           soft   nproc        102400
 *           hard   nproc        102400
EOF
chmod +x /etc/rc.d/rc.local

9.关闭control-alt-delete3键重启
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf

1 0.调整内核参数
true > /etc/sysctl.conf
cat >> /etc/sysctl.conf << EOF
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 65536
kernel.shmall = 4294967296
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
net.core.somaxconn = 65535
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 1024 65535
EOF
/sbin/sysctl -p

11.增加系统进程数(线程)的限制
sed -i 's/1024/102400/' /etc/security/limits.d/90-nproc.conf


12.设置系统默认启动级别:
sed -i '/^id/s/5/3/' /etc/inittab

也可以将以上命令 写到脚本中 然后运行脚本

给男生个小建议哦~

记住她喜欢吃酸的还是甜的
喜欢下雨还是下雪
她想你了 你陪陪她  她在外面受委屈了 你安慰她 她生气了你哄哄她 她哭了 你抱抱她

还不行 就直接动嘴亲亲她!!!!!!!!!!!

推荐阅读