Light計劃我思考良久,以爲能夠着手了。第一束光便照進---服務器:
服務器對於編程者愛好者而言就像劍之於男人的浪漫
關於Linux雲服務器的入門,該走的坑帶你走一遍。
記住一點:服務器就是一臺永遠開機,沒有屏幕的本子,一個永不見天日的搬磚工。
html
怎麼肯定一個東西是你的?沒錯,是密碼。這樣你的神器就只歸你全部:前端
點擊登陸,進入服務器java
而後發出靈魂三問之首:
我是誰?
node
而後發出靈魂三問之中:
我在哪裏?
python
而後發出靈魂三問之尾:
我要去往何方?
這個問題太困難,服務器表示I don't know.
mysql
每次登陸都要用瀏覽器未免太麻煩,有不少終端的鏈接軟件,如SecureCRT
下載什麼的,一搜一大把。點擊右上角快速鏈接,主機名填你的公網ip(第一幅圖裏一片紅的地方是ip)linux
而後會讓你輸密碼,輸一下就好了。nginx
[root@VM_0_4_centos ~]# cat /etc/centos-release # 查看版本
CentOS Linux release 7.6.1810 (Core)
複製代碼
如今服務器就是一個只有一條鋼索橋的小破村,先把ftp跑通,至少能和服務器文件收發
在控制檯的安全組裏先把經常使用放入端口開放一下22,80,21,3306等。git
[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) # 表示默認就是關的
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
下,如今經過瀏覽器就能夠訪問、下載服務器文件了。github
[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
複製代碼
這裏經過FileZilla進行文件傳輸:
坑來了:503 Permission denied,
,哥但是至高無上的root權限,你有什麼資格denied我?
vsftpd默認不給root用戶暴露ftp,能夠修改一下,或者新建一個用戶。
vi /etc/vsftpd/ftpusers #修改:註釋root
vi /etc/vsftpd/user_list #修改:註釋root
/bin/systemctl restart vsftpd.service # 重啓
複製代碼
一首我很喜歡的MV奉上,也是音視頻文章的素材: ftp://175.24.44.231/projects/
這樣兩端的路就通了,文件實現互通。
看了一下,沒有Java怎麼能忍,寶劍出鞘,召喚Java。
[root@VM_0_4_centos local]# java --version
-bash: java: command not found
複製代碼
---[· yum search jdk #搜索jdk
---->[結果]-----
//略...
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)
複製代碼
下面運行SpringBoot項目,先演示一下,詳見SpringBoot系列(已放在ftp裏,可下載)
將本地寫好的項目經過ftp傳到服務器上去,使用java -jar 運行
[root@VM_0_4_centos ~]# cd ~
[root@VM_0_4_centos ~]# mkdir project
[root@VM_0_4_centos ~]# ls
project
複製代碼
服務器已打開,如今能夠訪問:http://175.24.44.231/
至此,你能夠測試服務器是否正常運做,連通無誤,這是一切的基礎
其實域名就是將你的服務器ip映射成 www.toly1994.com 而已,並無什麼大不了的
不用域名,給別人拋個ip也能訪問,只不過有了域名+備案
就名正言順,咱是好公民。
很簡單,將域名解析一下,映射到
公網ip
便可
這樣沉睡已久的 toly1994.com 開始甦醒,
爲服務器小破村修了路,又蓋了間小破房,至此,域名解析OK。
systemctl start firewalld.service # 開啓防火牆
systemctl stop firewalld.service # 關閉防火牆
systemctl status firewalld.service # 查看防火牆狀態
複製代碼
防火牆一旦開啓,再訪問
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 # 重啓防火牆
複製代碼
當你須要開放什麼端口時,本身開就好了。還有個小點:當你關閉命令行時應用就掛了
能夠用sudo nohup java -jar n_stack-0.0.1-SNAPSHOT.jar
開啓
Java/SpringBoot大軍已集結完畢,隨時準備進擊...
---[· cd /usr/local/
---[· mkdir nginx
---[· cd nginx/
複製代碼
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
# 這時候壓縮包就能夠刪掉了
複製代碼
---[· 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
複製代碼
80端口已經在用了,能夠在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
複製代碼
控制檯什麼都沒輸出,別慌,沒有錯就是成功了
注意:騰訊雲控制檯的安全組和防火牆須要開放8080端口
---[· 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 關閉
./nginx -s reload 重啓
複製代碼
記得在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服務
server {
listen 8081; #//服務端口8081,記得打開安全組和防火牆端口
chunk_size 4096; #//數據傳輸塊的大小
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
複製代碼
nginx大軍集結完畢,FFmpeg大軍已在路上,準備進擊....
下載解壓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
複製代碼
建立mysql用戶及組
cd /usr/local # local目錄
groupadd mysql # 建立mysql組
useradd -r -g mysql mysql # 在mysql組 建立mysql用戶
cd mysql/ #進入mysql文件下
chown -R mysql:mysql ./ #受權全部的文件
複製代碼
初始化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
//略...
複製代碼
配置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最大鏈接數
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導入數據速度
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
複製代碼
開啓/關閉服務
service mysql start
service mysql stop
複製代碼
添加環境變量
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
複製代碼
使用上面隨機的密碼進行登陸,而後再修改密碼。
[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大軍已集結完畢,隨時準備進擊...
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 已填充完畢,前端大軍準備進擊...
自帶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 已集結完畢,隨時準備進擊...
若是你一不當心選了個低版本,或者想要將Windows版的服務器換成Linux,只須要十秒
聲明一點,我可不是在爲騰訊雲作廣告,只是剛好在用。你用任何虛擬服務器均可以
甚至用電腦上的Linux虛擬機也能夠模擬玩玩,經過局域網間可訪問
若是有公網的ip,徹底能夠將本身的電腦搞成個高性能服務器....
如今我宣佈:
Light計劃
正式開啓--2019.12.05 。
@張風捷特烈 2019.12.05 未允禁轉
個人公衆號:編程之王
聯繫我--郵箱:1981462002@qq.com
--微信:1994328zdl
~ END ~