Ubuntu Tips

1: ubuntu镜像下载地址

http://cdimage.ubuntu.com/

2: ubuntu1204快捷键(gmone)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Ctrl+Alt+T                      启动终端
Shift+Ctrl+T 启动终端Tab
Shift+Ctrl+W 关闭终端Tab
Alt+[1,2,3...] 切换终端Tab
F11 全屏终端

ALT+F1 启动程序菜单
ALT+F2 运行命令
Ctrl+Win+Down 最小化当前窗口
Ctrl+Win+Up 最大化当前窗口
Ctrl+Win+D 返回桌面
Shift+F10 鼠标右击的键盘快捷键

Ctrl+H 显示隐藏文件
Alt+Enter 查看文件属性

3:设置自动lock为never

1
2
sudo vim /etc/sudoers
Defaults env_reset ==> Defaults env_reset, timestamp_timeout=-1

4: 设置ubuntu1404桌面为gnome3

1
sudo apt-get install gnome

5: 设置ubuntu1204关闭按钮移到右边

1
sudo apt-get install gconf-editor

终端下执行 gconf-editor, 选择/apps/metacity/general的button_layout, 将原来的

“close,minimize,maximize:” 改成 “:minimize,maximize,close”

6: windows远程桌面连接ubuntu系统

Step 1: 安装xrdp server

1
2
sudo apt-get install xrdp
sudo apt-get install vnc4server

Step 2: 安装xfce4

1
sudo apt-get install xubuntu-desktop

按如下内容修改该文件

1
echo "xfce4-session" >~/.xsession

Step 3: 重启xrdp server

1
sudo service xrdp restart

Step 4: 在windows中打开远程桌面连接

输入ubuntu ip->connect->选择sesman-Xvnc->输入账号密码即可远程连接ubuntu

7: 设置ubuntu1204启动项

1
sudo vim /etc/default/grub

8: ubuntu1604安装jdk

1
2
3
4
5
6
7
8
9
# open jdk8
sudo apt install -y openjdk-8-jdk

# oracle jdk8
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
java -version

9: 为apt-get添加自动补齐功能

1
2
3
4
5
apt-get install bash-completion
sudo vim ~/.bashrc --> append
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi

10: ubuntu1804安装MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo apt install -y mysql-server

sudo cat /etc/mysql/debian.cnf
# user = debian-sys-maint
# password = mMsH9vndsuAKo0wF

mysql -u debian-sys-maint -p
# USE mysql;
# UPDATE user SET authentication_string=PASSWORD('123456') WHERE user='root';
# UPDATE user SET plugin="mysql_native_password";
# FLUSH PRIVILEGES;

sudo service mysql restart

11: 远程连接mysql

1
2
3
mysql -u root -p
grant all privileges on *.* to root@'%' identified by 'password';
flush privileges;
1
2
3
vim /etc/mysql/my.cnf
#comment out or delete the line
#bind-address = 127.0.0.1
1
service mysql restart
1
2
#in localhost
mysql -h ip -P 3306 -u root -ppassword

12: ubuntu1204安装django

1
2
3
4
sudo apt-get install python-pip python-dev build-essential 
sudo pip install --upgrade pip
sudo pip install --upgrade virtualenv
sudo pip install django

13: 安装openfire

(1) 在openfire官网上下载最新的deb包: openfire_3.10.0_all.deb 直接安装即可

(2) 重启ubuntu

(3) 启动openfire

1
2
3
cd /var/lib
sudo chown -hR yuanlin openfire
sudo service openfire start

(4) 配置openfire

打开:

http://domain:9090/setup/index.jsp

14: 查看ubuntu版本号

1
cat /etc/issue

该文件的详细解释可通过man查看

1
man issue

15: 查看文件系统的设备名、UUID、类型

blkid

