CentOS-7 安装和使用

centos下载安装

CentOS-7 去 官网 下载

安装ifconfig

系统默认 没有安装 ifconfig 命令。

运行 yum install ifconfig 提示No package ifconfig available
通过运行 yum search ifconfig 提示我们: 安装ifconfig 包 只需要安装 net-tools.x86_64 即可
执行 yum install net-tools.x86_64

安装vim

yum install vim
配置,编辑vim配置文件
vim /etc/vimrc
末尾添加以下几行,设置缩进长度、退格缩回长度,一行最大字符数、显示行号、自动缩进
set shiftwidth=4 
set softtabstop=4 
set textwidth=200 
set nu 
set autoindent

安装OpenSSH服

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
1.安装OpenSSH服务(CentOS系统默认安装了openssh)
yum install openssh-server -y
2.配置OpenSSH服务(默认的配置已可以正常工作)

OpenSSH的主配置文件:/etc/ssh/sshd_config

常见的配置选项:

Port=22 设置SSH的端口号是22(默认端口号为22)
Protocol 2 启用SSH版本2协议
ListenAddress 192.168.0.222 设置服务监听的地址
DenyUsers user1 user2 foo 拒绝访问的用户(用空格隔开)
AllowUsers root osmond vivek 允许访问的用户(用空格隔开)
PermitRootLogin no 禁止root用户登陆
PermitEmptyPasswords no 用户登陆需要密码认证
PasswordAuthentication yes 启用口令认证方式12345678910111213141516

3.开机自启
chkconfig sshd on

4.重启OpenSSH服务
service sshd restart
5.客户端通过ssh远程连接服务器

ssh username@hostname(hostIP) 1
如:ssh user1@192.168.10.10

配置国内yum源

1
2
3
4
5
6
7
8
9
10
11
1、备份(针对所有CentOS可用,备份文件在当前路径下)
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/
下载阿里云源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者网易云源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
3、之后运行yum makecache生成缓存
yum makecache
4、更新
yum -y update

修改root密码

[root@localhost ~]# passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

增加用户(docker)并添加权限

adduser docker
passwd docker

通过ssh服务使用终端访问

安装openssh server
yum install ssh
启动ssh服务
service sshd start
设置开机运行: 
chkconfig sshd on

C++环境配置

安装c++开发环境
yum install gcc gcc-c++ make gdb automake autoconf ncurses-devel
yum install libtool rpm-build redhat-rpm-config yum-utils -y

升级安装gcc 8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
第一步:安装scl源:
yum install centos-release-scl scl-utils-build

第二步: 列出scl可用源
yum list all --enablerepo='centos-sclo-rh'
yum list all --enablerepo='centos-sclo-rh' | grep "devtoolset-"

 
第三步: 安装8版本的gcc、gcc-c++、gdb工具链(toolchian):
yum install -y devtoolset-8-toolchain

第四步: 开启gcc8
scl enable devtoolset-8 bash

最后:查看结果

gcc --version

安装cgdb

1
2
3
4
5
6
7
8
yum install readline-devel
yum install readline
yum install flex autoconf automake texinfo help2man
curl -R -O http://cgdb.me/files/cgdb-0.7.1.tar.gz
tar zxvf cgdb-0.7.1.tar.gz
cd cgdb-0.7.1
./configure --prefix=/usr/local
make && make install

安装cmake

1
2
3
4
5
6
7
8
wget https://cmake.org/files/v3.16/cmake-3.16.0.tar.gz
tar -xzvf cmake-3.16.0.tar.gz
cd cmake-3.16.0
./configure
./bootstrap
gmake
make && make install
cmake --version

安装protobuf

1
2
3
4
5
6
7
8
9
10
11
12
13
yum install autoconf libtool automake curl
命令安装
yum install protobuf-compiler
编译安装
wget https://protobuf.googlecode.com/files/protobuf-2.5.0.tar.gz
tar zxf protobuf-2.5.0.tar.gz
cd protobuf-2.5.0
./configure --prefix=/opt/local/protobuf-2.5.0
make
make install
ln -s /opt/local/protobuf-2.5.0/bin/protoc /usr/bin/protoc

