vmware模板机ubuntu1404制作

ubuntu1404-server模板及制作

1、添加root用户登陆权限、优化ssh

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak 

sed -i 's/PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config

sed -i 's/PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
    
 sed -i '/GSSAPIAuthentication/a\\GSSAPIAuthentication no' /etc/ssh/sshd_config 

echo "UseDNS no" >>/etc/ssh/sshd_config
 
service ssh restart
echo -e "duan@1994\nduan@1994" | passwd root

2、修改网卡名称

cp /etc/default/grub /etc/default/grub.bak
sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"/' /etc/default/grub

grub-mkconfig -o /boot/grub/grub.cfg
update-grub

修改/etc/network/interfaces内ens33 ip为eth0
重启虚拟机生效

3、配置静态ip

cp /etc/network/interfaces /etc/network/interfaces.bak

cat /etc/network/interfaces

source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
#################################
## dhcp ip config
#auto eth0
#iface eth0 inet dhcp
#################################
##static ip config
auto eth0
iface eth0 inet static
address 192.168.121.50
netmask 255.255.255.0
gateway 192.168.121.2
dns-nameserver 192.168.121.2
#################################

4、调整文件描述符大小

echo "ulimit -SHn 655350" >>/etc/profile

echo "fs.file-max = 655350" >>/etc/sysctl.conf

echo "root soft nofile 655350" >>/etc/security/limits.conf

echo "root hard nofile 655350" >>/etc/security/limits.conf

echo "* soft nofile 655350" >>/etc/security/limits.conf

echo "* hard nofile 655350" >>/etc/security/limits.conf

echo "session required pam_limits.so" >>/etc/pam.d/common-session

source /etc/profile

5、优化history

cat /etc/profile
export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S  `whoami` "
export HISTFILESIZE=5000
export HISTSIZE=5000

source /etc/profile

6、关闭防火墙

ufw disable

7、修改apt源为国内源、安装常用软件

cp /etc/apt/sources.list /etc/apt/sources.list.bak
root@ubuntu:~# cat /etc/apt/sources.list

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

apt-get update

8、支持telnet(server)

apt-get -y install openbsd-inetd
apt-get -y install telnetd
/etc/init.d/openbsd-inetd restart

9、升级内核、优化内核参数
1>升级内核

wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb

wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.20.17/linux-headers-4.20.17-042017_4.20.17-042017.201903190933_all.deb

wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.20.17/linux-headers-4.20.17-042017-generic_4.20.17-042017.201903190933_amd64.deb

wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.20.17/linux-image-unsigned-4.20.17-042017-generic_4.20.17-042017.201903190933_amd64.deb

wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.20.17/linux-modules-4.20.17-042017-generic_4.20.17-042017.201903190933_amd64.deb



dpkg -i *.deb
apt-get -f install -y

#sed -i 's/GRUB_DEFAULT=0/GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 3.19.8-031908ckt23-lowlatency"/g' /etc/default/grub
#update-grub

reboot
uname -sr

2>优化内核参数

cp /etc/sysctl.conf /etc/sysctl.conf.bak

vi /etc/sysctl.conf
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_abort_on_overflow = 1
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        66384  4194304
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.core.optmem_max = 81920
net.core.wmem_default = 8388608
net.core.wmem_max = 16777216
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.ipv4.tcp_max_syn_backlog = 1020000
net.core.netdev_max_backlog = 862144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 327680
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024    65535
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_max = 1048576
net.nf_conntrack_max = 1048576
fs.file-max = 655350

3>使内核参数生效

扫描二维码关注公众号,回复: 11623440 查看本文章
modprobe nf_conntrack
sysctl -p /etc/sysctl.conf
sysctl -w net.ipv4.route.flush=1

10、垃圾清理、历史记录清理

apt-get autoclean 
apt-get clean
apt-get autoremove 
cat /dev/null >/var/log/syslog
cat /dev/null >/var/log/dpkg.log
cat /dev/null >/var/log/lastlog
cat /dev/null >/var/log/auth.log
cat /dev/null >/var/log/alternatives.log
cat /dev/null >/var/log/bootstrap.log
cat /dev/null >/var/log/apt/history.log
cat /dev/null >/var/log/apt/term.log
cat /dev/null >~/.ssh/known_hosts
cat /dev/null >~/.bash_history
history -c

猜你喜欢

转载自blog.csdn.net/weixin_47003048/article/details/108347360
今日推荐