vps 常用环境安装

修订版本 v 2.0—增加java环境相关内容,优化Linux 语句、增加python pip 安装

修订版本 v 3.0 -增加 MySQL 安装,优化Linux语句内容。

必看

本安装系统适用于 centos 7 系列

1
2
cat /etc/redhat-release
centos 7

所有安装环境只根据个人需要进行安装,无需全部安装,会持续添加,修订 ~~

source /etc/profile 编译后只能在当前终端生效,重新开启一个中断后,该环境变量将失效。解决办法,重启 reboot、即可永久生效

Linux配置ssh

1.vnc配置ssh连接

  • 按照要求进行配置
  • 进行连接

2.ssh连接

  • 配置ssh配置文件
1
2
3
4
5
6
7
8
9
vi /etc/ssh/ssh_config

#修改ssh配置文件
# Port 22 去掉注释
Port 22
#------------------------分割线---------------------------
#PermitLocalCommand no #去掉注释并改为
PermitLocalCommand yes
- 退出保存即可

3.连接ssh

输入密码和用户即可

Yum 源

国外的服务可忽略

1
2
3
4
5
yum install -y wget
cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.bk
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all && yum makecache

其他源

清华源 https://mirrors.tuna.tsinghua.edu.cn/help/centos/

1
2
3
4
5
# 网易源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

# 中科大
wget -O /etc/yum.repos.d/CentOS-Base.repo 'https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=3'

Linux 最小化工具库

因为是最小化安装,所以好多常用工具需要自行安装

1
yum install -y vim lrzsz gcc gcc-c++ net-tools wget automake cmake gzip bzip2 zip unzip kernel kernel-devel kernel-headers git-all screen 

Java 环境

安装多个Java版本是可以切换的,没有测试在运行程序,切换版本,会不会出现故障,最好测试一下,目前本地测试服务未出现故障,没有跑服务,自测吧,可以根据需要进行安装

img

Java11

1.安装java环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
wget https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz
mkdir /opt/java
tar zxvf openjdk-11+28_linux-x64_bin.tar.gz -C /opt/java
rm -rf openjdk-11+28_linux-x64_bin.tar.gz

vim /etc/profile

# java 11
export JAVA_HOME=/opt/java/jdk-11
export JRE_HOME=/opt/java/jdk-11
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${PATH}:${JAVA_HOME}/bin:${JRE_HOME}/bin

# 加载源
source /etc/profile

Java8

yum安装

1
yum install java-1.8.0-openjdk.x86_64 -y

源码安装-jdk-8u77

需要自己下载源码、官网下载需要注册登录下载,1.8之后的,可自行注册下载,所需版本

1
2
3
4
5
6
7
8
9
10
11
12
13
mkdir /opt/java
tar zxvf jdk-8u77-linux-x64.tar.gz -C /opt/java
rm -rf jdk-8u77-linux-x64.tar.gz

vim /etc/profile

# java 8
export JAVA_HOME=/opt/java/jdk1.8.0_77
export JRE_HOME=/opt/java/jdk1.8.0_77
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${PATH}:${JAVA_HOME}/bin:${JRE_HOME}/bin

source /etc/profile

Java7

1
2
3
4
5
6
7
8
9
10
11
12
mkdir /opt/java
tar zxvf jdk-7u80-linux-x64.tar.gz -C /opt/java

vim /etc/profile

# java 7
export JAVA_HOME=/opt/java/jdk1.7.0_80
export JRE_HOME=/opt/java/jdk1.7.0_80
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${PATH}:${JAVA_HOME}/bin:${JRE_HOME}/bin

source /etc/profile

Java切换JDK 版本

1
2
3
4
5
6
7
# 将Java目录加入JDK选择列表
update-alternatives --install /usr/bin/java java /opt/java/jdk-11/bin/java 11
update-alternatives --install /usr/bin/java java /opt/java/jdk1.8.0_77/bin/java 8
update-alternatives --install /usr/bin/java java /opt/java/jdk1.7.0_80/bin/java 7

# 切换版本选择需要jdk的版本
update-alternatives --config java

