【- Light 計劃 -】新建了一臺Linux云服務(wù)器我該干嘛


image
引子

Light計劃我思考良久,覺得可以著手了。第一束光便照進---服務(wù)器:
服務(wù)器對于編程者愛好者而言就像劍之于男人的浪漫
關(guān)于Linux云服務(wù)器的入門,該走的坑帶你走一遍。
記住一點:服務(wù)器就是一臺永遠開機,沒有屏幕的本子,一個永不見天日的搬磚工。

image

第一章:初入江湖

1. 滴血認主

怎么確定一個東西是你的?每次,是密碼。這樣你的神器就只歸你所有:

image
image

2.我是誰,我在哪里,我要去往何方

點擊登錄,進入服務(wù)器

image
image

然后發(fā)出靈魂三問之首:我是誰?

image

然后發(fā)出靈魂三問之中:我在哪里?

image

然后發(fā)出靈魂三問之尾:我要去往何方?
這個問題太困難,服務(wù)器表示I don't know.

image

3.劍入寶鞘,鞘配英雄

每次登錄都要用瀏覽器未免太麻煩,有很多終端的連接軟件,如SecureCRT
下載什么的,一搜一大把。點擊右上角快速連接,主機名填你的公網(wǎng)ip(第一幅圖里一片紅的地方是ip)

image

然后會讓你輸密碼,輸一下就行了。

image
[root@VM_0_4_centos ~]# cat /etc/centos-release # 查看版本
CentOS Linux release 7.6.1810 (Core) 

4.要想富,先修路

現(xiàn)在服務(wù)器就是一個只有一條鋼索橋的小破村,先把ftp跑通,至少能和服務(wù)器文件收發(fā)
在控制臺的安全組里先把常用放入端口開放一下22,80,21,3306等。

image
[root@VM_0_4_centos ~]# systemctl status firewalld.service # 查看防火墻信息
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead) # 表示默認就是關(guān)的
     Docs: man:firewalld(1)
     
[root@VM_0_4_centos ~]# rpm -qa | grep vsftpd #查看是否已安裝vsftpd
[root@VM_0_4_centos ~]# yum -y install vsftpd #安裝vsftpd
[root@VM_0_4_centos ~]# systemctl start vsftpd #開啟vsftpd

默認的ftp文件在/var/ftp下,現(xiàn)在通過瀏覽器就可以訪問、下載服務(wù)器文件了。

[root@VM_0_4_centos ~]# cd /var/ftp
[root@VM_0_4_centos ftp]# mkdir projects
[root@VM_0_4_centos ftp]# ls
projects  pub
image

這里通過FileZilla進行文件傳輸:

image

坑來了:503 Permission denied,,哥可是至高無上的root權(quán)限,你有什么資格denied我?

image

vsftpd默認不給root用戶暴露ftp,可以修改一下,或者新建一個用戶。

vi /etc/vsftpd/ftpusers #修改:注釋root
vi /etc/vsftpd/user_list #修改:注釋root
/bin/systemctl restart vsftpd.service # 重啟
image

一首我很喜歡的MV奉上,也是音視頻文章的素材: ftp://175.24.44.231/projects/
這樣兩端的路就通了,文件實現(xiàn)互通。

image

第二章:仗劍江湖(Java)

1.天下第一劍-Java

看了一下,沒有Java怎么能忍,寶劍出鞘,召喚Java。

[root@VM_0_4_centos local]# java --version
-bash: java: command not found

