Featured image of post 『合集』Ubuntu 常用软件安装(持续更新中。。。)

『合集』Ubuntu 常用软件安装(持续更新中。。。)

我的腾讯云服务器被我{% spoiler 不小心 %}换了 IP,加上之前用的是宝塔面板,现在不想用了,所以重装了系统,这次装的是 Ubuntu20.04 的 Docker 基础镜像,自带 Docker,腾讯云控制台也有对应的容器控制面板,很方便。这里记录一下服务器上各种常用软件的安装方法与过程。持续更新中。。。


oh-my-zsh

安装 zsh

1
sudo apt-get install zsh

如果找不到,先 sudo apt update 一下。

{% note info zsh 配置文件加载顺序 %}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
/etc/zshenv
~/.zshenv
/etc/zprofile
~/.zprofile
/etc/zshrc
~/.zshrc
/etc/zlogin
~/.zlogin
~/.zlogout
/etc/zlogout

{% endnote %}

安装 oh-my-zsh

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

中间会询问是否把 zsh 设为默认 sh ,这里选择是。

如果不小心选择了否,可以通过 chsh -s $(which zsh) 重新设置。

各种插件

  • zsh-syntax-highlighting - 代码高亮
1
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  • zsh-autosuggestions - 自动建议
1
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  • zsh-completions - 自动补全
1
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions

配置

~/.zshrc 中配置 plugins=(git sudo z zsh-syntax-highlighting zsh-autosuggestions zsh-completions)

source ~/.zshrc 应用修改后的配置。

Git

镜像已经内置。

MongoDB

安装

  • Import the public key used by the package management system
1
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

The operation should respond with an OK.

  • Create a list file for MongoDB

Create the list file /etc/apt/sources.list.d/mongodb-org-5.0.list for your version of Ubuntu.

Click on the appropriate tab for your version of Ubuntu. If you are unsure of what Ubuntu version the host is running, open a terminal or shell on the host and execute lsb_release -dc.

The following instruction is for Ubuntu 20.04 (Focal).

Create the /etc/apt/sources.list.d/mongodb-org-5.0.list file for Ubuntu 20.04 (Focal):

1
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
  • Reload local package database
1
sudo apt-get update
  • Install the MongoDB packages

To install the latest stable version, issue the following

1
sudo apt-get install -y mongodb-org

Optional. Although you can specify any available version of MongoDB, apt-get will upgrade the packages when a newer version becomes available. To prevent unintended upgrades, you can pin the package at the currently installed version:

1
2
3
4
5
6
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-database hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections

启动

启动服务

1
sudo systemctl start mongod

开机自启动服务

1
sudo systemctl enable mongod

systemctl 启动失败

1
sudo chown mongodb:mongodb /tmp/mongodb-27017.sock

配置

进入 mongo 命令行

1
mongo

使用 admin 数据库(在 mongo 命令行中)

1
use admin

查找所有用户(在 mongo 命令行中)

1
db.system.users.find()

查看数据库角色(在 mongo 命令行中)

1
show roles

1.数据库用户角色:read、readWrite; 2.数据库管理角色:dbAdmin、dbOwner、userAdmin; 3.集群管理角色:clusterAdmin、clusterManager、clusterMonitor、hostManager; 4.备份恢复角色:backup、restore 5.所有数据库角色:readAnyDatabase、readWriteAnyDatabase、userAdminAnyDatabase、dbAdminAnyDatabase 6.超级用户角色:root

角色说明

read:允许用户读取指定数据库; readAnyDatabase:只在admin数据库中可用,赋予用户所有数据库的读权限; readWrite:允许用户读写指定数据库; readWriteAnyDatabase:只在admin数据库中可用,赋予用户所有数据库的读写权限; dbAdmin:允许用户在指定数据库中执行管理函数,如索引创建、删除,查看统计或访问system.profile; dbAdminAnyDatabase:只在admin数据库中可用,赋予用户所有数据库的dbAdmin权限; clusterAdmin:只在admin数据库中可用,赋予用户所有分片和复制集相关函数的管理权限; userAdmin:允许用户向system.users集合写入,可以找指定数据库里创建、删除和管理用户; userAdminAnyDatabase:只在admin数据库中可用,赋予用户所有数据库的userAdmin权限; root:只在admin数据库中可用。超级账号,超级权限。

查看用户(在 mongo 命令行中)

1
show users

创建用户(在 mongo 命令行中)

1
2
3
4
db.createUser({user:"admin",pwd:"123456",roles:["root"]})
db.createUser({user:"admin",pwd:"123456",roles:[{role:"root",db:"admin" }]})
db.createUser({user:"test",pwd:"test",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})
db.createUser({user:"gin",pwd:"gin",roles:[{role:"dbOwner",db:"gin"}]})

{% note caution caution %}

创建用户时,要切换到目标数据库再创建用户,不然创建的用户还是属于 admin

{% endnote %}

登录(在 mongo 命令行中)

1
db.auth('admin','password')

注意

  • 安装失败,多试几次 sudo apt update

{% fold %}

Err:6 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 Release

Could not wait for server fd - select (11: Resource temporarily unavailable) [IP: 13.35.49.55 443]

Err:7 https://download.docker.com/linux/ubuntu focal Release

Could not wait for server fd - select (11: Resource temporarily unavailable) [IP: 13.249.170.87 443]

Reading package lists… Done

E: The repository ‘https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 Release’ does not have a Release file.

N: Updating from such a repository can’t be done securely, and is therefore disabled by default.

N: See apt-secure(8) manpage for repository creation and user configuration details.

E: The repository ‘https://download.docker.com/linux/ubuntu focal Release’ no longer has a Release file.