maven

安装Java打包程序

1
2
3
4
wget https://dlcdn.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
tar -xvf apache-maven-3.6.3-bin.tar.gz
mv -f apache-maven-3.6.3 /usr/local/
rm -rf apache-maven-3.6.3-bin.tar.gz

添加环境变量

1
2
3
4
5
6
7
vim /etc/profile

# maven
export MAVEN_HOME=/usr/local/apache-maven-3.6.3
export PATH=${PATH}:${MAVEN_HOME}/bin
source /etc/profile
mvn -v

Python 3.9.7

https://note.qidong.name/2021/05/multiple-python/

Linux 安装

1.查看Python 版本

1
2
python -V
# CentOS 7 中自带的python版本是python-2.7.5 ,python是3.6的很多版本需要3.7的所需需要安装高版本,

2.下载安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tar.xz
tar -xvJf Python-3.9.7.tar.xz
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc libffi-devel
cd Python-3.9.7
./configure --prefix=/usr/local/python3
make && make install
cd ..
rm -rf Python-3.9.7.tar.xz Python-3.9.7

# 下载
# 解压
# 安装依赖包
# 进入python目录
# 编译
# 安装

3.创建链接

1
2
3
4
5
6
7
ln -s /usr/local/python3/bin/python3.9 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.9 /usr/bin/pip3
# 创建python3链接
# 创建pip3链接

#更新 pip
/usr/local/python3/bin/python3.9 -m pip install --upgrade pip

4.修改yum配置(可选)

因为执行yum需要python2版本,所以我们还要修改yum的配置

1
2
3
4
vim /usr/bin/yum
#! /usr/bin/python修改为#! /usr/bin/python2
vim /usr/libexec/urlgrabber-ext-down
#! /usr/bin/python 也要修改为#! /usr/bin/python2

5.创建虚拟环境(可选)

virtualenv 是一个可以在同一计算机中隔离多个python版本的工具。如 python2.7 / python3.9 ,但是如果都装到一起,经常会导致问题。

1
2
3
pip3 install --upgrade pip
pip3 install virtualenv
pip3 install virtualenvwrapper

修改文件路径

1
2
3
4
5
vim ~/.bashrc
#在文件末尾添加
VIRTUALENVWRAPPER_PYTHON=/usr/local/python3/bin/python3 # 指定virtualenvwrapper执行的python版本
export WORKON_HOME=$HOME/.virtualenvs # 指定虚拟环境存放目录,.virtualenvs目录名可自拟
source /usr/local/python3/bin/virtualenvwrapper.sh # virtualenvwrapper.sh所在目录

安装virtualenv

1
2
3
source ~/.bashrc
ln -s /usr/local/python3/bin/virtualenv /usr/local/bin/virtualenv
mkvirtualenv --python=/usr/bin/python3 py3-env

6.卸载 Python3 (可选)

1
2
3
4
5
6
7
8
#卸载pyhton3
rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps

#删除所有残余文件
whereis python3 |xargs rm -frv
#卸载完成
#查看现有的已安装的python
whereis python

Python 2 扩展

Centos7 默认自带 Python 2.7.5 版本,但是缺少 pip库 以及常用的模块,这里列举了,模块的安装方式,如果pip 安装不成功,可以尝试通过去官网下载编译安装

Python2的常用的库 https://pypi.org/

安装方式列举

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 安装 setuptools
wget https://pypi.python.org/packages/45/29/8814bf414e7cd1031e1a3c8a4169218376e284ea2553cc0822a6ea1c2d78/setuptools-36.6.0.zip#md5=74663b15117d9a2cc5295d76011e6fd1
unzip setuptools-36.6.0.zip
cd setuptools-36.6.0
python setup.py install
cd ..
rm -rf setuptools-36.6.0 setuptools-36.6.0.zip

# 安装 requests
wget https://pypi.python.org/packages/5b/0b/34be574b1ec997247796e5d516f3a6b6509c4e064f2885a96ed885ce7579/requests-2.12.4.tar.gz
tar -zxvf requests-2.12.4.tar.gz
cd requests-2.12.4
python setup.py install
cd ..
rm -rf requests-2.12.4.tar.gz requests-2.12.4

