【优化】ubuntu14.04服务器基本环境初始化
2021年04月08日 09:46:41 作者:Jiaozn 分类:Linux 评论(0)一、修改文件最大打开数
sudo vim /etc/security/limits.conf
文件尾追加
* hard nofile 1000000
* soft nofile 1000000
修改系统最大连接数
sysctl -a | grep somaxconn
echo '
net.core.somaxconn = 2048
# 处理TIME_WAIT数量过多
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
' >> /etc/sysctl.conf
sysctl -p
二、修改环境编码
sudo apt-get install language-pack-zh-hans
sudo vim /etc/default/locale
添加
LANG="en_US.UTF-8"
LANGUAGE="en_US:en"
LC_ALL="en_US.UTF-8"
生效
source /etc/profile
三、添加用户
# 有sudo权限jtsa用户 运维人员使用
sudo useradd jtsa -m -s /bin/bash
sudo passwd jtsa
sudo usermod -a -G sudo jtsa
# 有sudo权限jtserver用户 开发人员使用
sudo useradd jtserver -m -s /bin/bash
sudo passwd jtserver
sudo usermod -a -G sudo jtserver
# 无sudo权限jtjt用户 开发人员使用
sudo useradd jtjt -m -s /bin/bash
sudo passwd jtjt
四、修改ssh登录
sudo vim /etc/ssh/sshd_config 允许密码登录
将PasswordAuthentication改为yes
将Port改为36000
sudo service ssh restart
五、登录jtserver,添加ssh公钥和秘钥、添加authorized_keys
ssh-keygen -t rsa -C "jitui@jituia.com"
vim ~/.ssh/authorized_keys 添加本地电脑id_rsq.pub
chmod 600 ~/.ssh/authorized_keys
六、修改hostname
sudo vim /etc/hostname改为aws
sudo vim /etc/hosts添加127.0.0.1 aws
生效hostname sudo hostname -F /etc/hostname
重新登录
七、haproxy安装
sudo add-apt-repository ppa:vbernat/haproxy-1.8
sudo apt-get update
sudo apt-get install haproxy
haproxy -v
八、nginx、git安装
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git
添加nginx log日志压缩配置
echo "/home/jtserver/log/nginx/*.log {
daily
size 100M
missingok
rotate 7
compress
delaycompress
notifempty
su root root
create 0644 www-data root
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}" | sudo tee /etc/logrotate.d/custom-nginx-log
九、python环境
[supervisor deb包下载](http://ftp.debian.org/debian/pool/main/s/supervisor/)
sudo dpkg -i supervisor_3.3.1-1_all.deb
sudo apt-get install python-pip python-dev build-essential
sudo apt-get install uwsgi uwsgi-plugin-python
sudo apt-get install uwsgi-plugin-python3
十、redis安装
sudo apt-get install -y python-software-properties
sudo apt-get install software-properties-common
# sudo add-apt-repository -y ppa:rwky/redis
sudo add-apt-repository ppa:chris-lea/redis-server
sudo apt-get update
sudo apt-get install -y redis-server
十一、ssh登录
添加密钥到ssh-agent
eval "$(ssh-agent -s)"
生成ssh key,或者重新覆盖
# -f ~/.ssh/id_rsa -f 文件名
ssh-keygen -t rsa -C "test@jituia.com"
把专用密钥添加到 ssh-agent 的高速缓存中
ssh-add ~/.ssh/id_rsa
ssh设置不用密码登陆,复制本地id_rsa.pub追加到到服务器.ssh/authorized_keys
sudo vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
修改.ssh文件权限
# authorized_keys权限必须为600,不然出现Authentication refused: bad ownership or modes
chmod 755 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
# 重启ssh服务
sudo service ssh restart
# 排查authorized_keys不生效,查询/var/log/auth/log文件
十二、修改只使用阿里云源
sudo vim /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
十三
问题
1.Depends: init-system-helpers (>= 1.18~) b
打开文件https://launchpad.net/ubuntu/utopic/powerpc/init-system-helpers/1.18,下载1.18包
wget http://launchpadlibrarian.net/173841617/init-system-helpers_1.18_all.deb
sudo dpkg -i init-system-helpers_1.18_all.deb
打开网址,选择源地址
wget -O- http://neuro.debian.net/lists/trusty.cn-bj1.full | sudo tee /etc/apt/sources.list.d/neurodebian.sources.list
sudo apt-key adv --recv-keys --keyserver hkp://pool.sks-keyservers.net:80 0xA5D32F012649A5A9
sudo apt-get update
sudo apt-get install init-system-helpers
2.supervisor depends on python-meld3
sudo apt-get install python-meld3
3.保存ssh长链接
服务器/etc/ssh/sshd_config添加
ClientAliveInterval 60
ClientAliveCountMax 5
本地服务器/etc/ssh/sshd_config添加
Host *
TCPKeepAlive yes
ServerAliveInterval 60
4.修改服务器时区
一、运行tzselect,在这里我们选择亚洲 Asia,确认之后选择中国(China),最后选择北京(Beijing)
sudo tzselect
二、复制文件到/etc目录下
sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
三、更新时间,cn.pool.ntp.org是位于中国的公共NTP服务器
# sudo apt-get install ntpdate
sudo ntpdate cn.pool.ntp.org
四、安装ntp自动同步时间
sudo apt-get install ntp
sudo service ntp start
5、vim配置
" General {
set nu " 显示行号
set showcmd " 显示命令"
syntax on " 语法高亮
set nowritebackup " 禁止防止灾难备份
set nobackup " 关闭备份
set noswapfile " 禁止保存交换文件
set nocompatible " 关闭兼用模式
" set autoindent " 继承前一行的缩进方式,特别适用于多行注释
" set ai " 自动缩进
" set si " 智能缩进
set ruler " 右下角显示光标位置
set shiftround
" 设置在状态行显示的信息
set foldcolumn=0
set foldlevel=3
set nocompatible " 关闭兼容模式
set history=1000 " 历史记录数
" 搜索逐字高亮
set hlsearch
set incsearch
" 编码设置
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set report=0 " 通过使用: commands命令,告诉我们文件的哪一行被改变过
set showmatch " 高亮显示匹配的括号
syntax enable " 语法高亮
" 转化为4个字符
set expandtab
set smarttab
set shiftwidth=4
set tabstop=4 " Tab键的宽度
set undofile " 缺省关闭,局部于缓冲
set ul=1000 " 可以撤销的最大改变次数
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a " Automatically enable mouse usage
set mousehide " Hide the mouse cursor while typin
set selection=exclusive
"共享剪贴板
set clipboard=unnamed,unnamedplus
" Visual shifting (does not exit Visual mode)
vnoremap < <gv
vnoremap > >gv
" For when you forget to sudo.. Really Write the file.
cmap w!! w !sudo tee % >/dev/null
"-------------------------------
" 代码折叠
"---------------------------
"set foldmarker={,}
"set foldmethod=marker
"set foldmethod=syntax
"set foldlevel=100 " Don't autofold anything
"set foldopen-=search " don't open folds when you search into them
"set foldopen-=undo " don't open folds when you undo stuff
"set foldcolumn=4
" 恢复上次文件打开位置
set viminfo='10,\"100,:20,%,n~/.viminfo
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm'\"")|else|exe "norm $"|endif|endif
" }
" map {
" 分割窗口
map ws :split<cr>
map wv :vsplit<cr>
nmap wj <C-W>j
nmap wk <C-W>k
nmap wh <C-W>h
nmap wl <C-W>l
" }
评论
发表评论