VPS 配置记录

  • A+
所属分类:安全博客

前言

日常学习工作总需要一台 Linux 主机,但是每次需要配置环境的时候会很繁琐,因此用本文记录一下新装 Linux 的环境配置命令,方便日后使用。

GCP开启密码与root用户登陆

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sudo -i   //切换到root用户
vi /etc/ssh/sshd_config //编辑文件

#### 允许 root 权限登录
# Authentication:
# 限制用户必须在指定的时限内认证成功
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

#### 开启密码登录
# Change to no to disable tunnelled clear text passwords
PasswordAuthentication yes

# 重启 SSH
service sshd restart

# 修改 root 密码
passwd root

VPS 配置记录

VPS 配置记录

修改主机名

1
2
3
echo 'Xstark' >/etc/hostname
hostname `cat /etc/hostname`
bash

CentOS 更换源

1
2
3
4
5
6
7
8
9
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
yum -y install wget

# 查看是否修改成功
cat /etc/yum.repos.d/CentOS-Base.repo

# 生成缓存 升级软件包
yum makecache
yum -y update

CentOS 开启 SSH

1
2
3
4
5
6
7
# 检测是否安装 openssh-server
yum list installed | grep openssh-server
# 没有输出的话需要执行命令
yum install openssh-server

# 编辑 sshd 的配置文件
vim /etc/ssh/sshd_config

VPS 配置记录

AddressFamily
指定 sshd(8) 应当使用哪种地址族。取值范围是:”any”(默认)、”inet”(仅IPv4)、”inet6”(仅IPv6)。

Python

1
2
# 安装 Python3.6
yum -y install python36

Java

1
2
3
4
# 安装 jdk1.8
yum install java-1.8.0-openjdk* -y
# 查看版本
java -version

Nginx

1
2
3
4
5
6
7
8
9
# 安装:
yum install nginx
# 启用并启动Nginx服务:
$ sudo systemctl enable nginx
$ sudo systemctl start nginx
# 停止服务:
$ sudo systemctl stop nginx
# 要验证服务是否正在运行,检查其状态:
$ sudo systemctl status nginx

Mysql

1
2
sudo dnf install mysql-server
sudo systemctl start mysqld.service

查询 Mysql 状态:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sudo systemctl status mysqld

● mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabl>
Active: active (running) since Sat 2021-02-20 20:33:45 PST; 1min 26s ago
Process: 10223 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUC>
Process: 10096 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exite>
Process: 10072 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCE>
Main PID: 10178 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 4773)
Memory: 295.0M
CGroup: /system.slice/mysqld.service
└─10178 /usr/libexec/mysqld --basedir=/usr

Feb 20 20:33:38 Xstark systemd[1]: Starting MySQL 8.0 database server...
Feb 20 20:33:38 Xstark mysql-prepare-db-dir[10096]: Initializing MySQL database
Feb 20 20:33:45 Xstark systemd[1]: Started MySQL 8.0 database server.
lines 1-16/16 (END)

设置服务器启动时启动

1
sudo systemctl enable mysqld

设置安全策略

1
2
0.0.0.0 然后mysql.user  root的host 设置成%
flush

Ubuntu16.04 升级 Python3.8

下载源码

1
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz

解压源码

1
tar -xvzf Python-3.8.0.tgz

进入目录

1
cd Python-3.8.0

安装python3.8.0依赖

1
2
3
4
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libffi-dev

配置安装路径

1
./configure --with-ssl --prefix=/usr/local/python3

编译

1
make

安装

1
sudo make install

删除软链接

1
2
sudo rm -rf /usr/bin/python3
sudo rm -rf /usr/bin/pip3

新建软链接

1
2
sudo ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3
sudo ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3

检查是否安装成功

1
2
3
4
python3
Python 3.8.0 (default, Mar 27 2021, 12:35:37)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

升级后无法使用 PIP3 问题解决办法

报错信息如下:

VPS 配置记录

原因是是找不到 lsb_release 模块

使用下面的命令查找:

1
2
3
4
sudo find / -name 'lsb_release.py'
/usr/share/pyshared/lsb_release.py
/usr/lib/python2.7/dist-packages/lsb_release.py
/usr/lib/python3/dist-packages/lsb_release.py

复制到报错的目录下:

1
sudo cp /usr/lib/python3/dist-packages/lsb_release.py /usr/local/python3/lib/python3.8/

问题解决:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[email protected]:~#  pip3 install
ERROR: You must give at least one requirement to install (see "pip help install")
WARNING: You are using pip version 19.2.3, however version 21.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

[email protected]:~# pip3 install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/fe/ef/60d7ba03b5c442309ef42e7d69959f73aacccd0d86008362a681c4698e83/pip-21.0.1-py3-none-any.whl (1.5MB)
|████████████████████████████████| 1.5MB 15.9MB/s
Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
Successfully uninstalled pip-19.2.3
Successfully installed pip-21.0.1

参考链接:https://choudalao.com/article/100

FROM : lintstar.top , Author: 离沫凌天๓

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: