新装ubuntu电脑的一些调整
- 必要命令的安装
- 必要开发工具的安装
更换国内软件源
/etc/apt/sources.list文件,后面添加下面地址用来添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse\
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
然后更新一下
sudo apt update
sudo apt upgrade
然后是清华软件源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
上面步骤重复一下就好,目前就只有这个是可有,其他的博客上的软件源用了会有报错,记录一下。因为经常用python和其他一些关键命令需要python的一些类库相关的头文件和pkg-config,这些都是被linux分拆成一个个dev包的,所以这里给补上:
sudo apt install python3-dev
添加pip软件源
在用户目录下编写.pip/pip.conf文件:
[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
然后在使用更新包pip/pip3包的时候会有一个警告:
WARNING: The scripts pip, pip3 and pip3.10 are installed in '/home/xxx/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
那就按照警告说的,添加用户变量吧,编辑~/.bashrc文件
#添加
export PATH=/home/xxx/.local/bin:$PATH
然后source一下,就可以继续更新pip了。
添加docker加速源和go加速
首先是查看docker版本,然后针对性进行配置,如下:
jam@jam:~$ docker version
Client: Docker Engine - Community
Version: 23.0.0
API version: 1.42
Go version: go1.19.5
Git commit: e92dd87
Built: Wed Feb 1 17:47:51 2023
OS/Arch: linux/amd64
Context: default
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version": dial unix /var/run/docker.sock: connect: permission denie
这种情况就是权限不足,给docker分一点:
sudo chmod 777 /var/run/docker.sock
然后再查看docker版本,这时候信息就很全面了,没有权限报错了,我的docker api版本是1.42,根据下面网址配置阿里云的镜像加速服务:
阿里云镜像加速申请和配置指南
配置nginx服务和redis还有mq服务
docker作为容器服务的提供者,很多人用它来打包项目环境,然后在需要的地方直接pull镜像就可以复用了,企业也很多都使用docker来作为流水线的服务提供者,使用k8s来进行管理即可。这里把nginx,redis和mq都放在不同的docker镜像中,要用的时候再跑起来:
docker search nginx
docker pull nginx:latest
# docker images命令查看拉取的镜像
#后台运行,-p参数映照容器80端口到本机8080端口
docker run --name nginxtest -p 8080:80 -d nginx
docker ps -a #查看容器的运行情况
#同样的步骤都来几遍
docker run -itd --name redisserv -p 8081:6379 redis
# 设置访问需要密码
docker run -itd --name mongoserv -p 8082:27017 mongo --auth
#mq后面补上
然后就是配置go的加速:
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn
配置了国内的加速镜像七牛云,说实话,不知道它还能顶多久。
配置一下flask和django的虚拟开发环境
这里使用virtualenv:
pip install virtualenv
# 创建对应目录,然后使用virtualenv来设置为虚拟工程目录
virtualenv myproject
#或者指定python版本
virtualenv -p 绝对路径/python myproject
# 激活环境,退出就用deactive命令
source myproject/bin/activate
#安装,前后可以用pip list查看安装先后包变化
pip install flask
#安装好以后可以进python交互界面查看flask版本
python3
>>>flask.__version__
'2.2.2'
简单写一个helloflask:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def sayhello():
return "hello, flask."
if __name__ == '__main__':
app.run()
然后使用python app.py或者flask run都行,不过flask run一定要编写app.py名称的源文件,这个是它的设定,然后访问127.0.0.1:5000本地回流地址即可,默认是5000端口的。
django准备
pip install django
#进入交互界面
python3
>>>import django
>>>django.get_version()
'4.1.6'
>>>exit()
# 创建django项目
django-admin startproject www
cd www
python manage.py runserver
然后就可以访问回流地址的8000端口查看结果了。至此,flask和django都算搞定了。
后面遇到的问题
问题伊始,是访问github的时候发现网络有问题,然后就ping了一下,发现一直卡着,但也不结束,感觉问题有点麻烦,跟着网上一篇博客进行调整,发现是能解决问题,但没有完全解决问题。首先,我安装的是ubuntu20.04的系统,这是大前提。
修理过程:
现象
# 就这么一直卡着,但每退出去
jam:~$ ping github.com
PING github.com (20.205.243.166) 56(84) bytes of data.
^C
--- github.com ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3071ms
# 检查一下网络是否可通
jam:~$ ping www.bing.com
PING china.bing123.com (202.89.233.100) 56(84) bytes of data.
64 bytes from 202.89.233.100 (202.89.233.100): icmp_seq=1 ttl=119 time=42.7 ms
64 bytes from 202.89.233.100 (202.89.233.100): icmp_seq=2 ttl=119 time=42.2 ms
64 bytes from 202.89.233.100 (202.89.233.100): icmp_seq=3 ttl=119 time=44.4 ms
^C
--- china.bing123.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 42.196/43.093/44.414/0.953 ms
听说是dns污染的问题,还可能是运营商,不清楚。
那就配置一下dns吧,在谷歌专用的8.8.8.8和另外的1.1.1.1可ping通的情况下,配置/etc/resolv.conf,打开后看到一段未知配置:
# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 127.0.0.53
options edns0 trust-ad
search .
未知代码是指nameserver那里的配置,没印象配过这种,不过删掉这部分添加两个域名解析服务器,修改成下面这样:
nameserver 8.8.8.8
nameserver 1.1.1.1
不过,上面的文件注释是伏笔,注意(Do not edit)。
修改了以后,再去ping一下github.com进行测试,发现还是不行,nslookup测试一下:
# 如果显示没有nslookup可以这么解决
sudo age install dnsutils
jam:~$ nslookup github.com 8.8.8.8
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: github.com
Address: 20.205.243.166
jam:~$ ping 20.205.243.166
PING 20.205.243.166 (20.205.243.166) 56(84) bytes of data.
^C
--- 20.205.243.166 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3060ms
jam:~$ nslookup github.com 1.1.1.1
Server: 1.1.1.1
Address: 1.1.1.1#53
Non-authoritative answer:
Name: github.com
Address: 192.30.255.113
jam:~$ ping 192.30.255.113
PING 192.30.255.113 (192.30.255.113) 56(84) bytes of data.
64 bytes from 192.30.255.113: icmp_seq=1 ttl=48 time=262 ms
64 bytes from 192.30.255.113: icmp_seq=2 ttl=48 time=264 ms
64 bytes from 192.30.255.113: icmp_seq=3 ttl=48 time=203 ms
^C
--- 192.30.255.113 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 203.132/242.843/263.700/28.091 ms
jam:~$
上面的检测结果发现,8.8.8.8这个服务器要么被搞了,要么就是上面的ip被搞了,现在把1.1.1.1放在8.8.8.8前面试一下:
# 修改/etc/resolv.conf如下:
nameserver 1.1.1.1
nameserver 8.8.8.8
# 然后测试
jam:~$ ping github.com
PING github.com (192.30.255.113) 56(84) bytes of data.
64 bytes from lb-192-30-255-113-sea.github.com (192.30.255.113): icmp_seq=1 ttl=48 time=306 ms
64 bytes from lb-192-30-255-113-sea.github.com (192.30.255.113): icmp_seq=2 ttl=48 time=232 ms
64 bytes from lb-192-30-255-113-sea.github.com (192.30.255.113): icmp_seq=3 ttl=48 time=249 ms
^C
--- github.com ping statistics ---
4 packets transmitted, 3 received, 25% packet loss, time 3005ms
rtt min/avg/max/mdev = 232.454/262.432/306.175/31.631 ms
jam:~$
好,四分之一的丢包率,可以接受。但实际上后续还是遇上了同样的问题,还以为是github用了ssh,搞得又回头重新配了一次ssh-key,但当我重新回到resolv.conf一看,又回到最开始的地方才发现它自己偷偷修改了。。。。。。
这种dns的配置问题,才让我发现修改resolv.conf没啥用,有博客介绍说是dhcp的问题,但说法太多,了解太少,只能照做,没法判断:
# 修改/etc/systemd/resolved.conf,修改DNS一项
DNS=1.1.1.1 8.8.8.8
# 重启服务
jam:~$ sudo systemctl restart systemd-resolved
# 设定开机自启
jam:~$ sudo systemctl enable systemd-resolved
# 保存备份文件
jam:~$ sudo mv /etc/resolv.conf /etc/resolv.conf.bak
# 重新映射服务到etc目录下,如果ln -l查看/etc/resolv.conf会发现这个映射关系
jam:~$ sudo ln -s /run/systemd/resolve/resolv.conf /etc/
全程要使用root权限执行,否则总会有各种权限限制,执行完以后,应该就可以在/etc/resolv.conf中看到新的两个nameserver了。重启看看效果,嗯,阔以,至少域名解析应该暂时没问题了。另外在上面有记录电脑系统是ubuntu20.04,所以很多设置都会有变动,系统好像也放弃了NetworkManger其他的管理来着,用上了netplan。慢慢记录吧。
新装ubuntu电脑的一些调整的更多相关文章
- 远程访问ubuntu电脑
遇到的问题: 由于疫情的影响,一直在家划水,这几天突然想看看能不能通过我手中的笔记本远程访问那台在学校"落灰"的工作站呢? 目前有一台闲置的电脑,多个键已经"失灵&quo ...
- 关于新装ubuntu系统update失败和build-essential失败的解决办法
我是12月4日在新电脑上的vmware-workstation 10 上安装的ubuntu14.04LTS,但安装后再校园环境下总是build-essential失败,上网一查,说是要先update, ...
- Ubuntu 16.04虚拟机调整窗口大小自适应Windows 7
Windows 7上Ubuntu 16.04虚拟机安装成功后,默认的虚拟机窗口比较小,需要适当调整,才能把虚拟机的屏幕放大, 适合使用,以下介绍调整方法. 安装VMware Tools 启动虚拟机, ...
- Ubuntu 10.04 分辨率调整
最近学长们看了我的本本都在问我,显卡驱动是不是出现什么问题了···分辨率这么差.当时我的分辨率是1024X768,于是我就想修改我的屏幕分辨率改成1280X800.本来很简单的事情,我做起来却非常的曲 ...
- ubuntu 铺满桌面 调整字体 安装firefox中文版
ubuntu 铺满桌面 安装 open-vm-tools sudo apt-get install open-vm-tools sudo apt-get install open-vm* . rebo ...
- ubuntu 14.04 分辨率调整 -- xrandr命令
问题描述: 自己在安装ubuntu-kylin 14.04 TLS系统成功后,在调整分辨率的时候(系统设置--显示)发现分辨率的选项只有1024x768以及800x600两个选项,而台式机的外接显示屏 ...
- 新装Ubuntu后的一些配置
一:Ubuntu 16.04 开启root用户和使用root用户登陆 1. 编辑/etc/lightdm/lightdm.conf autologin-guest=false autologin-us ...
- 新装ubuntu 12.04 , 使用技巧
*********************************************** 一.让Ubuntu 12.04开机默认进入命令行模式. 修改 /etc/default/grubGRUB ...
- 三十项调整助力 Ubuntu 13.04 更上一层楼
在Ubuntu 13.04 Raring Ringtail安装完成之后,我们还有三十项调整需要进行. 1.Ubuntu 13.04 Raring Ringtail安装完毕后,我又进行了一系列工作 大家 ...
- vmware下ubuntu14.04调整分辨率
很多人在vmware中安装ubuntu时,为了调整屏幕分辨率,都去下载并安装vmware-tools.其实,这是没有必要的.如果你需要vmware和宿主机实现共享,或者为了使文件能拖进拖出,再或者是需 ...
随机推荐
- RPC简介及框架选择-copy
简单介绍RPC协议及常见框架,对比传统restful api和RPC方式的优缺点.常见RPC框架,gRPC及序列化方式Protobuf等 HTTP协议 http协议是基于tcp协议的,tcp协议是流式 ...
- Sorcerer pg walkthrough Intermediate
nmap ┌──(root㉿kali)-[~/lab] └─# nmap -p- -A 192.168.192.100 Starting Nmap 7.94SVN ( https://nmap.org ...
- react时时获取表单数据
import React, { Component } from "react"; export class TestHanderClick extends Component { ...
- shell学习之保存数据库
自动备份 Mysql 数据库脚本 #!/bin/bash #author by wxp #used to backup mysql practise USER=root PASSWD=1234 HOS ...
- "最新"部署幻兽帕鲁游戏服务器及开局经验分享
Banner 2024,<幻兽帕鲁><雾锁王国>等游戏爆火!那么如何快速拥有一个可以跟小伙伴们愉快玩耍的服务器呢?社区里不少小伙伴已经给出了自己的最佳实践,你甚至不需要懂技术, ...
- [JOI 2020 Final] 火事 题解
给一篇题解.(下面这张图是从 luogu 上粘贴的,因为不太会画图) 其中纵坐标为 \(t\),横坐标为 \(a_i\). 发现同颜色块只有平行四边形和直角梯形(等腰直角三角形)两种情况. 可以将直角 ...
- Linux编写一个自己的命令
Linux编写一个自己的命令 编译一个.c文件,生成可执行文件out.out只有在当前目录下可以执行. 而命令可在任何路径执行 想让out可以在任意路径执行,有以下两种办法 1.将执行文件添加到 /b ...
- Trae初体验
前情 自从AI IDE面世以来,网络上到处流传程序员要失业了,小白也能轻松完成程序开发了,某某0基础靠AI上架了苹果应用,平时工作也有偶尔用用AI工具的我,都觉得这些都是标题党文章不予理会的,直到看到 ...
- Linux 提升CPU利用率
由于同学项目CPU利用率不高,客户要降他们服务器配置,所以下下策. # 提升一个核CPU利用率 cat /dev/urandom | gzip -9 > /dev/null # 提升更大的CPU ...
- 如何在 CentOS 7 linux上安装和使用 FFmpeg
SSH首选FinalShell 1.下载解压 wget http://www.ffmpeg.org/releases/ffmpeg-5.1.tar.gz tar -zxvf ffmpeg-5.1.ta ...