Ubuntu配置开发环境


前言

对已经配置的开发环境做一个记录,不然有些装的东西老是忘记


1.配置文件解读

配置文件主要来自etc目录下和home目录下的隐藏文件,以下对常见配置文件进行解读:
/etc/rc.local
此脚本在每个多用户运行级别结束时执行,开机自启,我们可以将网络配置放在这里

/etc/init.d
开机启动有关的文件及可执行程序

/etc/exports


home目录下:
.profile
用户登录后会加载此文件,此文件基本是运行.bashrc中的内容:

# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n || true

用户登录 ->> 加载~/.bash_profile --> bash_profile中配置了首先是使~/.bashrc生效


.bashrc
.bashrc有很妙的用处:
1.自动运行命令行
可以添加一条命令行,每次打开bash时都会自动运行,比如:

echo "Hi~"
cd ~/Desktop

2.alias
用alias可以给常用的命令行起一个简短的别名。

alias la='ls -a'
alias ll='ls -l'
alias gst='git status -sb'
alias ga='git add'
alias ga.='git add .'
alias gc='git commit'
alias gc.='git commit .'

3.设置PATH等环境变量
如果将自己写的脚本放在~/local目录,进到local目录
pwd
复制local的绝对路径
在~/.bashrc里写入

export PATH="local的绝对路径:$PATH"

