Ubuntu

拍摄快照

在虚拟机安装好、配置号后各拍摄一次快照,并存储。

可在虚拟机出错后回滚

Root用户

Ubuntu默认不能以 Root用户身份直接登录

因此,正常操作时在需要调用 root权限时,必须使用 sudo命令来获取部分权限

Root直接登录

  • 在现有用户下为 root帐户设置密码

    sudo passwd root
    # 现在的用户的密码
    # root用户密码
    # 确认密码
  • 修改文件: /etc/pam.d/gdm-autologin ,用 # 注释掉

    auto retuired pam_succeed_if.so user != root quiet_success
  • 修改文件 /etc/pam.d/gdm-password

    auto retuired pam_succeed_if.so user != root quiet_success

临时转为 Root

在配置好 Root密码后,使用如下命令:

su root
# 密码

这之后的所有操作都不需要再加 sudo了

退出命令:

exit

脚本文件

权限

如果文件没有可运行权限,则不能使用 ./xxx的方式

此时可以选择 加权限或者使用其他命令运行的方式,如:

chmod o+x hello.sh
chmod u+x hello.sh
chmod 777 hello.sh
  • o:表示 other
  • u:表示 属主,user
  • g:表示 属组,group
  • 777:可读权限为4 可写为2 可执行为1;针对某文件,一种角色的权限可以表示为 4/2/1的和

bash

如果 xxx.sh没有 x权限,则可以使用

bash xxx.sh
sudo bash xxx.sh

此时,在文件内部的第一行必须标记为:

#!/bin/sh

来帮助找到 sh命令

python

如果 xxx.py没有 x权限,则可以使用

python xxx.py

此时,文件内部的第一行必须标记为:

#!bin/python3

网络相关

关于 apt换源

1)先将 /etc/apt/sources.list备份

cp sources.list sources.list.bak

2)然后修改sources.list中的源

gedit sources.list

修改为

# 清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# 网易源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

3)更新 apt

sudo apt-get update

4)然后就可以正常使用了

关于虚拟机网络

可选的为 NAT模式,桥接模式和自定义模式

NAT

使用 VMnet8的网卡

桥接

类似和电脑并联

一般选用桥接,便于连接 xshell

关于SSH

使用 apt下载以下内容

sudo apt-get install net-tools
sudo apt-get install openssh-server

然后使用 ifconfig查看虚拟机 IP

使用 xshell进行连接

关于FTP

宿主机和虚拟机可以通过 FTP协议互相传文件

XFTP

使用 xshell的 xftp

下载免费版 xftp后,在 xshell连接的情况下,使用 xftp进行宿主机和虚拟机的数据交互

lrzsz

可以使用 rz命令和 sz命令

先用 apt安装

sudo apt install lrzsz

然后就可以使用 rz命令将宿主机的东西传到虚拟机中

使用 sz命令将虚拟机中的东西传到宿主机中

但是貌似还是只能在 xshell中使用

关于防火墙和端口

先用 apt安装

sudo apt install ufw

开放单个端口

sudo ufw allow 80
sudo ufw allow 22

关闭单个端口

sudo ufw delete allow 80

查看防火墙的状态

sudo ufw status

重启防火墙

sudo ufw reload

关闭防火墙

sudo ufw disable

设置外来访问的默认权限(拒绝)

sudo ufw default deny

Java相关

配置 Java

直接安装Java

直接安装可以不用配置路径(好像)

主要,我也不知道直接 apt安装到了哪里,科学的讲估计是在 /usr/local下

# 直接在控制台输入 java或者 javac
# 会提示 没有该命令,然后会提示推荐安装的内容
# 可以装 jre也可以装 jdk
# 直接使用 apt即可安装

直接安装,虽然没有配置路径,但是貌似是存在 JAVA_HOME的,因为 tomcat可以识别到。

wget 下载安装

使用 wget命令安装

sudo wget  某个版本的java的tar.gz文件

下载后正常解压,可以解压到 /usr/local下,也可以解压到 /opt下

tar -zxvf 压缩文件名 -C 解压后存储的路径

手动配置路径

用户环境变量