protoc -I=. --cpp_out=. msg.proto

安装libevent

1
sudo apt-get install libevent-dev

编译安装 OpenSSL

1
2
3
4
5
6
7
8
9
prefix 是安装目录,openssldir 是配置文件目录,另外建议安装两次,shared 作用是生成动态连接库。
wget ftp://ftp.openssl.org/source/openssl-1.0.2g.tar.gz
tar -zxf openssl-1.0.2g.tar.gz
cd openssl-1.0.2g/
./config --prefix=/usr/local --openssldir=/usr/local/ssl
make && make install
./config shared --prefix=/usr/local --openssldir=/usr/local/ssl
make clean
make && make install

安装lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
lua安装依赖breadline环境
yum install readline-devel
安装lua详见[LUA官网](http://www.lua.org/download.html)
curl -R -O http://www.lua.org/ftp/lua-5.3.5.tar.gz
tar zxf lua-5.3.5.tar.gz
cd lua-5.3.5
make linux && make install

删除cent7默认lua5.1,并进行链接
cd /usr/bin
rm -rf lua luac
ln -s /usr/local/bin/lua /usr/bin/lua
ln -s /usr/local/bin/luac /usr/bin/luac
lua -v

升级python

centos7默认安装了python2.7.5,我们将它升级到2.7最后一个版本2.7.16

1
2
3
4
5
6
7
8
9
10
11
12
13
14
wget http://python.org/ftp/python/2.7.16/Python-2.7.16.tgz 
tar -zxvf Python-2.7.16.tgz
cd Python-2.7.16
#./configure
#make all
#make install
#make clean
#make distclean
#usr/local/bin/python2.7 -V
#mv /usr/bin/python /usr/bin/python2.6.6
#ln -s /usr/local/bin/python2.7 /usr/bin/python
#python -V
#vi /usr/bin/yum
将文件头部的#!/usr/bin/python改成#!/usr/bin/python2.6.6

安装golang

yum install golang vim-golang

修改gopath

1
2
3
4
5
6
7
8
9
10
11
创建 gowork 目录
mkdir /root/code/gowork -p

vim /etc/profile 添加
export GOPATH=/root/code/gowork
export PATH=$PATH:$GOPATH/bin

保存后执行source使其生效:
source /etc/profile

之后执行`go env`来检查环境变量是否配置成功

安装git

可以直接使用命令yum install git进行安装,不过git版本比较低,这里使用源码进行安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
安装需求
# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
# yum install gcc perl-ExtUtils-MakeMaker
# yum remove git

下载git2.22.0并将git添加到环境变量中

# cd /usr/src
# wget https://www.kernel.org/pub/software/scm/git/git-2.22.0.tar.gz
# tar xzf git-2.22.0.tar.gz

安装git并添加到环境变量中

# cd git-2.22.0
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install
# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
# source /etc/bashrc

查看版本号

# git --version
git version 2.22.0

通过源安装
当然, 最后的最后, 如果你已经安装过旧版的 git, 需要先卸载才行
yum remove git

添加 IUS 源
yum install -y https://centos7.iuscommunity.org/ius-release.rpm

IUS 源的软件名称一般会加上版本号和 u 字母

查看 git2u 版本
yum info git2u # 会发现比较新, 但不是最最新, 不过会比 yum 默认源要新很多

安装 git2u
yum install -y git2u

安装完成后, 再查看下版本咯
[root@icentos ~]# git version
git version 2.16.5

安装svn

yum install subversion subversion-tools

window与centos共享访问

window通过samba共享centos目录

centos挂载window共享目录

centos配置ftp服务器

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
安装ftp
yum install vsftpd -y
service vsftpd start
chkconfig
chkconfig vsftpd on
建一个测试文件夹
mkdir /var/ftp/test
试一下 ftp://ip,一个只能下载的FTP站就好了。
增加ftp用户密码12345678
useradd ftpuser -s /sbin/nologin
passwd ftpuser
ftp123
修改ftp配置文件
cp /etc
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf_back
vim /etc/vsftpd/vsftpd.conf
开启一下项
write_enable=YES
ascii_upload_enable=YES
ascii_download_enable=YES
ftpd_banner=Welcome to blah FTP service
chroot_local_user=YES
重启ftp服务
service vsftpd restart
在window上输入ftp://ip访问,输入用户名及密码 ftpuser/12345678即可看到/home/ftpuser/目录

mysql环境搭建

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
首先必须添加mysql社区repo通过输入命令
sudo rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
安装mysql
yum install -y mysql-server mysql mysql-devel libmysqlclient-dev
启动服务
service mysqld start
设置root密码
/usr/bin/mysqladmin -u root password '12345678'
设置mysql开机启动
chkconfig mysqld on
配置mysql允许远程访问
mysql -u root -p
执行以下命令开启远程访问限制
grant all privileges on *.* to 'root'@'%' identified by '12345678' with grant option;
flush privileges;
exit;
重启mysql
service mysqld restart

xshell通过ssh与服务器传输文件

使用yum install lrzsz命令进行安装,rz命令上传 sz命令下载

安装iptables防火墙

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
安装
yum install iptables-services
设置开机自启动
systemctl enable iptables.service

service iptables start #启动服务
service iptables stop   #停止服务
service iptables restart  #重启服务

关闭SELINUX
vim /etc/selinux/config
 #注释以下配置
 SELINUX=enforcing
 SELINUXTYPE=targeted
 
 #增加以下配置
 SELINUX=disabled
 
 #使配置立即生效
 setenforce 0

安装nginx

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
	1、安装prce(重定向支持)和openssl(https支持,如果不需要https可以不安装。)
yum -y install pcre*
yum -y install openssl*
2、下载nginx 1.9.9
wget http://nginx.org/download/nginx-1.9.9.tar.gz
3、解压编译安装
tar -zxvf nginx-1.9.9.tar.gz
cd nginx-1.9.9
./configure
make && make install
编译完成后会发生成了/usr/local/nginx/目录
4.启动nginx
/usr/local/nginx/sbin/nginx
重启
/usr/local/nginx/sbin/nginx -s reopen
关闭
/usr/local/nginx/sbin/nginx -s stop
重新加载配置
/usr/local/nginx/sbin/nginx -s reload
5.验证nginx是否启动成功
  执行curl http://localhost 出现下面信息表示启动成功
6.检查
ps -ef |grep nginx
netstat -antup |grep 80
7、开放80端口
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/rc.d/init.d/iptables save
service iptables restart
9.配置web
主配置文件/usr/local/nginx/conf/nginx.conf
修改默认web路径(http://www.5yun.org/6634.html)
vim /usr/local/nginx/conf/nginx.conf
修改localtion / root 为 /var/www
重启nginx
/usr/local/nginx/sbin/nginx -s reopen
在/var/www下放至web服务器


./configure --prefix=/usr/local/nginx-1.9.9 \
--with-http_ssl_module --with-http_spdy_module \
--with-http_stub_status_module --with-pcre
如果没有error信息,就可以执行下边的安装了:
make
make install
4、开启nginx进程

/usr/local/nginx-1.8.0/sbin/nginx
重启或关闭进程:
/usr/local/nginx-1.8.0/sbin/nginx -s reload
/usr/local/nginx-1.8.0/sbin/nginx -s stop
5、关闭防火墙,或者添加防火墙规则就可以测试了。
service iptables stop
或者编辑配置文件:
vi /etc/sysconfig/iptables
添加这样一条开放80端口的规则后保存:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重启服务即可:
service iptables restart
ok,,可以浏览器访问了。
Welcome to nginx!

redis安装

** yum安装redis**

参考教程 CentOS 7 yum 安装redis(更简单)

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
下载fedora的epel仓库
yum install epel-release
安装redis
yum install redis

使用下面的命令操作redis
# 启动redis
service redis start
# 停止redis
service redis stop
# 查看redis运行状态
service redis status
# 查看redis进程
ps -ef | grep redis

开机自启动
chkconfig redis on

进入redis服务
# 进入本机redis
redis-cli
# 列出所有key
keys *

防火墙开放相应端口
# 开启6379
/sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
# 开启6380
/sbin/iptables -I INPUT -p tcp --dport 6380 -j ACCEPT
# 保存
/etc/rc.d/init.d/iptables save
# centos 7下执行
service iptables save

编译安装Redis

centos6安装redis-2.8.19.tar.gz

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
然后再按照下面的方式执行
Installation
Download, extract and compile Redis with:
$ wget http://download.redis.io/releases/redis-3.2.6.tar.gz
$ tar xzf redis-3.2.6.tar.gz
$ cd redis-3.2.6
$ make && make install
$ cd deps/hiredis
$ make && make install

The binaries that are now compiled are available in the src directory. Run Redis with:
$ src/redis-server
You can interact with Redis using the built-in client:
$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

修改 /etc/ld.so.conf 文件,增加 /usr/local/lib
执行 /sbin/ldconfig

1、linux下如何安装hiredis
1)下载地址
https://github.com/redis/hiredis
2)编译和安装
解压后的文件夹执行 make;make install;