4.提示符
当打开一个控制台(console) 时,最先看到的就是提示符(prompt),如:[root@localhost ~]#
在默认设置下,提示符将显示用户名、主机名(默认是’localhost’)、当前所在目录。
按照传统,最后一个字符可以标识普通用户($),还是’root’(#)。
可以通过 $PS1 变量来设置提示符。
我的root下的$PS1:

root@ubuntu:~# echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$

普通用户下的PS1:

i2y@ubuntu:/$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$

那我们可以在.bashrc中修改PS1,就可以改变提示符。
其中可用字符的含义在 man bash 的’PROMPTING’部分有说明:

 			  \a     an ASCII bell character (07)
              \d     the date in "Weekday Month Date" format (e.g., "Tue May 26")
              \D{format}
                     the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in  a  locale-specific
                     time representation.  The braces are required
              \e     an ASCII escape character (033)
              \h     the hostname up to the first `.'
              \H     the hostname
              \j     the number of jobs currently managed by the shell
              \l     the basename of the shell's terminal device name
              \n     newline
              \r     carriage return
              \s     the name of the shell, the basename of $0 (the portion following the final slash)
              \t     the current time in 24-hour HH:MM:SS format
              \T     the current time in 12-hour HH:MM:SS format
              \@     the current time in 12-hour am/pm format
              \A     the current time in 24-hour HH:MM format
              \u     the username of the current user
              \v     the version of bash (e.g., 2.00)
              \V     the release of bash, version + patch level (e.g., 2.00.0)
              \w     the current working directory, with $HOME abbreviated with a tilde (uses the value of the PROMPT_DIRTRIM variable)
              \W     the basename of the current working directory, with $HOME abbreviated with a tilde
              \!     the history number of this command
              \#     the command number of this command
              \$     if the effective UID is 0, a #, otherwise a $
              \nnn   the character corresponding to the octal number nnn
              \\     a backslash
              \[     begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
              \]     end a sequence of non-printing characters


.bash_logout 登出此用户

# ~/.bash_logout: executed by bash(1) when login shell exits.

# when leaving the console clear the screen to increase privacy

if [ "$SHLVL" = 1 ]; then
    [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi

root用户下没有但是其他用户下有

2.网络

ifconfig:
查看、配置、启用或禁用网络接口(网卡)的工具
ifconfig 是一个用来查看、配置、启用或禁用网络接口的工具,这个工具极为常用的。比如我们可以用这个工具来配置网卡的IP地址、MAC地址、掩码、广播地址等。值得一说的是用ifconfig 为网卡指定IP地址,这只是用来调试网络用的,并不会更改系统关于网卡的配置文件。如果您想把网络接口的IP地址固定下来,目前有三个方法:一是通过各个发行和版本专用的工具来修改IP地址;二是直接修改网络接口的配置文件;三是修改特定的文件,加入ifconfig 指令来指定网卡的IP地址,比如在redhat或Fedora中,把ifconfig 的语名写入/etc/rc.d/rc.local文件中;

一些网络配置文件:
1.IP地址配置文件: /etc/network/interfaces打开后里面可设置DHCP(动态配置ip)或手动设置静态ip。前面auto eth0,让网卡开机自动挂载.
可配置静态ip如下:

auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1

2./etc/resolv.conf默认网关和DNS: 配置DNS客户端,它包含了DNS服务器地址和域名搜索配置,每一行应包含一个关键字和一个或多个的由空格隔开的参数。设置静态ip就没有自动获取到DNS服务器了我们设置一下:
/etc/resolvconf/resolv.conf.d/head中添加了一行:nameserver: 8.8.8.8

3./etc/hosts文件 当机器启动时,在可以查询DNS以前,机器需要查询一些主机名到IP地址的匹配。这些匹配信息存放在/etc/hosts文件中。在没有域名服务器情况下,系统上的所有网络程序都通过查询该文件来解析对应于某个主机名的IP地址。

4./etc/NetworkManager/NetworkManager.conf(不知道为什么要改,先放着)

[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq
[ifupdown]
managed=false
文件修改为:
[main]
plugins=ifupdown,keyfile,ofono
#dns=dnsmasq
[ifupdown]
managed=true

一些命令:
关闭、打开网络:
ifconfig ens33 down
ifconfig ens33 up

刷新ip配置:
ip addr flush ens33
systemctl restart networking.service

重启网络服务:
/etc/init.d/networking restart

重启network-manager:
service network-manager restart

刷新resolv.conf的配置:
resolvconf -u

问题:
我这出了一点问题,配置为静态IP就使用不了DNS,那我们这里先不去解决了,
上网就用dhcp,桥接模式必须设置为自动,这样使系统可以找到可使用的连接。
连接开发板就使用静态ip,桥接模式设置为有线模式

我的uboot去ping Windows或Linux时,ping通后会自动关闭网卡(我们可以在Windows的控制面板中看出来),导致uboot ping主机可以ping通,但是Linux ping uboot时不通,其实是没问题的(在uboot ping Linux的同时让Linux去ping uboot 是可以ping通的,因为uboot在那一小段时间内打开了自己的网卡,也因为是桥接的方式,Linux只能在那个时候和uboot建立连接)

3.搭建tftp服务器

1.安装
apt-get xinetd
apt-get install tftp-hpa tftpd-hpa //分别是客户端和服务器
2.建立传输目录:
mkdir /tftpboot #我在根目录下创建的
chmod 0777 /tftpboot
不建立也行,tftp默认目录:/var/lib/tftpboot
3.配置
/etc/xinetd.conf

 # Simple configuration file for xinetd
  #
  # Some defaults, and include /etc/xinetd.d/
  defaults
  {
  # Please note that you need a log_type line to be able to use log_on_success
  # and log_on_failure. The default is the following :
  # log_type = SYSLOG daemon info
  }
  includedir /etc/xinetd.d

/etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot" # 这里是你的tftpd-hpa的服务目录,这个想建立在哪里都行
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="-l -c -s" # 这里是选项,-c是可以上传文件的参数,-s是指定tftpd-hpa服务目录,上面已经指定

/etc/xinetd.d/tftp

 service tftp
  {
  socket_type = dgram
  wait = yes 
  disable = no
  user = root
  protocol = udp 
  server = /usr/sbin/in.tftpd
  server_args = -s /tftpboot
  #log_on_success += PID HOST DURATION
  #log_on_failure += HOST
  per_source = 11
  cps =100 2
  flags =IPv4
  }

4.重启服务

service tftpd-hpa restart
/etc/init.d/xinetd reload
/etc/init.d/xinetd restart

5.测试

	# cd /home
  # tftp localhost  #localhost 表示本机
  tftp>get test.txt  //test.txt 是之前在 /tftpboot 目录下新建的文件
  tftp>put test1.txt //test1.txt 是在 /home 目录下新建的文件
  tftp>q

6.开发板下载文件
开发板uboot和Linux都可以使用tftp
uboot使用:tftp MemoryAddress FileName
linux使用:其是busybox中的命令,功能被阉割,其用法为:
在开发板的命令行中输入
 tftp -l a.txt -r a.txt -g 192.168.1.21 69
参数说明:-l 是local的缩写,后跟本地或下载到本地后重命名的文件名。
-r 是remote的缩写,后跟远程即PC机tftp服务器根目录中的文件名,或上传到PC机后重命名后的文件名。
-g 是get的缩写,下载文件时用,后跟PC机的IP地址
-p 是put的缩写,上传文件时用,后跟PC机的IP地址tftp 默认占用的是69端口。

注意:下载或上传文件时,文件名最好相同,否则会出现得到了文件,但文件大小却是 0k的尴尬现象。如果出现了这种现象,多敲几次命令,在 -l -r 和 -g 前面多放几个空格

4.搭建nfs服务器

1.安装
apt-get install nfs-kernel-server
apt-get install nfs-common

2.配置
/etc/exports:添加:

/root/rootfs *(rw,sync,no_root_squash,no_subtree_check)

其意义如下:
• /root/rootfs:共享的目录
• * :指定哪些用户可以访问
• * 所有可以ping同该主机的用户
• 192.168.1.* 指定网段,在该网段中的用户可以挂载
• 192.168.1.12 只有该用户能挂载
• (ro,sync,no_root_squash): 权限
• sync : 同步
• no_root_squash: 不降低root用户的权限
• 其他选项man 5 exports 查看

4.操作
1、更改文件夹的访问权限:chmod 777 -R /root/rootfs/rootfs
2、查看当前挂载:showmount -e
3、更新:exportfs -r
4、重启本地网卡:showmount localhost -e
5、挂在目录到本地:mount -t nfs -o nolock 192.168.1.141:/root/rootfs/rootfs /opt

4.重启服务
/etc/init.d/nfs-kernel-server restart

5.测试
开发板Linux环境下
1、检查客户端和服务端的网络是否连通(ping命令)
    ping + 主机IP
2、查看服务端的共享目录
    showmount -e + 主机IP
    showmount -e 192.168.1.93
    Export list for 192.168.1.93:
    /home *
3、将该目录挂载到本地
    mount -t nfs -o nolock 192.168.1.141:/root/rootfs/rootfs /opt

/root/rootfs/rootfs:目标主机(192.168.1.141)的nfs共享目录;
/opt:开发板本地的nfs共享目录;

挂载卸载命令:
mount [选项] <挂载设备名称> <挂载点>
umount <挂载设备名称或挂载点>

4、访问
    访问本地的mnt目录,就可访问服务端共享的目录了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值