---[·  yum search jdk #搜索jdk
---->[結(jié)果]-----
//略...
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment
//略...

---[·  yum install java-1.8.0-openjdk.x86_64 # 安裝JDL
---[·  java -version 
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)

2.Java之劍最華麗光環(huán)--SpringBoot

下面運行SpringBoot項目,先演示一下,詳見SpringBoot系列(已放在ftp里,可下載)
將本地寫好的項目通過ftp傳到服務(wù)器上去,使用java -jar 運行

[root@VM_0_4_centos ~]# cd ~
[root@VM_0_4_centos ~]# mkdir project
[root@VM_0_4_centos ~]# ls
project
image

服務(wù)器已打開,現(xiàn)在可以訪問:http://175.24.44.231/
至此,你可以測試服務(wù)器是否正常運作,連通無誤,這是一切的基礎(chǔ)

image

3.以宇宙的名義-域名

其實域名就是將你的服務(wù)器ip映射成 www.toly1994.com 而已,并沒有什么大不了的
不用域名,給別人拋個ip也能訪問,只不過有了域名+備案 就名正言順,咱是好公民。

image

很簡單,將域名解析一下,映射到公網(wǎng)ip即可

image

這樣沉睡已久的 toly1994.com 開始蘇醒,
為服務(wù)器小破村修了路,又蓋了間小破房,至此,域名解析OK。


4. 你的生命有我來守護 - 防火墻
systemctl start firewalld.service # 開啟防火墻
systemctl stop firewalld.service # 關(guān)閉防火墻
systemctl status firewalld.service # 查看防火墻狀態(tài)

防火墻一旦開啟,再訪問toly1994.com就會找不到80端口,需要開放防火墻端口

[root@VM_0_4_centos ~]# /sbin/iptables -L -n # 查看防火墻開放的端口
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
firewall-cmd --permanent --add-port=80/tcp # 開放80端口
firewall-cmd --reload # 重啟防火墻

當(dāng)你需要開放什么端口時,自己開就行了。還有個小點:當(dāng)你關(guān)閉命令行時應(yīng)用就掛了
可以用sudo nohup java -jar n_stack-0.0.1-SNAPSHOT.jar開啟
Java/SpringBoot大軍已集結(jié)完畢,隨時準備進擊...


第三章:多媒體風(fēng)云-nginx/流媒體服務(wù)器

1.創(chuàng)建文件夾
---[·  cd /usr/local/
---[·  mkdir nginx
---[·  cd nginx/

2.下載解壓nginx和nginx-rtmp-module
wget https://nginx.org/download/nginx-1.16.1.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/v1.2.1.tar.gz

---[·  tar -xvf nginx-1.16.1.tar.gz
---[·  tar -xvf v1.2.1.tar.gz
---[·  ls
nginx-1.16.1  nginx-1.16.1.tar.gz  nginx-rtmp-module-1.2.1  v1.2.1.tar.gz
# 這時候壓縮包就可以刪掉了

3.編譯nginx
---[·  cd nginx-1.16.1

# 添加編譯配置--注意模塊名
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-1.2.1

make && make install #編譯安裝

---[·  cd ..
---[·  ls
conf  html  logs  nginx-1.16.1  nginx-rtmp-module-1.2.1  sbin

4.[配置的修改處]

80端口已經(jīng)在用了,可以在conf/nginx.conf里修改端口為8080

---[·  cd conf
---[·  ls
fastcgi.conf          fastcgi_params          koi-utf  mime.types          nginx.conf          scgi_params          uwsgi_params          win-utf
fastcgi.conf.default  fastcgi_params.default  koi-win  mime.types.default  nginx.conf.default  scgi_params.default  uwsgi_params.default

---[·  vim nginx.conf
image

5. 啟動nginx

控制臺什么都沒輸出,別慌,沒有錯就是成功了
注意:騰訊云控制臺的安全組和防火墻需要開放8080端口

image
---[·   cd /usr/local/nginx/sbin 
---[·   ./nginx

---[·   ps -ef | grep nginx # 查看情況
root     10043     1  0 10:32 ?        00:00:00 nginx: master process ./nginx
nobody   10044 10043  0 10:32 ?        00:00:00 nginx: worker process
root     14035 30742  0 11:03 pts/2    00:00:00 grep --color=auto nginx
cd /usr/local/nginx/sbin
./nginx -s stop 關(guān)閉
./nginx -s reload 重啟

6.媒體流一下下

記得在ftp里有一個視頻

---[·   cd /var/ftp/projects 
---[·   ls
n_stack-0.0.1-SNAPSHOT.jar  sh.mp4
---[·   vim /usr/local/nginx/conf/nginx.conf
####################修改添加與http、event同級####################
rtmp {                #RTMP服務(wù)
   server {
       listen 8081;  #//服務(wù)端口8081,記得打開安全組和防火墻端口
   chunk_size 4096;   #//數(shù)據(jù)傳輸塊的大小


   application toly {
       play /var/ftp/projects; #//視頻文件夾
   }
   }
}
####################修改####################

---[·  cd /usr/local/nginx/sbin
---[·  sudo ./nginx -s reload #重啟

下面是本地通過ffplay拉流播放的效果,表示OK。
這樣在projects下方的任何視頻都可以被點播,至于FFmpeg直播,祈禱本王活得久一點吧.....

ffplay rtmp://toly1994.com:8081/toly/sh.mp4 
image

nginx大軍集結(jié)完畢,F(xiàn)Fmpeg大軍已在路上,準備進擊....


第四章:天下第二劍-MySQL

1.前期準備

下載解壓mysql

rpm -qa|grep -i mysql # 查看是否有mysql
# 如果有 rpm -e XXXXX --nodeps 刪除

cd /usr/local   #選一個下載文件的地方
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz # 下載mysql

tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz # 解壓mysql
[root@VM_0_4_centos mysql]# mv mysql-8.0.18-linux-glibc2.12-x86_64 mysql #重命名為mysql
[root@VM_0_4_centos mysql]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  qcloud  sbin  share  src  yd.socket.server

創(chuàng)建mysql用戶及組

cd /usr/local # local目錄
groupadd mysql # 創(chuàng)建mysql組
useradd -r -g mysql mysql # 在mysql組 創(chuàng)建mysql用戶
cd mysql/ #進入mysql文件下
chown -R mysql:mysql ./ #授權(quán)所有的文件

初始化mysql

---[·  pwd
/usr/local/mysql

---[·  mkdir data
---[· bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
?  bin/mysqld: error while loading shared libraries: libnuma.so.1: 

---[· yum -y install numactl
---[· bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

[root@VM_0_4_centos mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-12-05T09:11:42.077017Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-12-05T09:11:42.077121Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 31048
2019-12-05T09:11:47.785216Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 47<:0(pYQs>C

?? 會生成默認的密碼:root@localhost: 47<:0(pYQs>C


[只將data文件暴露給mysql用戶]

[root@VM_0_4_centos mysql]# chown -R root:root ./
[root@VM_0_4_centos mysql]# chown -R mysql:mysql data
[root@VM_0_4_centos mysql]# ll
total 552
drwxr-xr-x  2 root  root    4096 Sep 20 20:57 bin
drwxr-xr-x  6 mysql mysql   4096 Dec  5 17:11 data
drwxr-xr-x  2 root  root    4096 Sep 20 20:57 docs
drwxr-xr-x  3 root  root    4096 Sep 20 20:57 include
drwxr-xr-x  7 root  root    4096 Sep 20 20:57 lib
-rw-r--r--  1 root  root  408918 Sep 20 16:30 LICENSE
//略...

2.mysql配置文件相關(guān)

配置mysql

[root@VM_0_4_centos mysql]# cd support-files/
[root@VM_0_4_centos support-files]# ls
mysqld_multi.server  mysql-log-rotate  mysql.server

[root@VM_0_4_centos support-files]# touch my-default.cnf
[root@VM_0_4_centos support-files]# chmod 777 ./my-default.cnf
[root@VM_0_4_centos support-files]# cd ../
[root@VM_0_4_centos mysql]# cp support-files/my-default.cnf /etc/my.cnf

按需修改配置文件vim /etc/my.cnf

[client]
port=3306
#.sock文件路徑
socket = /tmp/mysql/mysql.sock
default-character-set=utf8

[mysqld]
#mysql最大連接數(shù)
max_connections=2000
 
datadir=/wocloud/mysql/data
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql/mysql.sock
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
 
#密碼有效期,0表示永久有效
default_password_lifetime=0
 
#提高source導(dǎo)入數(shù)據(jù)速度
innodb_flush_log_at_trx_commit=0
max_allowed_packet=100M

user=mysql
#臨時文件存放路徑
tmpdir=/tmp/mysql
 
#默認配置
symbolic-links=0
character-set-server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
 
[mysql]
no-auto-rehash
default-character-set=utf8
 
[mysqld_safe]
default-character-set = utf8
 
[mysql.server]
default-character-set = utf8

開機自起

[root@VM_0_4_centos mysql]# cd support-files/
[root@VM_0_4_centos support-files]# cp mysql.server /etc/init.d/mysql 
[root@VM_0_4_centos support-files]# chmod +x /etc/init.d/mysql
[root@VM_0_4_centos support-files]# chkconfig mysql on 

開啟/關(guān)閉服務(wù)

service mysql start 
service mysql stop

添加環(huán)境變量
vim ~/.bash_profile:

#MYSQL ENVIRONMENT
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib

source ~/.bash_profile,通過$PATH命令可以查看是否按照成功。


[番外]-也許你比較好奇為嘛在etc里寫my.cnf配置
可以查看一下mysql默認可生效的my.cnf位置:

[root@VM_0_4_centos mysql]# mysql --verbose --help | grep my.cnf
                      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 

3. 登錄mysql和修改密碼

使用上面隨機的密碼進行登錄,然后再修改密碼。

[root@VM_0_4_centos mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'ooxxooxxooxx';# 修改密碼

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

Grant all privileges on *.* to 'root'@'%' identified by 'toly1994' with grant option;

GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'toly1994' WITH GRANT OPTION;

GRANT ALL ON *.* TO 'root'@'%';

MySQL大軍已集結(jié)完畢,隨時準備進擊...


第五章:斬魔雙劍-NodeJS + Python

1.node 環(huán)境
cd /usr/local
wget https://npm.taobao.org/mirrors/node/v12.13.1/node-v12.13.1-linux-x64.tar.xz
tar -xvf node-v12.13.1-linux-x64.tar.xz
mv node-v12.13.1-linux-x64 nodejs

ln -s /usr/local/nodejs/bin/node /usr/sbin/node
ln -s /usr/local/nodejs/bin/npm /usr/sbin/npm

---[·  node -v
v12.13.1

---[·  npm -v
6.12.1

node 已填充完畢,前端大軍準備進擊...


2.Python環(huán)境

自帶Python 2.7.5,再裝個python3吧,
編譯pip3時需要一些東西,先裝一下,否則編譯無法生成pip3:

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
---[·  python -V
Python 2.7.5

---[·  cd /usr/local/
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tar.xz
tar -xvf Python-3.7.5.tar.xz #解壓
cd Python-3.7.5
./configure --prefix=/usr/local/python3 # 配置
make && make install   # 編譯安裝

查看是否生成python3和pip3

---[·  cd /usr/local/python3/bin
---[·  ls
2to3  2to3-3.7  easy_install-3.7  idle3  idle3.7  pip3  pip3.7  pydoc3  pydoc3.7  python3  python3.7  python3.7-config  python3.7m  python3.7m-config  python3-config  pyvenv  pyvenv-3.7

建立軟連接

ln -s /usr/local/python3/bin/python3 /usr/sbin/python3
ln -s /usr/local/python3/bin/pip3 /usr/sbin/pip3

---[·  python3 -V
Python 3.8.0

---[·  pip3 -V
pip 19.2.3 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)

python 已集結(jié)完畢,隨時準備進擊...


附錄:操作系統(tǒng)

如果你一不小心選了個低版本,或者想要將Windows版的服務(wù)器換成Linux,只需要十秒

image
image
image

尾聲

聲明一點,我可不是在為騰訊云做廣告,只是恰好在用。你用任何虛擬服務(wù)器都可以
甚至用電腦上的Linux虛擬機也可以模擬玩玩,通過局域網(wǎng)間可訪問
如果有公網(wǎng)的ip,完全可以將自己的電腦搞成個高性能服務(wù)器....

現(xiàn)在我宣布:Light計劃 正式開啟--2019.12.05 。

@張風(fēng)捷特烈 2019.12.05 未允禁轉(zhuǎn)
我的公眾號:編程之王
聯(lián)系我--郵箱:1981462002@qq.com --微信:1994328zdl
~ END ~

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容