针对每个用户的环境变量,只有本用户才能有效

每个用户的家目录下有个隐藏文件 .profile

ls -a /home/zhao/.profile

在 CentOS下,叫做 .bash_profile好像

可以使用 gedit或者vim修改其内容,建议先备份

可在其内部添加如下:

export JAVA_HOME=/opt/jdk-1.8.0
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

系统环境变量配置

在 /etc/profile.d 目录下新建一个脚本,命名任意,但要以 .sh为后缀

内部配置类似 上面

注意:如果,是手动解压安装 Java的,必须手动配置路径,建议配置为系统路径

配置 Tomcat

使用 wget 从官网上下载,注意版本号和 JDK版本的联系

也可以使用 XFTP 或者 rz命令从宿主机中上传

下载后解压

tar -zxvf apache-tomcat-版本号 -C 解压后的路径

然后,可以进入到该目录下查看,会发现只有 root才有访问权限

于是需要切换 root用户

su root
# 密码

在 bin目录下启动:./startup.sh

在 bin目录下关闭:./shutdown.sh

开启tomcat后,在宿主机与虚拟机上都能访问到发布的项目

# 宿主机
虚拟机ip:8080 # 虚拟机
localhost:8080

备份之后 修改配置文件

gedit conf/server.xml

配置 Redis

直接 apt安装 redis-server

sudo apt install redis-server

查看 redis状况

service redis-server status

在 /etc/redis/redis.conf 下修改redis配置

gedit redis.conf

​ 注释掉 bind 127.0.0.1

​ 添加密码 requirepass

重启 redis-server

登录 redis-cli尝试

在宿主机上登录 Redis Desktop Manager尝试连接虚拟机上的 redis

配置 MySQL

安装MySQL

1)通过 apt安装 MySQL

sudo apt-get install mysql-server

2)初始化配置

sudo mysql_secure_installation

#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (选择N ,不会进行密码的强校验) #2
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入) #3
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (选择N,不删除匿名用户) #4
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N (选择N,允许root远程连接) #5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (选择N,不删除test数据库) #6
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (选择Y,修改权限立即生效)

3)检查 MySQL状态

systemctl status mysql.service

4)配置远程访问

修改 /etc/mysql/mysql.conf.d/mysqld.cnf

# bind 127.0.0.1

5)登录 mysql进行修改

sudo mysql -uroot -p

use mysql;

select host,user,plugin from user; -- 此时 root的 plugin和其他的不一样,表示只能用权限登录

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
ALTER USER 'root'@'localhost' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER;
UPDATE user SET host = '%' WHERE user = 'root'; flush privileges;
quit;

之后,切换为普通用户登录 mysql

尝试使用 宿主机的 navicat登录 虚拟机上的 mysql

MySQL卸载

1)查看依赖项

dpkg --list|grep mysql

2)卸载

sudo apt-get remove mysql-common
sudo apt-get autoremove --purge mysql-server-5.7

3)清除残留数据

dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P

4)查看依赖项

dpkg --list|grep mysql

5)删除依赖项

sudo apt-get autoremove --purge mysql-apt-config