1
2
3
4
/dev/sda1: UUID="BA30-0114" TYPE="vfat"
/dev/sda2: UUID="2A31-1525" TYPE="vfat"
/dev/sda5: UUID="24a4b704-2c8e-4603-89b8-3b65d074f796" TYPE="ext4"
/dev/sda6: UUID="3c6d4341-e564-40a1-8fa6-337d43baa411" TYPE="swap"

再通过查看/etc/fstab就可以知道”/“目录所在的设备名 (修复系统时需要查找”/“目录所在设备名)

16: 搭建VPN server

(1) 下载安装

1
apt-get install pptpd

(2) 配置/etc/pptpd.conf

1
2
localip server_ip  #这个就是你当前主机的IP地址
Remoteip 10.0.0.2-100 #这个就是给客户端分配置的IP地址池

(3) 配置/etc/ppp/options

1
2
ms-dns 8.8.8.8
ms-dns 172.16.10.5

(4) 配置/etc/ppp/pptpd-options

1
name server_ip  #这个就是你当前主机的IP地址

(5) 配置/etc/ppp/chap-secrets

1
2
# client  server  secret  IP addresses
"test" * "123456" *

(6) 配置转发

方法1:

1
echo 1 > /proc/sys/net/ipv4/ip_forward

方法2:

1
2
3
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1 #将后面值改为1,然后保存文件
sysctl –p #马上生效

(7) 配置访问外网

1
iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE

(8) 重启服务

1
service pptpd restart

(9) 查看运行的端口

1
netstat -tnlpu | grep pptpd

17: 搭建GitLab Community Edition

(基于ubuntu 14.04 64bit)

(1) 安装依赖

1
sudo apt-get install curl openssh-server ca-certificates postfix

(2) download deb package from https://packages.gitlab.com/gitlab/gitlab-ce

(3) 安装

1
sudo dpkg --install gitlab-ce_8.3.0-ce.0_amd64.deb

(4) 配置

1
2
3
sudo gitlab-ctl reconfigure
sudo gitlab-ctl status
sudo gitlab-ctl restart

18: 搭建WordPress

(1) 安装依赖

1
2
3
sudo apt-get install apache2
sudo apt-get install mysql-server
sudo apt-get install php5 php5-mysql

(2) 创建数据库

1
2
mysql -u root -p
create database wordpress;

(3) 安装wordpress: 解压wordpress后放至apache目录(例如/var/www)

(4) 浏览器打开apache地址, 配置wordpress后即可

19: 源更新和安装错误

1
2
Reading package lists... Error!
E: Unable to parse package file /var/lib/apt/lists/cn.archive.ubuntu.com_ubuntu_dists_trusty_restricted_i18n_Translation-en%5fUS (1)

解决办法

