vmware模板机ubuntu1604制作

ubuntu server 1604模板机制作

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 sshd 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

echo 'export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S  `whoami` "' >>/etc/profile

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

source /etc/profile

6、关闭防火墙和设置journalctl日志大小避免把系统盘占满

ufw disable

journalctl 命令自动维护文件大小
只保留近一周的日志
journalctl --vacuum-time=1w

只保留500MB的日志
journalctl --vacuum-size=500M

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

cp /etc/apt/sources.list /etc/apt/sources.list.bak

cat /etc/apt/sources.list
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

apt-get update

apt-get install -y git ntp ntpdate lrzsz lftp wget unzip zip bash-completion tree elinks nmap net-tools tcptraceroute aptitude dos2unix net-tools htop iftop sshuttle sysstat

7.1、支持telnet(server) 可选

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

8、设置时区、同步时间

timedatectl set-timezone Asia/Shanghai

apt-get -y install ntpdate

sed -i '/# By default this script does nothing./a ntpdate -u ntp1.aliyun.com' /etc/rc.local

chmod a+x /etc/rc.local

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
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>使内核参数生效

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
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值