Ubuntu小配置的更多相关文章

  1. Ubuntu下配置python完成爬虫任务(笔记一)

    Ubuntu下配置python完成爬虫任务(笔记一) 目标: 作为一个.NET汪,是时候去学习一下Linux下的操作了.为此选择了python来边学习Linux,边学python,熟能生巧嘛. 前期目 ...

  2. 转[开发环境配置]在Ubuntu下配置舒服的Python开发环境

    在Ubuntu下配置舒服的Python开发环境 Ubuntu 提供了一个良好的 Python 开发环境,但如果想使我们的开发效率最大化,还需要进行很多定制化的安装和配置.下面的是我们团队开发人员推荐的 ...

  3. Ubuntu下配置L2TP

    发现PPTP已经不可用了,不知是不是又被墙了.只能尝试L2TP了. Ubuntu可视化配置界面network-manager默认是没有L2TP配置选项的,需要安装第三方插件软件: sudo apt-a ...

  4. ubuntu环境配置之vi 配置【转载】

    ubuntu环境配置之vi 配置 [日期:2014-02-10] 来源:Linux社区  作者:zhonghe1114 [字体:大 中 小]   Android的源码开发,几乎离不开Linux,Lin ...

  5. [C#]使用 C# 代码实现拓扑排序 dotNet Core WEB程序使用 Nginx反向代理 C#里面获得应用程序的当前路径 关于Nginx设置端口号,在Asp.net 获取不到的,解决办法 .Net程序员 初学Ubuntu ,配置Nignix 夜深了,写了个JQuery的省市区三级级联效果

    [C#]使用 C# 代码实现拓扑排序   目录 0.参考资料 1.介绍 2.原理 3.实现 4.深度优先搜索实现 回到顶部 0.参考资料 尊重他人的劳动成果,贴上参考的资料地址,本文仅作学习记录之用. ...

  6. 《一个操作系统的实现》 ubuntu系统环境配置

    <一个操作系统的实现> ubuntu系统环境配置 电脑之前已经安装了gcc. 一.nasm安装:sudo apt-get install nasm或官网下载http://sourcefor ...

  7. Ubuntu中配置Java环境变量时,出现command not found问题解决记录

    百度出Ubuntu中配置Java环境变量时,在利用sudo gedit /etc/profile 对profile编辑后, 在terminal中输入 sudo source /etc/profile, ...

  8. SecureCRT连接虚拟机(ubuntu)配置

    使用SecureCRT连接虚拟机(ubuntu)配置记录   这种配置方法,可以非常方便的操作虚拟机里的Linux系统,且让VMware在后台运行,因为有时候我直接在虚拟机里操作会稍微卡顿,或者切换速 ...

  9. Ubuntu下配置C/C++开发环境

    在 Ubuntu 下配置 C/C++ 开发环境 转自:白巴的临时空间 Submitted by 白巴 on 2009-04-27 19:52:12. 学习笔记 虽然 Ubuntu 的版本已经是9.04 ...

随机推荐

  1. hdu3706 Second My Problem First

    Problem Description Give you three integers n, A and B.  Then we define Si = Ai mod B and Ti = Min{ ...

  2. Codeforces ECR86 C. Yet Another Counting Problem(规律,区间)

    题意:给你两个正整数a和b,询问q次,每次给你一个区间[l,r],问[l,r]中有多少数字满足:x%a%b!=a%b%a. 题解:看公式无从下手的题,一般都是要找规律的.首先,我们知道,假如x%a%b ...

  3. 牛客编程巅峰赛S1第6场 - 黄金&钻石&王者 B.牛牛摆放花 (贪心)

    题意;将一组数重新排序,使得相邻两个数之间的最大差值最小. 题解:贪心,现将所有数sort一下,然后正向遍历,将数分配到新数组的两端,然后再遍历一次维护一个最大值即可. 代码: class Solut ...

  4. 国产网络测试仪MiniSMB - 双击就可以直接编辑数据报文字段(如IP地址)

    国产网络测试仪MiniSMB(www.minismb.com)是复刻smartbits的IP网络性能测试工具,是一款专门用于测试智能路由器,网络交换机的性能和稳定性的软硬件相结合的工具.可以通过此以太 ...

  5. JQuery和js实现简单的霓虹灯

    注意jquery文件的路径要正确. <!DOCTYPE html> <html> <head> <title></title> <me ...

  6. Sentry 高级使用教程

    Sentry 高级使用教程 Sentry versions https://github.com/getsentry/sentry-docs https://github.com/getsentry/ ...

  7. Apple Watch Series 6 字母图案 (图解教程)

    Apple Watch Series 6 字母图案 (图解教程) Apple Watch Series 6 自定义文字 如何开启 字母图案 solution 1 选择 彩色 表盘️ PS: 该复杂功能 ...

  8. chroot vs docker

    chroot vs docker chroot Linux A chroot on Unix operating systems is an operation that changes the ap ...

  9. js bitwise operation all in one

    js bitwise operation all in one 位运算 & 按位与 | 按位或 ^ 按位异或 / XOR let a = 5; // 000000000000000000000 ...

  10. Google Advanced Search Skills

    Google Advanced Search Skills site: