08.27 Linux 網站環境搭建
Linux 網站環境搭建
伺服器:10.88.158.65
使用者名稱:tkamc 密碼:[email protected] root密碼:[email protected]
- 下載安裝anaconda3:
Anaconda3-5.2.0-Linux-x86_64.sh
2、bash Anaconda3-5.2.0-Linux-x86_64.sh
在安裝過程中全部輸入yes,加入環境變數
- 更新環境變數:
#source ~/.bashrc
- 測試
#python 是否是python3.6
安裝過程:
[[email protected] Downloads]$ mkdir /home/tkamc/Anaconda
[[email protected] Downloads]$ cp Anaconda3-5.0.1-Linux-x86_64.sh /home/tkamc/Anaconda
[
[[email protected] Anaconda]$ echo $SHELL
/bin/bash
[[email protected] Anaconda]$bash Anaconda3-5.0.1-Linux-x86_64.sh
[[email protected] Anaconda]$python -V
[[email protected] Anaconda]$vi ~/.bash_profile
[[email protected] Anaconda]$source ~/.bash_profile
[[email protected] Anaconda]$python -V
- 安裝所需python包
指定映象安裝:
pip install --proxy=http://10.88.49.1:808 django==2.0.5 -i https://pypi.doubanio.com/simple
django-celery==3.2.2
djangorestframework
markdown # Markdown support for the browsable API.
django-filter # Filtering support
celery==3.1.26.post2
mysqlclient==1.3.12 #前提裝上mysql
django-cors-headers==2.0.1
Django-auth-ldap
- 安裝python_ldap依賴包
下載rpm:
openldap-2.4.44-15.el7_5.x86_64.rpm
cyrus-sasl-devel-2.1.27-0.3rc7.fc29.x86_64.rpm
openssl-devel-1.0.2k-12.el7.x86_64.rpm
openldap-devel-2.4.44-15.el7_5.x86_64.rpm
#依次執行以上四個安裝
#rpm -ivh --force --nodeps
openssl-devel-1.0.2k-12.el7.x86_64.rpm
執行:
#pip install --proxy=http://10.88.49.1:808 python_ldap -i https://pypi.doubanio.com/simple
Oralce客戶端安裝與配置
在root使用者下
1、下載oracle客戶端安裝包/home/tkamc/package/
oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-jdbc-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-odbc-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-tools-11.2.0.4.0-1.x86_64.rpm
2、解壓預設在/usr/lib下
#cd /home/tkamc/package/
#rpm2cpio oracle*.rpm |cpio -idvm 解壓
3、移動:
mv usr /home/tkamc
4、配置環境變數:
vi /etc/profile (在root下)
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:
export ORACLE_HOME=/home/tkamc/usr/lib/oracle/11.2/client64
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORACLE_BASE=/home/tkamc/usr/lib/oracle/11.2
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH
source /etc/profile
5、建立三個檔案
cd /home/tkamc/usr/lib/oracle/11.2/client64
mkdir -p network/admin
[[email protected] admin]$ vi tnsnames.ora
#tnames.ora Network Configuration File:/usr/lib/oracle/11.2/client64/network/admin
# Generated by Oracle configuration tools.
ORCL45 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.88.17.45)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
配置TNS:
[[email protected] admin]$ vi listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /opt/oracle)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
[[email protected] admin]$ vi sqlnet.ora
#SQLNET.AUTHENTICATION_SERVICES= (NTS)
#NAMES.DIRECTORY_PATH= (TNSNAMES)
- 如果中文亂碼:
#vi /etc/profile
#export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
安裝mysql
在tkamc使用者下(最好不要在root下) root 預設指向/etc/my.cnf 配置檔案 加許可權 #chmod -R 777 mysql
1、下載解壓:
#tar -zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
- 改名
#cd /home/tkamc
#mv mysql-5.6.36-linux-glibc2.5-x86_64 mysql
3、安裝mysql
#cd mysql/scripts
初始化執行:
./mysql_install_db --user=tkamc --basedir=/home/tkamc/mysql --datadir=/home/tkamc/mysql/data
4、修改配置檔案
#cd ../support-files/
#vi mysql.server
#vi ~/.bash_profile
#. ~/.bash_profile
#echo $PATH
5、建立目錄
#mkdir /home/tkamc/mysql/data
#cd /home/tkamc/mysql/data
#vi my.cnf
[mysqld]
datadir=/home/tkamc/mysql/data
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for oracle according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#skip-grant-tables
[mysqld_safe]
log-error=/home/tkamc/mysql/log/localhost.localdomain.log
pid-file=/home/tkamc/mysql/log/localhost.localdomain.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
- 建立目錄
#mkdir /home/tkamc/mysql/log
#cd /home/tkamc/mysql/log
#touch $HOSTNAME.pid
#touch $HOSTNAME.log
7、再次修改配置檔案
#cd /home/tkamc/mysql
#vi my.cnf
[mysqld]
datadir=/home/tkamc/mysql/data
socket=/tmp/mysql.sock #此處必須這樣寫 以便後期認證登入使用
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for oracle according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#skip-grant-tables #此處用於無法校驗登入使用
[mysqld_safe]
log-error=/home/tkamc/mysql/log/oracle.log #oracle為hostname
pid-file=/home/tkamc/mysql/log/oracle.pid #oracle為hostname
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
8、修改配置檔案
#cd /home/tkamc/mysql/support-files
#vi mysql.server
修改 46、47、211行記錄
46 basedir=/home/tkamc/mysql
47 datadir=/home/tkamc/mysql/data
211 conf=/home/tkamc/mysql/data/my.cnf
- 啟動mysql
./mysql.server start
10、修改密碼
對於無法通過sockt認證可以通過如下方法修改密碼
用命令編輯配置檔案
#vim /home/tkamc/mysql/my.cnf
在[mysqld]下新增skip-grant-tables,然後儲存並退出
- 重啟mysql服務
#service mysqld restart
12、更改root使用者名稱
重啟以後,執行mysql命令進入mysql命令列
執行:
MySQL> UPDATE mysql.user SET Password=PASSWORD('新密碼') where USER='root';
MySQL>
MySQL> exit
把/etc/my.cnf中的skip-grant-tables註釋掉,然後重啟mysql
#service mysqld restart
13、登入
mysqladmin -u root password msyql
14、配置遠端訪問
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION; #允許root使用者遠端訪問
mysql>FLUSH PRIVILEGES; #重新整理許可權
mysql>exit
15、設定最大連線資料
mysql -u root –p
mysql>show variables like 'max_connections';(查可以看當前的最大連線數)
msyql>set global max_connections=1000;(設定最大連線數為1000,可以再次檢視是否設定成功)
mysql>FLUSH PRIVILEGES;
mysql> show processlist; #所有使用者的當前連線
#命令 \c exit mysql退出
- 資料庫匯入
生成sql語句。
#mysql>source /home/tkamc/abc.sql;
問題處理:
Centos下登陸mysql報錯#1045 - Access denied for user 'root'@'localhost' (using password: NO)
解決方法很簡單,
1.先關閉mysql服務: sudo /etc/init.d/mysqld stop 或者 service mysql stop
2.用管理員身份登陸mysql : mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
3.獲取root許可權: mysql -u root mysql
4.更改密碼: mysql> UPDATE user SET Password=PASSWORD('你想要的密碼') where USER='root';
5.歸還特權: mysql> FLUSH PRIVILEGES;
6.退出mysql登陸: mysql> quit
7.啟動mysql服務: sudo /etc/init.d/mysqld start 或者 service mysql start
8.可以用新密碼登陸啦: mysql -uroot -p你的密碼
Django+uwsgi+ngnix安裝
原理詳解:https://www.cnblogs.com/Xjng/p/aa4dd23918359c6414d54e4b972e9081.html
- 安裝uwsgi
Pip install --proxy=http://10.88.49.1:808 uwsgi -i https://pypi.doubanio.com/simple
2、測試啟動
uwsgi --http 10.88.158.65:8080 --file TopSpeedData/wsgi.py --static-map=/static=static
- 訪問10.88.158.65:8080 出現頁面成功!
- 建立uwsgi.py檔案
cd /home/tkamc/TopSpeedData/TopSpeedData
vi uwsgi.ini
寫入:
# uwsig使用配置檔案啟動
[uwsgi]
# 專案目錄
chdir=/home/tkamc/TopSpeedData/
# 指定專案的application
module=TopSpeedData.wsgi:application
# 指定sock的檔案路徑
socket=/home/tkamc/TopSpeedData/TopSpeedData/uwsgi.sock
# 程序個數
workers=5
pidfile=/home/tkamc/TopSpeedData/TopSpeedData/uwsgi.pid
# 指定IP埠
http=10.88.158.65:8080
# 指定靜態檔案
static-map=/static=/home/tkamc/TopSpeedData/static
# 啟動uwsgi的使用者名稱和使用者組
uid=root
gid=root
# 啟用主程序
master=true
# 自動移除unix Socket和pid檔案當服務停止的時候
vacuum=true
# 序列化接受的內容,如果可能的話
thunder-lock=true
# 啟用執行緒
enable-threads=true
# 設定自中斷時間
harakiri=30
# 設定緩衝
post-buffering=4096
# 設定日誌目錄
daemonize=/home/tkamc/TopSpeedData/TopSpeedData/uwsgi.log
- 啟動專案
uwsgi --ini uwsgi.ini
- 訪問10.88.158.65:8080 出現頁面成功!
安裝ngnix:
Ngnix安裝依賴gcc、pcre、openssl、zlib這四個包。
通過rpm -qa|grep gcc 命令檢視。
- 解壓:
#tar -zxvf /home/tkamc/package/nginx-1.12.0.tar.gz
- 配置安裝:(在root使用者下,預設安裝在/usr/local)
#cd ngnix-1.12.0
#./configure
#make
#make install
- 啟動ngnix:
#/usr/local/nginx/sbin/nginx
4、檢視程序
#ps aux | grep nginx
- 測試訪問:10.88.158.65:80
正常啟動!
- 修改配置:
#vi /usr/local/nginx/conf/nginx.conf
server { # 這個server標識我要配置了
listen 80; # 我要監聽那個埠
server_name 127.0.0.1:8080 ; # 你訪問的路徑前面的url名稱
#access_log /var/log/nginx/access.log main; # Nginx日誌配置
charset utf-8; # Nginx編碼
gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream; # 支援壓縮的型別
error_page 404 /404.html; # 錯誤頁面
error_page 500 502 503 504 /50x.html; # 錯誤頁面
# 指定專案路徑uwsgi
location / { # 這個location就和咱們Django的url(r'^admin/', admin.site.urls),
include uwsgi_params; # 匯入一個Nginx模組他是用來和uWSGI進行通訊的
uwsgi_connect_timeout 30; # 設定連線uWSGI超時時間
uwsgi_pass unix:/home/tkamc/TopSpeedData/TopSpeedData/uwsgi.sock;# 指定uwsgi的sock檔案所有動態請求就會直接丟給他
}
# 指定靜態檔案路徑
location /static/ {
alias /home/tkamc/TopSpeedData/static/;
index index.html index.htm;
}
}
- 重啟nginx:
#cd /usr/local/nginx/sbin/nginx
#./nginx restart
- 訪問10.88.158.65:8080
出現專案頁面表示成功!
常用命令:
#fuser -k 80/tcp 關閉80埠程序
#ps -ef | grep nginx 檢視程序
#rpm -qa | grep gcc 檢視是否安裝gcc
#netstat -nap | grep 8080 檢視8080埠