N: Updating from such a repository can’t be done securely, and is therefore disabled by default.

N: See apt-secure(8) manpage for repository creation and user configuration details.

{% endfold %}

Mysql Server

安装

1
sudo apt install mysql-server

进入 mysql 命令行

1
mysql -uroot

设置密码

set password for root@localhost = ‘123456’;

1
2
3
4
CREATE DATABASE IF NOT EXISTS lskypro;
CREATE USER 'lskypro'@'%' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON lskypro.* TO 'lskypro'@'%' WITH GRANT OPTION;
flush privileges;

Redis

直接使用 apt 安装

1
sudo apt install redis-server

使用 redis-cli 验证

1
redis-cli

redis-cli 内设置密码

1
config set requirepass 123456

命令行指定的密码,重启后无效,想要永久生效则修改配置文件 /etc/redis/redis.conf ,在 requirepass 后添加密码。

如果想设置远程访问, sudo vim /etc/redis/redis.conf ,需要将 bind 127.0.0.1 ::1 注释掉并且没有设置访问密码,然后将 Protected-mode 设置为 no 。

{% note info Redis Protected-mode %}

Protected-mode 是为了禁止公网访问redis cache,加强redis安全的。

它启用的条件,有两个: 1) 没有bind IP 2) 没有设置访问密码

{% endnote %}

Golang

在官网或其他网站如:

下载压缩包

go1.18.1.linux-amd64.tar.gz , 上传至服务器,然后解压缩:

1
sudo tar -zxf go1.18.1.linux-amd64.tar.gz -C /usr/local

设置环境变量

1
2
3
4
5
6
7
8
9
export GOROOT=/usr/local/go
export GOPATH=/home/ubuntu/go
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH

export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct
export CGO_ENABLED=0
export GOOS=linux
export GOARCH=amd64

➜ ~ go version go version go1.18.1 linux/amd64

Node.js

1
sudo curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

## Run **sudo apt-get install -y nodejs** to install Node.js 14.x and npm

## You may also need development tools to build native addons:

​ sudo apt-get install gcc g++ make

## To install the Yarn package manager, run:

​ curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg –dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null

​ echo “deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main” | sudo tee /etc/apt/sources.list.d/yarn.list

​ sudo apt-get update && sudo apt-get install yarn

换清华源(已过期)

清华源已经将 NodeSource 去掉,下面[使用 n 替代](#使用 n 安装)。

编辑 /etc/apt/sources.list.d/nodesource.list , 把 https://deb.nodesource.com/node/ 替换为 https://mirrors.tuna.tsinghua.edu.cn/nodesource/node/ 即可。

这里是 https://deb.nodesource.com/node_14.x ,改为 https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_14.x

换源后安装(×)

1
2
sudo apt update
sudo apt install nodejs

使用 n 安装

首先要安装 npm,然后用 npm 安装 n,这里先随意下载一个版本。

1
sudo apt install nodejs npm

~ npm -v

6.14.4

~ node -v

v10.19.0

然后安装 n

1
npm install -g n

使用 n 切换版本

1
2
3
4
# 设定环境变量(~/.zshrc)
export NODE_MIRROR=https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/
# 然后正常使用 n 即可
sudo n stable

~ node -v

v16.15.0

~ npm -v

8.5.5

npm 换源

1
npm config set registry "https://registry.npm.taobao.org" 

注意

Err:5 https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_14.x focal Release

Certificate verification failed: The certificate is NOT trusted. The certificate chain uses expired certificate. Could not handshake: Error in the certificate v

erification. [IP: 101.6.15.130 443]

1
sudo apt install ca-certificates --reinstall

Nginx

直接 apt 安装就可以。

1
sudo apt install nginx
1
sudo systemctl start nginx
1
sudo systemctl enable nginx

Docker

这次安装的镜像是 docker 基础镜像,内置了 docker,不再记录。

可以查看另一篇文章:Docker

Grafana

1
sudo docker run -d --net=host --restart=always --name=grafana grafana/grafana

ShowDoc

1
2
sudo docker run -d --name showdoc --user=root --privileged=true -p 4999:80 \
-v /data/showdoc/html:/var/www/html/ star7th/showdoc

MinIO

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
sudo docker run -itd --name minio \
-p 9000:9000 \
-p 19000:19000 \
-d --restart=always \
-e "MINIO_ROOT_USER=admin" \
-e "MINIO_ROOT_PASSWORD=123456" \
-v /data/minio:/data \
-v /etc/minio:/root/.minio \
minio/minio server /data \
--console-address '0.0.0.0:19000'

Cloudreve

Lsky Pro 2

如果要访问宿主机的 Mysql ,可以在 mysql 配置文件(/etc/mysql/mysql.conf.d/mysqld.cnf)中设置 bind-address 为 0.0.0.0(允许所有 IP 访问),然后 docker network inspect lskypro_default ,查看容器 IP,在服务器的防火墙中开放此 IP 对 3306 的访问权限。

EMQX

Prometheus

Portainer

frp

ctop

Top-like interface for container metrics

ctop provides a concise and condensed overview of real-time metrics for multiple containers:

https://github.com/bcicen/ctop/raw/master/_docs/img/grid.gif

as well as a single container view for inspecting a specific container.

ctop comes with built-in support for Docker and runC; connectors for other container and cluster systems are planned for future releases.

安装

1
2
3
4
echo "deb http://packages.azlux.fr/debian/ buster main" | sudo tee /etc/apt/sources.list.d/azlux.list
wget -qO - https://azlux.fr/repo.gpg.key | sudo apt-key add -
sudo apt update
sudo apt install docker-ctop

未完待续。。。

Reference