查看Linux发行版本

1
# cat /etc/os-release

开启root用户ssh

先安装openssh-server

1
# yum install openssh-server

修改ssh配置文件

1
2
# vim /etc/ssh/sshd_config
:set nu #vim显示行号

修改第34行(注意去掉前面的”#”号)

1
#PermitRootLogin without-password ---> PermitRootLogin yes

修改第58行(注意去掉前面的”#”号)

1
#PasswordAuthentication yes ---> PasswordAuthentication yes

重启ssh服务

1
# sudo service ssh restart

安装好CentOS无网

1
2
3
4
5
6
7
# cd /etc/sysconfig/network-scripts

#vi ifcfg-ens34

ONBOOT=yes

# systemctl restart network

换源

1
# vim /etc/yum.repos.d/CentOS-Base.repo
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
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

git代理设置

1
2
3
# git config --global https.proxy https://127.0.0.1:1082

# git config --global http.proxy http://127.0.0.1:1082

127.0.0.1为代理服务器的地址,1082为代理端口

编译工具

安装gcc、g++

1
# yum install gcc gcc-c++

安装其他相关常用工具

1
2
3
# yum -y install gcc automake autoconf libtool make

# yum install vim

安装高版本gcc

Centos 7默认gcc版本为4.8,有时项目使用gcc版本比较高,用低版本gcc编译会出问题,这时就需要安装个高版本的gcc

1、安装centos-release-scl

1
# sudo yum install centos-release-scl

2、安装devtoolset,注意,如果想安装7.版本的,就改成devtoolset-7-gcc

1
# sudo yum install devtoolset-8-gcc*

3、如何使用

1
# source /opt/rh/devtoolset-8/enable

4、查看版本

1
# gcc -v

注意,第三步执行后会在当前窗口生效,另开窗口的话还是会执行默认的4.8版本gcc,如果不想每次source一下,可以把/usr/bin/下的gcc和g++备份一下,然后再创建个新版本的软连接,这样每次使用gcc都是用的高版本啦

1
2
3
4
5
6
# mv /usr/bin/gcc /usr/bin/gcc-4.8
# mv /usr/bin/g++ /usr/bin/g++-4.8

# ln -s /opt/rh/devtoolset-8/root/bin/gcc /usr/bin/gcc
# ln -s /opt/rh/devtoolset-8/root/bin/g++ /usr/bin/g++

挂载windows共享目录

username为本地用户名,password为密码,如果没有密码就空着

1
# mount -t cifs -o username=administrator,password= //192.168.31.10/share /mnt

如果报mount失败bad option; for several filesystems (e.g. nfs, cifs) ...,则需要安装一下cifs-utils

1
# yum install cifs-utils (网上大多数说 yum install nfs-utils 我试了并不行)

然后就可以愉快的在共享目录写代码,在linux里编译了。但是有个问题,linux文件系统一般为ext4,windows文件系统一般是NTFS,所以想在NTFS上生成linux下的软连接会报错ln: failed to create symbolic link 'libxxx.so': Operation not supported,这个问题我还没找到最好的解决办法(网上建议linux共享文件夹给windows,不太符合我的习惯),有更好方案的大佬可以给我说说

设置启动自动运行命令

编辑rc.local,rc.local位置一般在/etc/rc.local或者/etc/rc.d/rc.local,在exit 0前加上想要开机执行的命令即可,例如加上开机即挂载的命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

mount -t cifs -o username=administrator,password= //192.168.31.10/share /mnt

exit 0

如果/etc下没有rc.local,也没有rc.d这个目录,只有rc0.d、rc1.d…,可以按以下方案
1、设置rc-local.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# sudo vim /etc/systemd/system/rc-local.service

[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target

2、激活rc-local.service

1
# sudo systemctl enable rc-local.service

3、添加启动服务
手工创建/etc/rc.local
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# 下面这条是要开机启动的命令
mount -t cifs -o username=administrator,password= //192.168.31.10/share /mnt

exit 0

4、给予脚本执行权限
1
# sudo chmod 777 /etc/rc.local

清理内存占用

查看内存占用情况

1
# free -m

开始清理

1
# echo 1 > /proc/sys/vm/drop_caches

查看清理后内存占用情况

1
# free -m