VPS介绍

增加非root用户

当以root权限登陆一台全新的VPS之后,第一件事情就是增加拥有sudo权限的非root用户,目的如下: - it prevents the user making any system-destroying mistakes - it stores all the commands run with sudo to a file where can be reviewed later if needed

增加用户

   sudo adduser work

增加sudo权限

sudo /usr/sbin/visudo

# User privilege specification
rootALL=(ALL:ALL) ALL
workALL=(ALL:ALL) ALL

删除用户

sudo userdel newuser
sudo rm -rf /home/newuser

安装tmux 1.8

ubuntu Lucid源中的tmux版本过老,为此,我们手动安装tmux 1.8,

安装基础编译环境

sudo apt-get install build-essential

安装依赖包

wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar xzf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
configure && make && sudo make install
sudo apt-get install ncurses-dev

安装tmux 1.8

wget http://downloads.sourceforge.net/tmux/tmux-1.8.tar.gz
tar xzf tmux-1.8.tar.gz
cd tmux-1.8
./configure LDFLAGS="-Wl,-rpath /usr/local/lib"
make
sudo make install

非root运行tmux技巧

bash -c "export LD_LIBRARY_PATH=~/tool/bin/lib:$LD_LIBRARY_PATH && ~/tool/bin/bin/tmux a || ~/tool/bin/bin/tmux -f ~/tool/conf/tmux.conf"

tmux 配置文件


set -g prefix ^a
unbind ^b
bind a send-prefix
unbind '"'
bind - splitw -v # horizontal split
unbind %
bind | splitw -h # vertical split
bind k selectp -U # select upper pane
bind j selectp -D # select lower pane
bind h selectp -L # select left pane
bind l selectp -R # select right pane
bind ^k resizep -U 10
bind ^j resizep -D 10
bind ^h resizep -L 10
bind ^l resizep -R 10
bind ^u swapp -U # swap with upper pane
bind ^d swapp -D # swap with lower pane

# THEME
set -g status-bg black
set -g status-fg white
set -g window-status-current-bg white
set -g window-status-current-fg black
set -g window-status-current-attr bold
set -g status-interval 60
set -g status-left-length 30
set -g status-left '#[fg=green](#S) #(whoami)'
set -g status-right "#[fg=green]#(date)#[default] #[fg=green]#(cut -d ' ' -f 1-3 /proc/loadavg)#[default]"

setw -g mode-keys vi
setw -g mode-mouse off
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
set -g base-index 1
#set -s escape-time 0
setw -g aggressive-resize on

unbind r
bind r source-file ~/.tmux.conf

set -g history-limit 25000

#T-Mobile G2 workarounds
bind Q send-keys F1
bind W send-keys F2
bind E send-keys F3
bind R send-keys F4
bind T send-keys F5
bind Y send-keys F6
bind U send-keys F7
bind I send-keys F8
bind O send-keys F9
bind P send-keys F10
bind A send-keys F11
bind S send-keys F12

bind / send-keys |

unbind t
bind t send-keys Tab

unbind N
bind N clock-mode

unbind @
bind @ send-keys Escape

unbind H
bind H send-keys Home

unbind L
bind L send-keys End

unbind J
bind J send-keys PageDown

unbind K
bind K send-keys PageUp

#Alt-n window switching
unbind M-1
unbind M-2
unbind M-3
unbind M-4
unbind M-5
unbind M-6
unbind M-7
unbind M-8
unbind M-9
bind-key -n M-1 select-window -t :1
bind-key -n M-2 select-window -t :2
bind-key -n M-3 select-window -t :3
bind-key -n M-4 select-window -t :4
bind-key -n M-5 select-window -t :5
bind-key -n M-6 select-window -t :6
bind-key -n M-7 select-window -t :7
bind-key -n M-8 select-window -t :8
bind-key -n M-9 select-window -t :9

bind-key -n ^PageDown next-window
bind-key -n ^PageUp previous-window

#set -g default-terminal "screen-256color"
#For compatibility
set -g default-terminal "xterm-color"

##CLIPBOARD selection integration
##Requires prefix key before the command key
#Copy tmux paste buffer to CLIPBOARD
bind C-c run "tmux show-buffer | xclip -i -selection clipboard"
#Copy CLIPBOARD to tmux paste buffer and paste tmux paste buffer
bind C-v run "tmux set-buffer \"$(xclip -o -selection clipboard)\"; tmux paste-buffer"

locale设置

查看locale

# 查看当前系统语言环境
locale
# 查看系统内安装的locale
locale -a

安装zh_CN.utf8

cd /usr/share/locales
sudo ./install-language-pack zh_CN

locale配置: /etc/default/locale

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=zh_CN.UTF-8
LC_TIME=zh_CN.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=zh_CN.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=zh_CN.UTF-8
LC_NAME=zh_CN.UTF-8
LC_ADDRESS=zh_CN.UTF-8
LC_TELEPHONE=zh_CN.UTF-8
LC_MEASUREMENT=zh_CN.UTF-8
LC_IDENTIFICATION=zh_CN.UTF-8
LC_ALL=

mosh 安装与配置

由于VPS在美国,ssh连接速度很慢,考虑用mosh解决该问题

The mosh-client binary must exist on the user's machine, and the mosh-server binary on the remote host.

参考:http://mosh.mit.edu/

安装

sudo add-apt-repository ppa:keithw/mosh
sudo apt-get update
sudo apt-get install mosh

防火墙配置

sudo iptables -I INPUT 1 -p udp --dport 60000:61000 -j ACCEPT

mosh登陆

mosh work@162.221.4.10

ftp server安装

安装ftp server

sudo apt-get install vsftpd

配置:/etc/vsftpd.conf

生效如下配置:

chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list

重启ftp

sudo /etc/init.d/vsftpd restart

nginx 安装与配置

参考:http://wiki.nginx.org/Install

安装add-apt-repository

sudo apt-get install python-software-properties

安装nginx

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx

nginx 配置:/etc/nginx 参考:http://blog.martinfjordvald.com/2010/07/nginx-primer

php-fpm&mysql 安装

增加ppa

sudo apt-add-repository ppa:ondrej/php5-oldstable

安装php组件

sudo aptitude -y install php5-cli php5-common php5-mysql php5-suhosin php5-gd
sudo aptitude -y install php5-fpm php5-cgi php-pear php5-memcache php-apc

ubuntu 增加lib

sudo vim /etc/ld.so.conf.d/newlib.conf
# Add the path to file and save it
sudo ldconfig

未完待续...

本人最近折腾了好几台VPS(国内外),国内用的阿里云用的是ubuntu 12.04,软件源较新,安装软件远没有以上ubuntu10.04折腾...喵,VPS配置第二篇将会涉及VPS安全相关的内容~后续也会陆续在Github上分享本人的vim, bashrc等配置~


Follow me on GitHub