启动服务器
redis-server
启动客户端
redis-cli
配置redis 后台
centos安装redis+三种启动方式(http://blog.csdn.net/zc474235918/article/details/50974483)

安装tinyxml

# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/tinyxml-devel-2.6.1-1.el6.x86_64.rpm
# rpm -ivh tinyxml-devel-2.6.1-1.el6.x86_64.rpm

编译静态库
wget https://nchc.dl.sourceforge.net/project/tinyxml/tinyxml/2.6.2/tinyxml_2_6_2.zip
unzip tinyxml_2_6_2.zip -d tinyxml 
修改Makefile
[plain] view plain copy
#OUTPUT := xmltest  
OUTPUT := libtinyxml.a  

${OUTPUT}: ${OBJS}  
#       ${LD} -o $@ ${LDFLAGS} ${OBJS} ${LIBS} ${EXTRA_LIBS}  
        ${AR} $@ ${LDFLAGS} ${OBJS} ${LIBS} ${EXTRA_LIBS}  

#xmltest.o: tinyxml.h tinystr.h  
编译安装
make && install

手把手教你搭建自己的shadowsocks

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Shadowsocks-go一键安装脚本
本脚本适用环境:
系统支持:CentOS,Debian,Ubuntu
内存要求:≥64M
日期:2018 年 03 月 15 日

关于本脚本:
一键安装 Go 版的 shadowsocks 最新版本 1.2.1。与 Python 版不同的是,其客户端程序能使用多个服务端配置,本脚本安装的是服务端程序。
友情提示:如果你有问题,请先参考这篇《Shadowsocks Troubleshooting》后再问。


默认配置:
服务器端口:自己设定(如不设定,默认从 9000-19999 之间随机生成)
密码:自己设定(如不设定,默认为 teddysun.com)
加密方式:自己设定(如不设定,默认为 aes-256-cfb)

Shadowsocks for Windows 客户端下载:
https://github.com/shadowsocks/shadowsocks-windows/releases


使用方法:
使用root用户登录,运行以下命令:
wget --no-check-certificate -O shadowsocks-go.sh https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-go.sh
chmod +x shadowsocks-go.sh
./shadowsocks-go.sh 2>&1 | tee shadowsocks-go.log
安装完成后,脚本提示如下:

Congratulations, Shadowsocks-go server install completed!
Your Server IP :your_server_ip
Your Server Port :your_server_port
Your Password :your_password
Your Encryption Method:your_encryption_method

Welcome to visit:https://teddysun.com/392.html
Enjoy it!
卸载方法:
使用 root 用户登录,运行以下命令:

./shadowsocks-go.sh uninstall
其他事项:
客户端配置的参考链接:https://teddysun.com/339.html

安装完成后即已后台启动 Shadowsocks-go ,运行:

/etc/init.d/shadowsocks status
可以查看 Shadowsocks-go 进程是否已经启动。
本脚本安装完成后,已将 shadowsocks-go 加入开机自启动。

使用命令:
启动:/etc/init.d/shadowsocks start
停止:/etc/init.d/shadowsocks stop
重启:/etc/init.d/shadowsocks restart
状态:/etc/init.d/shadowsocks status

多用户多端口配置文件示例:
配置文件路径:/etc/shadowsocks/config.json
{
"port_password":{
"8989":"password0",
"9001":"password1",
"9002":"password2",
"9003":"password3",
"9004":"password4"
},
"method":"your_encryption_method",
"timeout":600
}
官方版本的示例 ,详见这里。

设定固定IP

虚拟机网络适配模式设为:桥接模式+复制物理网络连接状态
$sudo cp /etc/network/interfaces /etc/network/interfaces_back
$sudo vim /etc/network/interfaces
配置内容为
auto lo
iface lo inet loopback           

auto eth0 
iface eth0 inet static 
address 192.168.0.111
netmask 255.255.255.0 
gateway 192.168.0.1

重启网络使之生效
$sudo /etc/init.d/networking restart

这时候就能ping到局域网中的电脑了。但是上不了Internet,是因为没有设置DNS的原因。DNS信息保存在/etc/resolv.conf中,一旦更改,立即生效。
$sudo vim /etc/resolvconf/resolv.conf.d/head
配置内容为
nameserver 192.168.2.43
nameserver 192.168.2.6
或者直接在/etc/network/interfaces 添加
dns-nameservers 192.168.2.43
dns-nameservers 192.168.2.6
重启生效
$sudo reboot -h now

查看ip信息
ifconfig
查看路由相关信息:
route -n
命令设定ip
ifconfig eth1 192.168.1.10 netmask 255.255.255.0 

相关问题

相关

ssh工具

  • xshell

centos7升级内核

教程:https://www.jianshu.com/p/fdf6bb6c5b9c

gcc升级

1
wget https://ftp.gnu.org/gnu/gcc/gcc-8.3.0/gcc-8.3.0.tar.gz

相关问题

vim相关教程

文件换行符问题

如test.sh提示换行符问题
vim test.sh
命令模式下输入以下内容,表示使用unix换行符,set ff=dos表示使用dos换行符
set ff=unix
wq

在Linux中查看所有正在运行的进程

[在Linux中查看所有正在运行的进程](http://blog.csdn.net/cnmilan/article/details/34104713)

端口占用

sudo netstat -tulnp | grep ':80'
kill -9 PID

压缩解压缩

解压 tar zxvf 文件名.tar.gz
压缩 tar zcvf 文件名.tar.gz 目标名

其它

在自己vps ubuntu上安装v2ray

输入下面命令进行一键安装

1
bash <(curl -L -s https://install.direct/go.sh)

安装完成后我们来编辑一下配置文件

1
vim /etc/v2ray/config.json

记下来inbounds里面的
port 28072
id 1656d469-bc80-48d4-a0e3-01243cf7d046
alterId 64

若需要配置Shadowscoks,请于inbounds同级增加以下配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"inboundDetour": [
{
"protocol": "shadowsocks",
"port": 30001,
"settings": {
"method": "aes-256-cfb",
"password": "v2ray",
"udp": false
}
}
],
"log": {
"loglevel": "warning",
"access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log"
},

之后可以使用 service v2ray start|stop|status|reload|restart|force-reload 控制 V2Ray 的运行