服務(wù)器配置太低,裝了gitlab后掛了宿稀,重新配置一下趁舀。
一、掛載數(shù)據(jù)盤
df -h
只有系統(tǒng)盤了祝沸,掛載上原來的數(shù)據(jù)盤
fdisk -l
看到數(shù)據(jù)盤了/dev/vdb1
掛載上這個數(shù)據(jù)盤矮烹,
mkdir /data
mount /dev/vdb1 /data
然后寫入分區(qū):
echo '/dev/vdb1 /data ext4 defaults 0 0' >> /etc/fstab
不寫入分區(qū)表越庇,重啟后又要掛載的。
怎么知道分區(qū)類型是ext4奉狈,用這個命令:
df -hT
好的成功了卤唉!
二、安裝nginx
首先更新系統(tǒng)軟件
# yum update
安裝nginx
1.安裝nginx源
# yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.安裝nginx
# yum install nginx
3.啟動nginx
# service nginx start
Redirecting to /bin/systemctl start nginx.service
4.訪問http://你的ip/
如果成功安裝會出來nginx默認(rèn)的歡迎界面
三嘹吨、安裝MySQL5.7.*
1.安裝mysql源
# yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
2.安裝mysql
# yum install mysql-community-server
3.安裝mysql的開發(fā)包搬味,以后會有用
# yum install mysql-community-devel
4.啟動mysql
# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
5.查看mysql啟動狀態(tài)
# service mysqld status
出現(xiàn)pid
證明啟動成功
6.獲取mysql默認(rèn)生成的密碼
# grep 'temporary password' /var/log/mysqld.log
選中的就是密碼。
7.換成自己的密碼
# mysql -uroot -p
Enter password:輸入上頁的密碼蟀拷,進(jìn)入mysql
8. 更換密碼
1
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPasdfs4!';
這個密碼一定要足夠復(fù)雜碰纬,不然會不讓你改,提示密碼不合法;
9.退出mysql并試用下新密碼
mysql> quit;mysql -uroot -p
確認(rèn)密碼正確
四问芬、編譯安裝php7.0.0
1.下載php7源碼包
# cd /root & wget -O php7.tar.gz http://cn2.php.net/get/php-7.0.1.tar.gz/from/this/mirror
2.解壓源碼包
# tar -xvf php7.tar.gz
3.進(jìn)入目錄
# cd php-7.0.1
4.安裝php依賴包
# yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
5.編譯配置悦析,這里如果上一步的某些依賴包沒有安裝好,就會遇到很多configure error此衅,我們一一解決强戴,安裝上相關(guān)軟件開發(fā)包就可以
# ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
configure error:
1.configure: error: xml2-config not found. Please check your libxml2 installation.
解決:
# yum install libxml2 libxml2-devel
2.configure: error: Cannot find OpenSSL's <evp.h>
解決:
# yum install openssl openssl-devel
3.configure: error: Please reinstall the BZip2 distribution
解決:
# yum install bzip2 bzip2-devel
4.configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
解決:
# yum install libcurl libcurl-devel
5.If configure fails try --with-webp-dir=<DIR> configure: error: jpeglib.h not found.
解決:
# yum install libjpeg libjpeg-devel
6.If configure fails try --with-webp-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.
解決:
# yum install libpng libpng-devel
7.If configure fails try --with-webp-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.
解決:
# yum install freetype freetype-devel
8.configure: error: Unable to locate gmp.h
解決:
# yum install gmp gmp-devel
9.configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解決:
# yum install libmcrypt libmcrypt-devel
10.configure: error: Please reinstall readline - I cannot find readline.h
解決:
# yum install readline readline-devel
11.configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
解決:
# yum install libxslt libxslt-devel
6.編譯與安裝
# make && make install
這里要make好久,要耐心一下
7.添加 PHP 命令到環(huán)境變量
# vim /etc/profile
在末尾加入
PATH=$PATH:/usr/local/php/bin
export PATH
要使改動立即生效執(zhí)行
# source /etc/profile
查看環(huán)境變量
# echo $PATH
查看php版本
# php -v
8.配置php-fpm
# cp php.ini-production /etc/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
9.啟動php-fpm
# /etc/init.d/php-fpm start
五挡鞍、配置nginx虛擬機(jī),綁定域名
1.添加配置文件
# vim /etc/nginx/conf.d/www.chaisz.xyz.conf
這里可以把www.chaisz.xyz改成自己的域名
把下面的內(nèi)容復(fù)制到www.chaisz.xyz.conf里
server{
listen 80;
server_name www.chaisz.xyz;
root /data/www/; # 該項要修改為你準(zhǔn)備存放相關(guān)網(wǎng)頁的路徑
location / {
index index.php index.html index.htm;
#如果請求既不是一個文件骑歹,也不是一個目錄,則執(zhí)行一下重寫規(guī)則
if (!-e $request_filename)
{
#地址作為將參數(shù)rewrite到index.php上墨微。
rewrite ^/(.*)$ /index.php/$1;
#若是子目錄則使用下面這句道媚,將subdir改成目錄名稱即可。
#rewrite ^/subdir/(.*)$ /subdir/index.php/$1;
}
}
#proxy the php scripts to php-fpm
location ~ \.php {
include fastcgi_params;
##pathinfo支持start
#定義變量 $path_info 翘县,用于存放pathinfo信息
set $path_info "";
#定義變量 $real_script_name最域,用于存放真實地址
set $real_script_name $fastcgi_script_name;
#如果地址與引號內(nèi)的正則表達(dá)式匹配
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
#將文件地址賦值給變量 $real_script_name
set $real_script_name $1;
#將文件地址后的參數(shù)賦值給變量 $path_info
set $path_info $2;
}
#配置fastcgi的一些參數(shù)
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
###pathinfo支持end
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
location ^~ /data/runtime {
return 404;
}
location ^~ /application {
return 404;
}
location ^~ /simplewind {
return 404;
}
}
#************如果不需要支持https,以下內(nèi)容不需要***********
#************支持https需要ssl證書
server {
listen 443;
server_name localhost;
ssl on;
root /data/www/;
index index.html index.htm;
ssl_certificate /etc/nginx/ssl/214052098260625.pem;
ssl_certificate_key /etc/nginx/ssl/214052098260625.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
index index.php index.html index.htm;
#如果請求既不是一個文件锈麸,也不是一個目錄镀脂,則執(zhí)行一下重寫規(guī)則
if (!-e $request_filename)
{
#地址作為將參數(shù)rewrite到index.php上。
rewrite ^/(.*)$ /index.php/$1;
#若是子目錄則使用下面這句忘伞,將subdir改成目錄名稱即可薄翅。
#rewrite ^/subdir/(.*)$ /subdir/index.php/$1;
}
}
#proxy the php scripts to php-fpm
location ~ \.php {
include fastcgi_params;
##pathinfo支持start
#定義變量 $path_info ,用于存放pathinfo信息
set $path_info "";
#定義變量 $real_script_name氓奈,用于存放真實地址
set $real_script_name $fastcgi_script_name;
#如果地址與引號內(nèi)的正則表達(dá)式匹配
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
#將文件地址賦值給變量 $real_script_name
set $real_script_name $1;
#將文件地址后的參數(shù)賦值給變量 $path_info
set $path_info $2;
}
#配置fastcgi的一些參數(shù)
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
###pathinfo支持end
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
location ^~ /data/runtime {
return 404;
}
location ^~ /application {
return 404;
}
location ^~ /simplewind {
return 404;
}
#******************如果不需要支持https翘魄,以上內(nèi)容不需要
}
2.重啟nginx
# service nginx reload
3.測試腳本
# vim /data/www/index.php
把下面的代碼復(fù)制到這個文件 里
<?php
phpinfo();
4.查看訪問http://www.chaisz.xyz 和 https://www.chaisz.xyz
ok!收工!
MySQL密碼忘記解決方法
- vim /etc/my.cnf 加入skip-grant-tables
service mysqld restart
mysql -u root -p 直接進(jìn)入mysql
update mysql.user set authentication_string=password('root') where user='root' ;
編輯my.cnf文件刪掉skip-grant-tables 這一行探颈,然后重啟MySQL熟丸,/etc/init.d/mysqld restart,否則MySQL仍能免密碼登錄
mysql -u root -p
然后輸入密碼即可登錄MySQL數(shù)據(jù)庫
mysql創(chuàng)建遠(yuǎn)程用戶并授權(quán)
先用ssh登錄遠(yuǎn)程服務(wù)器伪节,用root連上數(shù)據(jù)庫看看情況光羞;
mysql> select Host,User,authentication_string from mysql.user;
+----------------+------------------+-------------------------------------------+
| Host | User | Password |
+----------------+------------------+-------------------------------------------+
| localhost | root | *836E233974EBE6EA32F95F890A91363F8427F78B |
| iz94926clkiz | root | *836E233974EBE6EA32F95F890A91363F8427F78B |
| 127.0.0.1 | root | *836E233974EBE6EA32F95F890A91363F8427F78B |
| ::1 | root | *836E233974EBE6EA32F95F890A91363F8427F78B |
| localhost | debian-sys-maint | *1460ED3535ABDBB887F9E5F57F40A2354610CDF3 |
+----------------+------------------+-------------------------------------------+
rows in set (0.00 sec)
一共有5個mysql賬號绩鸣,Host列可以看出來,這些賬號都只支持服務(wù)器本機(jī)連接纱兑,現(xiàn)在我們來創(chuàng)建一個遠(yuǎn)程用戶嘉裤;
create user test identified by '123456';
+----------------+------------------+-------------------------------------------+
| Host | User | Password |
+----------------+------------------+-------------------------------------------+
| localhost | root | *836E283974EBE6EA32F95F890A91363F8427F78B |
| iz949s6clkiz | root | *836E283974EBE6EA32F95F890A91363F8427F78B |
| 127.0.0.1 | root | *836E283974EBE6EA32F95F890A91363F8427F78B |
| ::1 | root | *836E283974EBE6EA32F95F890A91363F8427F78B |
| localhost | debian-sys-maint | *1460ED35E5ABDBB887F9E5F57F40A2354610CDF3 |
| % | test | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+----------------+------------------+-------------------------------------------+
rows in set (0.00 sec)
創(chuàng)建完成了蚀之,在程序里面連接發(fā)現(xiàn)還是沒有權(quán)限,剛才我們只是創(chuàng)建了用戶,還沒有對這個用戶分配權(quán)限征椒;
grant all privileges on *.* to 'test'@'%'identified by '123456' with grant option;
all代表接受所有操作庶骄,比如 select,insert,delete....; . 代表所有庫下面的所有表;% 代表這個用戶允許從任何地方登錄澳眷;為了安全习柠,這個%可以替換為你允許的ip地址;
然后刷新mysql用戶權(quán)限相關(guān)表倒信;
flush privileges ;
到這里就可以收工了科贬。如果還是連不上去:access deny ;
可以看一下mysql配置文件 vim /etc/my.cnf
看是否有下面這行,
bind-address = 127.0.0.1
這里mysql默認(rèn)綁定了本地ip鳖悠,不接受其他來源榜掌;注釋掉,重啟mysql 一切OK乘综;
還有兩個常用操作憎账;
修改指定用戶密碼
update mysql.user set authentication_string=password('新密碼') where User="test" and Host="localhost";
刪除用戶
delete from user where User='test' and Host='localhost';