1
2
sudo rm /var/lib/apt/lists/* -vf
sudo apt-get update

20: 安装nodejs

1
2
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

21: 安装nvm

1
2
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
source ~/.bashrc

22: 安装mongodb

1
2
3
4
5
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo mongod --config /etc/mongod.conf &

23: 安装redis

1
2
3
4
5
6
7
8
9
10
sudo apt-get install redis-server

sudo /etc/init.d/redis-server start
sudo /etc/init.d/redis-server status
sudo /etc/init.d/redis-server stop

redis-cli
help
set key1 "hello world"
get key1

24: 安装ssh server

1
sudo apt-get install -y openssh-server

25: 安装nginx

1
2
3
4
5
sudo apt-get install nginx

sudo service nginx stop
sudo service nginx status
sudo service nginx start

26: 更新ubuntu1604源

1
vim /etc/apt/sources.list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
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 http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
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
1
sudo apt-get update

27: 安装oh-my-zsh

1
2
3
4
5
sudo apt install -y zsh curl

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

chsh -s $(which zsh)

28: 安装node

1
2
3
4
5
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash

nvm install --lts

npm install -g cnpm --registry=https://registry.npm.taobao.org

29: 安装PHP7.1

1
2
3
4
5
6
7
sudo apt install -y software-properties-common

sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install -y php7.1 php7.1-fpm php7.1-redis php7.1-mysql php7.1-mbstring php7.1-xml

30: 安装&配置samba

1
2
3
4
5
sudo apt install -y samba

sudo smbpasswd -a yuanlin

sudo vim /etc/samba/smb.conf
1
2
3
4
5
[dev]
comment = dev
path = /var/dev
writable = yes
valid user = yuanlin
1
sudo service smbd restart

31: 安装&配置docker

1
sudo apt install -y docker.io
1
2
3
4
5
6
7
8
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://utwec57b.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

32: 安装Wine QQ

方法1

下载QQ

1
chmod +x QQ-20171129-x86_64.AppImage

双击即可使用

方法2

1
2
3
4
5
6
# install wine
sudo add-apt-repository ppa:wine/wine-builds

sudo apt update

sudo apt install -y winehq-devel

下载QQ

1
tar xvf wineQQ8.9_19990.tar.xz -C ~/

33: 安装Chrome

1
2
3
4
5
6
7
sudo wget https://repo.fdzh.org/chrome/google-chrome.list -P /etc/apt/sources.list.d/

wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -

sudo apt update

sudo apt install -y google-chrome-stable

34: 安装Shadowsocks

1
2
3
4
5
sudo apt update

sudo apt install -y python-pip python-setuptools m2crypto

sudo -H pip install shadowsocks --upgrade
1
vim ~/.shadowsocks.conf
1
2
3
4
5
6
7
8
9
{
"server":"jp001.v2ss.pw",
"server_port":12313,
"local_address":"127.0.0.1",
"local_port":1086,
"password":"***",
"timeout":300,
"method":"rc4-md5"
}
1
2
3
sudo sslocal -c ~/.shadowsocks.conf -d start

export HTTP_PROXY=socks5://127.0.0.1:1086;export HTTPS_PROXY=socks5://127.0.0.1:1086

更多参考 科学上网 | Ubuntu使用shadowsocks翻墙

35: 安装Swift

1
sudo apt install -y clang libicu-dev git
1
2
3
4
5
6
7
8
9
git clone https://github.com/kylef/swiftenv.git ~/.swiftenv

echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.zshrc

echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.zshrc

echo 'eval "$(swiftenv init -)"' >> ~/.zshrc

source ~/.zshrc
1
2
3
swiftenv install 4.0.3

swift --version

36: 安装PostgreSQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
sudo apt install -y postgresql postgresql-contrib pgadmin3

sudo passwd postgres

sudo su - postgres

psql postgres

CREATE USER kong WITH PASSWORD '123456';

CREATE DATABASE "kong";
# DROP DATABASE "kong";

GRANT ALL PRIVILEGES ON DATABASE "kong" to kong;

37: 安装Kong

下载安装包

1
2
3
4
5
6
7
sudo apt install -y openssl libpcre3 procps perl

sudo dpkg -i kong-community-edition-0.14.0.xenial.all.deb

sudo cp /etc/kong/kong.conf.default /etc/kong/kong.conf

sudo vim /etc/kong/kong.conf
1
2
3
4
5
pg_host = 127.0.0.1
pg_port = 5432
pg_user = kong
pg_password = 123456
pg_database = kong
1
2
3
4
5
6
7
8
kong migrations up

sudo kong start
# Kong started

curl -i http://localhost:8001/
# HTTP/1.1 200 OK
# Server: kong/0.14.0

38: 安装Kong-Dashboard

1
2
3
4
5
6
cnpm i -g kong-dashboard

nohup kong-dashboard start \
--kong-url http://localhost:8001 \
--port=8002 \
--basic-auth kong=123456 &

39: 安装pyenv

1
2
3
4
5
6
7
8
9
sudo apt install -y make build-essential libssl1.0-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git

curl https://pyenv.run | bash

wget http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz -P ~/.pyenv/cache

pyenv install 3.5.2