安装 pip

1
2
3
4
5
6
7
wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
tar -zxvf pip-9.0.1.tar.gz
cd pip-9.0.1
python setup.py install
pip install --upgrade pip
cd ..
rm -rf pip-9.0.1.tar.gz pip-9.0.1

PHP 环境安装

PHP7.3

1
2
3
4
yum install -y epel-release yum-utils
yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-pecl-swoole php73-php-recode php73-php-snmp php73-php-soap php73-php-xmll
ln -s /opt/remi/php73/root/usr/bin/php /usr/bin/php

phpggc

1
git clone https://github.com/ambionics/phpggc.git

MySQL 安装

Centos

https://cloud.tencent.com/developer/article/1886339

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# centos 7
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
yum install -y mysql-community-server
systemctl start mysqld.service
systemctl status mysqld.service
systemctl enable mysqld
systemctl daemon-reload


#查询密码
grep 'temporary password' /var/log/mysqld.log

mysql -uroot -p

# 修改密码复杂度
set global validate_password_policy=0;
set global validate_password_length=1;

#设置密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';

# 授权其他机器远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;

#修改为UTF-8 修改内容如下
vim /etc/my.cnf

[mysql]
default-character-set=utf8

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default-storage-engine=INNODB
character_set_server=utf8

symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

# 重启
service mysqld restart

#添加防火墙规则
firewall-cmd --state
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

卸载MySQL

1
2
rpm -qa | grep mysql
yum -y remove mysql57-community-release-el7-10.noarch

Redis 客户端

是连接用的客户端

1
2
3
4
5
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
sudo cp src/redis-cli /usr/local/bin/

使用

1
redis-cli -h

Node.js

node-v16.15.0

1
2
3
4
5
6
7
8
mkdir /usr/local/node
cd /usr/local/node
wget https://npmmirror.com/mirrors/node/v16.15.0/node-v16.15.0-linux-x64.tar.xz
tar xf node-v16.15.0-linux-x64.tar.xz
rm -rf node-v16.15.0-linux-x64.tar.xz

ln -s /usr/local/node/node-v16.15.0-linux-x64/bin/npm /usr/local/bin/
ln -s /usr/local/node/node-v16.15.0-linux-x64/bin/node /usr/local/bin/

Ruby安装

1
2
3
4
5
6
7
wget https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.2.tar.gz
tar zxvf ruby-3.1.2.tar.gz
rm -rf ruby-3.1.2.tar.gz
cd ruby-3.1.2
./configure
make
sudo make install

Go环境

1.Linux

go 官网 :https://golang.org/dl/

安装教程:https://www.runoob.com/go/go-environment.html

1
2
3
4
5
6
7
8
9
10
11
12
wget https://golang.org/dl/go1.17.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.17.linux-amd64.tar.gz
rm -rf go1.17.linux-amd64.tar.gz go1.17.linux-amd64




vim /etc/profile
# go
export PATH="$PATH:/usr/local/go/bin"

source /etc/profile

设置国内代理 !!!! VPS在国外可忽略

https://github.com/goproxy/goproxy.cn/blob/master/README.zh-CN.md

1
2
export GO111MODULE=on
export GOPROXY=https://goproxy.cn

2.windows

在powershell运行,切换国内代理。

1
2
$env:GO111MODULE = "on"
$env:GOPROXY = "https://goproxy.cn"

Docker 环境

1.检查版本

1
cat /etc/redhat-release

2.安装

1
2
3
4
5
6
7
8
9
10
11
12
13
yum install -y gcc gcc-c++
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum -y install docker-ce docker-ce-cli containerd.io docker-compose
systemctl start docker
systemctl enable docker
docker version
docker run hello-world
yum update -y
curl -L https://mirror.ghproxy.com/https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose

3.卸载docker

1
2
3
systemctl stop docker 
yum -y remove docker-ce
rm -rf /var/lib/docker