VMware 9 安裝CentOS 7
-> 建立新虛擬機, 選擇稍後安裝操做系統
-> 選擇Linux系統Centos 64位
-> 填寫虛擬機名稱, 選擇虛擬機安裝位置
-> 建立磁盤大小30GB, 選擇將虛擬磁盤存儲爲單個文件
-> 虛擬機設置, 點擊CD/DVD(IDE), 使用IOS映像文件, 選擇待安裝的CentOS 7.iso文件; 網卡適配器選擇NAT模式
-> VMware編輯菜單欄, 選擇虛擬網絡編輯器, 選擇VMnet8
-> 開啓虛擬機進行Linux安裝, 設置root密碼和用戶帳號密碼
-> 重啓進入虛擬機javascript
安裝VMware工具
-> 選擇虛擬機菜單欄,選擇安裝VMware工具
-> 圖形界面安裝VMware工具
-> CentOS系統中彈出的VMware tools窗口中, 右擊VMwaretools-9.6.0-1294478.tar.gz選擇解壓縮到桌面, 點擊解壓縮
-> 桌面生成一個vmware-tools-distrib的文件夾
-> 桌面上打開終端
-> 切換到root帳號, cd Desktop/vmware-tools-distrib 進入文件夾
-> 用./執行安裝./vmware-install.pl, 接下來一直回車, 直到中止
-> 用命令reboot或者shutdown -r now重啓虛擬機, 若宿主機和虛擬機能夠互相粘貼文件, 則安裝完成
-> 字符界面安裝VMware工具
-> mkdir /media/cdrom 在media下建立cdrom目錄
-> mount -t auto /dev/cdrom /media/cdrom 掛載cdrom, mount命令是掛載光驅的基本命令
-> 提示 mount: block device /dev/cdrom is write-protected, mounting read-only 掛載成功
-> cd /media/cdrom 查看光盤的文件
-> cp /media/cdrom/VMwareTools-10.0.1-3160059.tar.gz /usr/src 複製光盤文件
-> cd /usr/src 進入目錄
-> tar -zxvf VMwareTools-10.0.1-3160059.tar.gz 解壓VMware工具包, 生成vmware-tools-distrib文件夾
-> cd /usr/etc/vmware-tools-distrib 進入文件夾
-> 用./執行安裝./vmware-install.pl, 接下來一直回車, 直到中止
-> 用命令reboot或者shutdown -r now重啓虛擬機, 若宿主機和虛擬機能夠互相粘貼文件, 則安裝完成
php
設置命令行級別
設置命令行級別啓動方法:
ln -sf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target 或
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target 或
systemctl set-default multi-user.target
設置窗口級別啓動方法:
ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target 或
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target 或
systemctl set-default graphical.target
查詢Linux版本 cat /etc/redhat-release => CentOS Linux release 7.1.1503(Final)
css
配置網卡 NAT方式
-> windows網絡和共享中心, 更改適配器設置, 以太網(當前網絡)屬性, 選擇共享, 選擇容許其餘網絡用戶經過此計算機的Internet鏈接來鏈接(N), 選擇VMnet8。
-> VMnet8屬性, Internet協議版本4(TCP/IPv4)屬性, 查看IP爲192.168.137.1, 子網掩碼爲255.255.255.0
-> Centos查看網卡信息 ifconfig
-> 進入網卡配置目錄 cd /etc/sysconfig/network-scripts/
-> vim ifcfg-eno33
TYPE=Ethernet #網卡類型
BOOTPROTO=dhcp #啓用地址協議 --static:靜態協議 --bootp協議 --dhcp協議
DEVICE=ens33 #網卡接口名稱
NAME=ens33
UUID=d476cec8-b31f-4f44-a75e-ebf13251c89a
ONBOOT=yes #系統啓動時是否自動加載
IPADDR=192.168.137.128 #網卡IP地址
NETMASK=255.255.255.0 #網卡網絡地址
GATEWAY=192.168.137.1
-> service network restart 重啓網絡服務
-> ping 192.168.137.1 Centos ping通 主機 (需關閉主機防火牆)
-> ping 192.168.137.128 主機 ping通 Centos
-> shell 遠程鏈接虛擬機
安裝 Nginx1.9.9
-> 安裝基礎環境包(已安裝的可更新) -y : 自動選擇y
yum -y install openssl*
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
yum -y install libxml2 libxml2-devel zlib zlib-devel ncurses ncurses-devel curl curl-devel
yum -y install gd gd2 gd-devel gd2-devel
yum –y install gcc gcc-c++
-> 安裝pcre
使用rz命令從主機下載pcre-8.38.zip文件
unzip pcre-8.38.zip 解壓pcre-8.38.zip
cd pcre-8.38
./configure 默認安裝便可
make
make install
-> 下載 Nginx1.9.9 使用wget命令,或者使用rz命令從主機下載nginx-1.9.9.tar.gz文件,保存在/usr/src/
-> wget http://nginx.org/download/nginx-1.9.9.tar.gz
-> tar -zxvf nginx-1.9.9.tar.gz 解壓縮
-> cd nginx-1.9.9 進入目錄
-> /usr/sbin/groupadd www 創建用戶組
-> /usr/sbin/useradd -g www www 創建www用戶
-> ./configure --user=www --group=www --prefix=/usr/local/ --with-http_stub_status_module --with-http_ssl_module --with-pcre=/application/pcre 配置
-> 注: 因爲安裝pcre沒有指定目錄,所以不用指定--with-pcre。若安裝pcre有指定路徑,--with-pcre也要指定路徑
-> make 編譯
-> make install 安裝
-> 配置nginx
-> cd /usr/local/nginx/conf
-> vim nginx.conf
user www www;
worker_processes auto;
worker_rlimit_nofile 204800;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
error_log /data/logs/nginx_error/nginx_error.log crit;
pid logs/nginx.pid;
events {
use epoll; # Linux best model
worker_connections 2048000; # max thread erery process
multi_accept on;
}
http {
#close the nginx version
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
include mime.types;
default_type application/octet-stream;
charset UTF-8;
# ssi on;
# ssi_silent_errors on;
# ssi_types text/shtml;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
keepalive_timeout 65;
client_header_timeout 10;
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 10;
limit_conn_zone $binary_remote_addr zone=addr:5m;
limit_conn addr 100;
client_header_buffer_size 32k;
large_client_header_buffers 4 4k;
server_names_hash_bucket_size 128;
client_max_body_size 100M;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_disable "MSIE [1-6]\.";
gzip_proxied expired no-cache no-store private auth;
gzip_min_length 1k;
gzip_comp_level 4;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server
{
listen 80;
server_name _;
return 500;
}
include vhosts/*.conf;
}
-> mkdir vhosts
-> chmod 777 vhosts
-> /usr/local/nginx/sbin/nginx 啓動
-> /usr/local/nginx/sbin/nginx -t 測試配置文件
-> /usr/local/nginx/sbin/nginx -s reload 重啓
-> /usr/local/nginx/sbin/nginx -v 查看nginx版本
-> /usr/local/nginx/sbin/nginx -V 查看nginx版本,及配置信息
-> netstat -antlp | grep 80 nginx佔用80端口,檢查是否啓動
-> ps -ef | grep nginx 命令ps查找nginx的主進程號,檢查是否啓動(假設主進程號爲3514)
-> kill -QUIT 3514 從容中止
-> kill -TERM 3514 快速中止
-> kill -9 3514 強制中止,只關閉一個主進程號,其他進程號仍在運行
-> kill -9 3514 3515 3525 強制關閉nginx全部進程號
-> kill -HUP 3514 平滑重啓
安裝 Mysql-5.7.10
-> 注: MySQL5.5版本開始棄用了常規的configure編譯方法,經過cmake來編譯。
須要下載安裝cmake編譯器、boost庫、ncurses庫、GNU分析器生成器bison
-> 安裝基礎環境包
yum -y install gcc gcc-c++ ncurses ncurses-devel 這些上面安裝nginx已經安裝了依賴包,所以不需再次安裝。
-> yum -y install bison
-> 下面用編譯的方式安裝cmake,也能夠用yum
-> 安裝 cmake3.4.2
-> wget https://cmake.org/files/v3.4/cmake-3.4.2.tar.gz 下載cmake到/usr/src
-> tar -zxvf cmake-3.4.2.tar.gz 解壓
-> cd cmake-3.4.2 進入目錄
-> ./configure 默認配置
-> make 編譯
-> make install 安裝
-> 安裝boost1.60.0
-> wget http://sourceforge.net/projects/boost/files/boost/1.60.0/boost_1_60_0.tar.gz
-> tar -zxvf boost_1_60_0.tar.gz
-> cd boost_1_60_0
-> ./bootstrap.sh --prefix=/usr/local/boost 生成安裝工具bjam和b2
-> ./b2 編譯
-> ./b2 install 安裝(安裝目錄上面已經指定,這邊可不指定--prefix=/usr/local/boost)
-> wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz 下載mysql到/usr/src
-> tar -zxvf mysql-5.7.10.tar.gz 解壓
-> cd mysql-5.7.10 進入目錄
-> groupadd mysql 建立mysql用戶組
-> useradd -g mysql -s /sbin/nologin mysql 創建mysql用戶
-M 不要自動創建用戶的登入目錄
-g 指定用戶所屬組
-s 指定用戶登入後所使用的shell,默認值爲/bin/bash
/sbin/nologin 不容許mysql用戶直接登陸系統
-> 配置
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DENABLE_DOWNLOADS=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 -DMYSQL_MAINTAINER_MODE=0 -DWITH_SSL:STRING=bundled -DWITH_ZLIB:STRING=bundled -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
注:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql [MySQL安裝的根目錄]
-DMYSQL_DATADIR=/data/mysql/data [MySQL數據庫文件存放目錄]
-DSYSCONFDIR=/etc [MySQL配置文件所在目錄]
-DMYSQL_USER=mysql [MySQL用戶名]
-DWITH_MYISAM_STORAGE_ENGINE=1 [MySQL的數據庫引擎]
-DWITH_INNOBASE_STORAGE_ENGINE=1 [MySQL的數據庫引擎]
-DWITH_ARCHIVE_STORAGE_ENGINE=1 [MySQL的數據庫引擎]
-DWITH_MEMORY_STORAGE_ENGINE=1 [MySQL的數據庫引擎]
-DWITH_READLINE=1 [MySQL的readline library]
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock [MySQL的通信目錄]
-DMYSQL_TCP_PORT=3306 [MySQL的監聽端口]
-DENABLED_LOCAL_INFILE=1 [啓用加載本地數據]
-DENABLE_DOWNLOADS=1 [編譯時容許自主下載相關文件]
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all [使MySQL支持全部的擴展字符]
-DDEFAULT_CHARSET=utf8 [設置默認字符集爲utf8]
-DDEFAULT_COLLATION=utf8_general_ci [設置默認字符校對]
-DWITH_DEBUG=0 [禁用調試模式]
-DMYSQL_MAINTAINER_MODE=0
-DWITH_SSL:STRING=bundled [通信時支持ssl協議]
-DWITH_ZLIB:STRING=bundled [容許使用zlib library]
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/usr/local/boost
-> 注:沒有boost,則編譯時,出現錯誤
CMake Error at cmake/boost.cmake:76 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
This CMake script will look for boost in <directory>. If it is not there,
it will download and unpack it (in that directory) for you.
If you are inside a firewall, you may need to use an http proxy:
export http_proxy=http://example.com:80
Call Stack (most recent call first):
cmake/boost.cmake:228 (COULD_NOT_FIND_BOOST)
CMakeLists.txt:435 (INCLUDE)
-- Configuring incomplete, errors occurred!
See also "/byrd/tools/mysql-5.7.9/CMakeFiles/CMakeOutput.log".
解決辦法: 安裝boost庫,放到/usr/local/boost目錄下,而後在cmake後面加選項-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
-> make 編譯
-> make install 安裝
-> cd /data
-> mkdir mysql 建立數據目錄
-> mkdir logs 建立mysql日誌目錄
-> chown -R mysql:mysql mysql 修改目錄所屬組和全部者
-> cd /usr/local 進入目錄
-> chown -R mysql:mysql mysql 將/usr/local/mysql的全部者修改成mysql
-> cd /usr/local/mysql/bin 進入目錄,準備初始化
-> ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data --initialize 初始化
-> 輸出
2016-01-21T08:22:12.894937Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-01-21T08:22:15.362884Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-01-21T08:22:15.811051Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-01-21T08:22:15.897160Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 146afa03-c018-11e5-82ec-000c291b7130.
2016-01-21T08:22:15.901938Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-01-21T08:22:15.909391Z 1 [Note] A temporary password is generated for root@localhost: fQBsl)Nwa8+M
-> 記住生成的初始密碼在首次以root用戶登入時使用 -> fQBsl)Nwa8+M
-> 注:
1 ./scripts/mysql_install_db已廢棄,使用則提示:
2016-01-21 13:38:40 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-01-21 13:38:40 [ERROR] The data directory needs to be specified.
2 /data/mysql/data目錄下必須爲空,不然則提示:
2016-01-21T05:46:23.819275Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2016-01-21T05:46:23.819328Z 0 [ERROR] Aborting
3
-> 建立配置文件
-> mv /etc/my.cnf my.cnf.bak 將默認生成my.cnf更名或刪除不然啓動服務會報錯
-> cd /usr/local/mysql/support-files 進入MySQL安裝目錄支持文件目錄
-> cp my-default.cnf /etc/my.cnf 複製模板爲新的配置文件,根據須要修改配置。不修改則按默認配置參數運行。
-> 這裏對my.cnf稍做字符集和目錄修改
[client]
default-character-set=utf8
port = 3306
socket = /data/mysql/mysql.sock
[mysqld]
default-time-zone = system
character_set_server=utf8
user = mysql
port = 3306
basedir = /usr/local/mysql
socket = /data/mysql/mysql.sock
datadir = /data/mysql/data
log-error = /data/mysql/logs/mysql_error.log
pid-file = /data/mysql/mysql.pid
-> 安裝ssl
-> ./mysql_ssl_rsa_setup
-> 配置mysql自動啓動
-> cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 複製啓動腳本
-> chmod 755 /etc/init.d/mysqld 修改執行權限
-> chkconfig mysqld on 設置開機啓動(設定mysqld在二、三、四、5等級爲on)
或 chkconfig --level 345 mysqld on 設定mysqld在等級三、四、5爲開機運行服務
-> 啓動MySQL服務
/usr/local/mysql/support-files/mysql.server start 啓動mysql服務
/usr/local/mysql/support-files/mysql.server restart 重啓mysql服務
/usr/local/mysql/support-files/mysql.server stop 中止mysql服務
或者使用rpm服務命令啓動
service mysql start
service mysql restart
service mysql stop
或者使用絕對路徑
/etc/init.d/mysqld start
/etc/init.d/mysqld restart
/etc/init.d/mysqld stop
-> 查看MySQL是否運行
-> ps aux | grep mysqld
-> ps -ef | grep 3306
-> service mysql status
-> 建立mysql命令文件(建立軟連接),才能夠在任意位置使用mysql命令訪問數據庫
-> ln -s /mysql/bin/mysql /usr/bin/
-> 登錄mysql
-> mysql -u root -p
-> 注: -u 用戶名 -p 要求輸入密碼
-> 輸入剛纔生成的初始密碼 fQBsl)Nwa8+M
-> 登錄成功
-> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456'); 修改root密碼爲123456
-> quit 退出命令行
-> 遠程登陸數據庫
-> 添加mysql用戶 帳號: mysqluser 密碼: zxc123
-> insert into mysql.user(Host,User,authentication_string) values("%","mysqluser",password("zxc123"));
-> 注: 新版mysql已將user表的password改成authentication_string
配置文件my.cnf中sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
爲了安全,指定了嚴格模式,禁止經過insert這種形式直接修改mysql庫中的user表進行添加新用戶
將配置文件中的STRICT_TRANS_TABLES刪掉,即改成: sql_mode=NO_ENGINE_SUBSTITUTION
配置文件my.cnf沒有的話,添加sql_mode=NO_ENGINE_SUBSTITUTION,重啓mysql服務便可
-> 給用戶受權(若是主機名不同,則建立新用戶,能夠直接使用這個命令建立)
-> grant select,insert,update,delete,create,drop on *.* to mysqluser@"%" identified by "zxc123";
注: grant 權限 on 數據庫.* to 用戶名@登陸主機 identified by "密碼";
數據庫: *.* 表示全部庫的全部表; test.* 表示test庫的全部表;test.test_table 表示test庫的test_table表
登陸主機: '%'表示全部ip; 'localhost'表示本機; '192.168.10.2' 特定IP
建立一個mysqluser用戶,密碼爲zxc123,能夠在任何主機上登陸,並對全部數據庫有增刪改查的權限。
顯示全部的數據庫
show databases;
使用某一個數據庫
use 數據庫名;
顯示一個數據庫的全部表(必須先使用use databasename;)
show tables;
退出mysql命令行
quit;
刪除數據庫和數據表
drop database 數據庫名;
drop table 數據表名;
查看MYSQL數據庫中全部用戶
select distinct concat('User: ''',user,'''@''',host,''';') as query from mysql.user;
查看數據庫中具體某個用戶的權限
show grants for 'root'@'localhost';
select * from mysql.user where user='root' \G;
查看user表結構
desc 數據庫名.數據表名;
新建用戶,最後三個參數分別是登陸ip,用戶名,密碼
insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));
用戶受權
格式: grant 權限 on 數據庫.* to 用戶名@登陸主機 identified by "密碼";
須要執行刷新權限的命令: flush privileges;
用戶受權示例:
爲用戶授予部分權限
grant select,update on testDB.* to test@localhost identified by '1234';
flush privileges;
授予一個用戶全部數據庫的某些權限
grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";
flush privileges;
撤銷已經賦予給 MySQL 用戶權限的權限。
revoke all on *.* from test@"%";
刪除用戶
delete from user where User='test' and Host='localhost';
flush privileges;
刪除帳戶及權限:
drop user 用戶名@'%';
drop user 用戶名@localhost;
修改指定用戶密碼
mysql -u root -p 使用root登陸
update mysql.user set password=password('新密碼') where User="test" and Host="localhost";
flush privileges;
-> 防火牆開放3306端口
-> firewall-cmd --permanent --add-port=3306/tcp
-> 注: centos7 採用了firewall動態管理防火牆,廢棄iptables靜態模型的防火牆。
能夠禁用firewall,使用iptables
systemctl stop firewalld 關閉firewall防火牆
systemctl disable firewalld 開機禁用firewall防火牆
yum install iptables-services 安裝iptables
systemctl start iptables 啓用iptables
systemctl enable iptables 開機啓用iptables
firewall命令:
systemctl enable firewalld.service 設置開機啓動
systemctl start firewalld 或 systemctl start firewalld.service 開啓防火牆
firewall-cmd --state 或 systemctl status firewalld 查看centos7防火牆狀態
firewall-cmd --reload 從新加載防火牆
使用firewalld開放Linux端口:
firewall-cmd --permanent --add-port=80/tcp --zone=public 開啓80端口
firewall-cmd --permanent --add-port=1000-2000/tcp 永久開啓1000-2000端口
firewall-cmd --query-port=80/tcp 查詢1000端口開啓狀態
命令含義:
--zone 做用域
--add-port=80/tcp 添加端口,格式爲:端口/通信協議
--permanent 永久生效,沒有此參數重啓後失效
FirewallD的默認區域是public。
阻塞區域(block):任何傳入的網絡數據包都將被阻止。
工做區域(work):相信網絡上的其餘計算機,不會損害你的計算機。
家庭區域(home):相信網絡上的其餘計算機,不會損害你的計算機。
公共區域(public):不相信網絡上的任何計算機,只有選擇接受傳入的網絡鏈接。
隔離區域(DMZ):隔離區域也稱爲非軍事區域,內外網絡之間增長的一層網絡,起到緩衝做用。對於隔離區域,只有選擇接受傳入的網絡鏈接。
信任區域(trusted):全部的網絡鏈接均可以接受。
丟棄區域(drop):任何傳入的網絡鏈接都被拒絕。
內部區域(internal):信任網絡上的其餘計算機,不會損害你的計算機。只有選擇接受傳入的網絡鏈接。
外部區域(external):不相信網絡上的其餘計算機,不會損害你的計算機。只有選擇接受傳入的網絡鏈接。
-> 用mysqluser帳號遠程登陸mysql
安裝 PHP-7.0.2
-> 安裝依賴包
-> yum -y install libxml2 libxml2-devel openssl openssl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel (這些上面安裝過的就不需再次安裝)
-> yum -y install bzip2 bzip2-devel libcurl libcurl-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
-> 安裝 libmcrypt
-> wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
-> tar -zxvf libmcrypt-2.5.8.tar.gz
-> cd libmcrypt-2.5.8
-> ./configure
-> make && make install
-> wget http://cn2.php.net/get/php-7.0.2.tar.gz 下載 php-7.0.2.tar.gz
-> tar -zxvf php-7.0.2.tar.gz 解壓縮
-> cd php-7.0.2 進入目錄
-> ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-openssl-dir --with-mcrypt --with-mhash --with-pcre-regex --with-pcre-dir --with-sqlite3 --with-zlib --with-zlib-dir --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --enable-ftp --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-jpeg-dir --with-png-dir --with-freetype-dir --with-gettext --with-gmp --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --enable-mysqlnd-compression-support --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-xsl --enable-zip --with-pear --enable-opcache
注:
--prefix=/usr/local/php 指定 php 安裝目錄
--with-config-file-path=/etc 設置php.ini的搜索路徑。默認爲PREFIX/lib
--enable-fpm 打上PHP-fpm 補丁後纔有這個參數,CGI方式安裝的啓動程序
--with-fpm-user=www
--with-fpm-group=www
--enable-inline-optimization 優化線程
--disable-debug 關閉調試模式
--disable-rpath 關閉額外的運行庫文件
--enable-shared 編譯共享庫,默認yes
--enable-soap soap模塊
--with-libxml-dir 打開libxml2庫的支持
--with-xmlrpc 打開xml-rpc的c語言
--with-openssl openssl的支持,加密傳輸時用到的
--with-mcrypt mcrypt算法(函數庫須要安裝)
--with-mhash mhash算法(函數庫須要安裝)
--with-pcre-regex 定 PCRE 包含文件和庫文件路徑
--with-sqlite3
--with-zlib 打開zlib庫的支持
--enable-bcmath 打開圖片大小調整,用到zabbix監控的時候用到了這個模塊
--with-iconv
--with-bz2 打開對bz2文件的支持
--enable-calendar 打開日曆擴展功能
--with-curl 打開curl瀏覽工具的支持
--with-cdb
--enable-dom
--enable-exif 圖片的元數據支持
--enable-fileinfo
--enable-filter
--with-pcre-dir perl的正則庫安裝位置
--enable-ftp 打開ftp的支持
--with-gd 打開gd庫的支持
--with-openssl-dir
--with-jpeg-dir 打開對jpeg圖片的支持
--with-png-dir 打開對png圖片的支持
--with-zlib-dir 打開zlib庫的支持
--with-freetype-dir 打開對freetype字體庫的支持
--enable-gd-native-ttf 支持TrueType字符串函數庫
--enable-gd-jis-conv
--with-gettext 打開gnu 的gettext 支持,編碼庫用到
--with-gmp
--enable-json
--enable-mbstring 多字節,字符串的支持
--enable-mbregex
--enable-mbregex-backtrack
--with-libmbfl
--with-onig
--enable-pdo
--with-mysqli=mysqlnd mysql安裝目錄,對mysql的支持
--with-pdo-mysql=mysqlnd
--with-pdo-sqlite
--with-readline
--enable-session
--enable-shmop
--enable-simplexml
--enable-sockets 打開 sockets 支持
--enable-sysvmsg
--enable-sysvsem
--enable-sysvshm
--enable-wddx
--with-xsl 打開XSLT文件支持,擴展了libXML2庫 ,須要libxslt軟件
--enable-zip 打開對zip的支持
--enable-mysqlnd-compression-support
--with-pear 打開pear命令的支持,PHP擴展用的
--enable-opcache
-> 報錯解決
報錯1-> configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
解決1-> 編輯 /etc/ld.so.conf 加入/usr/local/lib,在執行ldconfig
-> make
-> make install
-> 配置
-> cp php.ini /usr/local/php/php.ini 複製配置文件
-> cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
-> vim /usr/local/php/etc/php-fpm.conf
pid = /var/run/php-fpm.pid 去掉前面的分號
error_log = /data/logs/php-fpm/php-fpm.log 去掉前面的分號
-> cd /usr/local/php/etc/php-fpm.d
-> cp www.conf.default www.conf 根據需求配置
-> 啓動php-fpm
-> kill -INT `cat /var/run/php-fpm.pid` 關閉php-fpm
-> kill -USR2 `cat /var/run/php-fpm.pid` 重啓php-fpm
INT, TERM 馬上終止
QUIT 平滑終止
USR1 從新打開日誌文件
USR2 平滑重載全部worker進程並從新載入配置和二進制模塊
-> ps aux | grep -c php-fp 查看php-fpm進程數
-> php 使用ci框架,在/usr/local/nginx/conf建立ci.conf重寫規則
-> vim /usr/local/nginx/conf/ci.conf
if ($request_uri ~* "^/(static|data|install|\.)/.*"){
set $rule '1';
}
if ($rule !~ '1'){
rewrite ^/(.+)$ /index.php?/$1 last;
}
-> :wq 保存退出
-> 配置域名
-> cd /usr/local/nginx/conf/vhost/
-> vim www.test.com.conf
upstream testphpfpm
{
server 127.0.0.1:9000;
}
server
{
listen 80;
server_name xxx.xxx.xxx;
index index.shtml index.html index.htm;
root /data/www/project;
ssi on;
ssi_silent_errors on;
ssi_types text/shtml;
#error_page 404 = http://xxx.xxx.xxx;
location ~ \.php$
{
alias /data/www/project;
fastcgi_pass testphpfpm;
fastcgi_index index.php;
include fastcgi.conf;
}
include ci.conf
log_format testaccess '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /data/logs/nginx/xxx.xxx.xxx.log testaccess;
}
-> :wq 保存退出
-> 分割日誌
-> 建立腳本目錄
-> cd /data
-> mkdir scripts
-> cd scripts
-> vim nginx_log_splid.sh
#!/bin/sh
LOGDIR ="/data/logs/nginx"
FILEDAY = `date -d "-1 days" +%Y%m%d`
/bin/mv $nginx_log_dir/www.test.com.log $LOGDIR /www.test.com.$FILEDAY.log
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
-> :wq
-> crontab -e 添加一條定時任務
0 0 * * * /data/scripts/nginx_log_splid.sh 每晚0點執行nginx_log_splid.sh文件
-> 主機訪問虛擬機的項目
-> 在/usr/local/nginx/conf/vhost目錄配置後,在主機的hosts裏,將域名指向虛擬機的IP便可html