上一篇: [原創: 雲服務器實戰系列2] 禁用root以及經過遠程接入html
基礎軟件包含:python
雲服務器安裝的是 Centos 6.9 x86-64版本mysql
centos系統初始化時會安裝有python2.6.x版本, 此處咱們使用python3linux
注意: 若是本機安裝了python2,儘可能不要管它,使用python3運行python腳本就好,由於可能有程序依賴目前的python2環境,nginx
sudo 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 gcc
複製代碼
最新的tgz安裝包請參考官網 www.python.org/downloads/git
sudo wget http://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
複製代碼
我的習慣安裝在/usr/local/python3 建立目錄github
mkdir -p /usr/local/python3
複製代碼
解壓下載好的Python-3.x.x.tgz包web
sudo tar -zxvf Python-3.7.5.tgz
複製代碼
進入解壓後的目錄 && 編譯安裝redis
cd Python-3.7.5.tgz
sudo ./configure --prefix=/usr/local/python3
sudo make && make install
複製代碼
[account@yunServer Python-3.7.5]$ sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[account@yunServer Python-3.7.5]$ python3
Python 3.7.5 (default, Nov 5 2019, 23:53:13)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
複製代碼
vi ~/.bash_profile
複製代碼
修改倒數第二行, 將/usr/local/python3/bin加入PATHsql
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
複製代碼
按ESC,輸入:wq回車退出。
修改完記得執行行下面的命令,讓上一步的修改生效:
source ~/.bash_profile
複製代碼
檢查Python3及pip3是否正常可用:
[account@yunServer Python-3.7.5]$ python3 -V
Python 3.7.5
[account@yunServer Python-3.7.5]$ pip3 -V
pip 19.2.3 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
複製代碼
在編譯安裝以前,須要安裝nginx依賴包pcre-devel
sudo yum -y install pcre-devel
複製代碼
這裏,將會把nginx安裝到/usr/local/下, 故在此下新建目錄:
sudo mkdir /usr/local/nginx
複製代碼
在nginx官網尋找合適的nginx源碼包,經過wget下載,這裏下載的是1.15.0版本
sudo wget http://nginx.org/download/nginx-1.15.0.tar.gz
複製代碼
下載完成以後,解壓源碼包
tar -zxvf nginx-1.15.0.tar.gz
複製代碼
進入剛解壓出來的目錄
cd nginx-1.15.0
複製代碼
sudo ./configure --prefix=/usr/local/nginx
複製代碼
sudo make && make install
複製代碼
用vim打開/etc/profile文件
sudo vim /etc/profile
複製代碼
在文件的末尾添加一行代碼,冒號後邊是我nginx的安裝路徑,若是你是在其餘路徑,則將冒號後邊的路徑改成你的nginx安裝路徑
PATH=$PATH:/usr/local/nginx/sbin
複製代碼
讓profile生效
sudo source /etc/profile
複製代碼
進入nginx安裝路徑,並將nginx權限更改成775
cd /usr/local/nginx/sbin
sudo chmod -R 775 nginx
複製代碼
nginx源碼安裝完成後默認不會註冊爲系統服務,因此須要手工添加系統服務腳本。在
/etc/init.d
目錄下新建nginx
文件,並更改權限其便可。
sudo vim /etc/init.d/nginx
複製代碼
並添加如下內容
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by caffreyxin at 2007.10.15.
# it is v.0.0.1 version.
# if you find any errors on this scripts, please contact caffreyxin.
# and send mail to xinyflove at sina dot com.
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
複製代碼
也能夠參考: github.com/xinyflove/M…
注意: 根據本身實際安裝目錄,修改這兩行:
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
複製代碼
sudo chmod 755 /etc/init.d/nginx
複製代碼
sudo chkconfig nginx on
複製代碼
chkconfig --list
複製代碼
service nginx start
service nginx stop
service nginx reload
配置好以後, 啓動nginx: service nginx start
. 經過瀏覽器直接訪問公網IP, 發現沒法鏈接?
查詢資料, 原來阿里雲默認有一個安全組, 在控制端口的出入. 在阿里雲實例的控制界面中, 找到 "更多" -> "網絡和安全組" -> "安全組配置", 以下圖所示
以後進入到:
選擇"配置規則"
同時在"入方向"和"出方向"添加這個端口的安全規則便可, 這裏個人配置是:
配置好規則之, 便可在瀏覽器經過訪問公網IP或與公網IP綁定的域名了, 以下圖所示:
未完, 待續!