您好,登錄后才能下訂單哦!
本操作是針對與centos7.2 進行的安裝服務,和環境配置,用mongodb代替mysql進行的lnmp安裝
---------------------------------------------------------------------------------------
php
----------------------------------------------------------------------------------------
//添加用戶
useradd -M -s /sbin/nologin php
//安裝編譯工具及庫文件
yum install -y zlib-devel fontconfig fontconfig-devel libXpm* libtool* libxml2 libxml2-devel curl curl-devel
yum install -y openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel libmcrypt
yum install -y libmcrypt-devel yasm yasm-devel
yum install -y gcc+ gcc-c++
//下載各個安裝包
libpnghttp://downloads.sourceforge.net/libpng/libpng-1.6.16.tar.xz
gdhttps://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz
tiffhttp://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz
freetypehttp://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.5.4.tar.gz
jpegsrchttp://www.ijg.org/files/jpegsrc.v9a.tar.gz
//安裝tiff
./configure --prefix=/usr/local/tiff --enable-shared
make && make install
//安裝libpng
cd libpng-1.6.16
./configure --prefix=/usr/local/libpng --enable-shared
make && make install
//安裝freetype
cd freetype-2.4.0
./configure --prefix=/usr/local/freetype
make && make install
//安裝jpeg
cd jpeg-v9a
./configure --prefix=/usr/local/jpeg --enable-shared
make && make install
//安裝libgd
cd libgd-2.1.0
./configure \
--prefix=/usr/local/libgd \
--enable-shared \
--with-jpeg=/usr/local/jpeg \
--with-png=/usr/local/libpng \
--with-freetype=/usr/local/freetype \
--with-fontconfig=/usr/local/freetype \
--with-xpm=/usr/ \
--with-tiff=/usr/local/tiff
make && make install
//安裝php的準備(只有64位機器才用得到)
cp -frp /usr/lib64/libltdl.so* /usr/lib/
cp -frp /usr/lib64/libXpm.so* /usr/lib/
//安裝php
export LD_LIBRARY_PATH=/usr/local/libgd/lib
cd php-5.6.16
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysql-sock=/tmp/mysqld.sock \
--with-pdo-mysql=mysqlnd \
--with-png-dir=/usr/local/libpng \
--with-gd \
--with-jpeg-dir=/usr/local/jpeg \
--with-freetype-dir=/usr/local/freetype \
--with-xpm-dir=/usr/ \
--with-mcrypt \
--with-zlib \
--with-iconv \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-opcache \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--enable-ctype \
--disable-ipv6 \
--disable-short-tags
make && make install
//后續處理
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
pid = run/php-fpm.pid //去除左側分號
進行以下設置:
這個默認是在/usr/loccal/php/etc/php-fpm.d/www.php-fpm.conf
user = php
group = php
pid = run/php-fpm.pid //去除左側分號
wq!
//添加開機啟動
cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php
chmod +x /etc/rc.d/init.d/php
chkconfig php on
---------------------------------------------------------------------
*****************yum 安裝nginx 或者編譯安裝nginx
---------------------------------------------------------------------
http://www.nginx.org 在 downloads里面的底部有個一個文件可以寫進.repo的那種
弄好之后直接yum安裝,
nginx如果是編譯安裝的話,在你下載網絡源的那一頁有./configure 后面的參數,或者自行找文檔
php 和 nginx 鏈接好
sudo yum install -y mongodb-enterprise 這個大概會安裝10個軟件包,有5個是以前yun源指定,這里我還沒寫,
剩下的5個應該是支持mongod某些特性的軟件包
這5個包是:mongodb-enterprise,
mongodb-enterprise-server,
mongodb-enterprise-shell,
mongodb-enterprise-mongos,
mongodb-enterprise-tools
11個包是:
(1/11): cyrus-sasl-gssapi-2.1.26-19.2.el7.x86_64.rpm | 41 kB 00:00:00
(2/11): lm_sensors-libs-3.3.4-11.el7.x86_64.rpm | 40 kB 00:00:00
(3/11): cyrus-sasl-plain-2.1.26-19.2.el7.x86_64.rpm | 38 kB 00:00:00
(4/11): mongodb-enterprise-3.2.1-1.el7.x86_64.rpm | 5.9 kB 00:00:02
(5/11): mongodb-enterprise-mongos-3.2.1-1.el7.x86_64.rpm | 5.4 MB 00:01:06
(6/11): mongodb-enterprise-shell-3.2.1-1.el7.x86_64.rpm | 7.0 MB 00:01:14
(7/11): net-snmp-5.7.2-24.el7.x86_64.rpm | 321 kB 00:00:00
(8/11): net-snmp-agent-libs-5.7.2-24.el7.x86_64.rpm | 702 kB 00:00:00
(9/11): net-snmp-libs-5.7.2-24.el7.x86_64.rpm | 747 kB 00:00:00
(10/11): mongodb-enterprise-server-3.2.1-1.el7.x86_64.rpm | 12 MB 00:02:19
(11/11): mongodb-enterprise-tools-3.2.1-1.el7.x86_64.rpm
-------------------------------
*********mongodb3.2
--------------------------------
首先先要看一下有沒有mysql安裝這,rpm -qa | grep mysql
yum remove mysql-libs*
yum install perl cyrus-sasl cyrus-sasl-plain cyrus-sasl-gssapi krb5-libs \
lm_sensors net-snmp openssl popt rpm-libs tcp_wrappers zlib
yum install cyrus-sasl cyrus-sasl-plain cyrus-sasl-gssapi krb5-libs \
net-snmp openssl
yum install cyrus-sasl cyrus-sasl-plain cyrus-sasl-gssapi krb5-libs \
lm_sensors-libs net-snmp-agent-libs net-snmp openssl rpm-libs \
tcp_wrappers-libs
mongd32.repo (這個會更好點兒) 企業版,收費的
[mongodb-enterprise]
name=MongoDB Enterprise Repository
baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/stable/$basearch/
gpgcheck=0
enabled=1
另一個這個會安裝5個包 社區版
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=0
enabled=1
((((如果要是刪除mongodb sudo yum erase $(rpm -qa | grep mongodb-enterprise)
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongo
)))))))
*********重頭戲,這里,需要php與mongod連接的時候,需要有驅動http://www.cnblogs.com/chengmo/archive/2010/06/28/1766959.html
cd /usr/local/php/
wget http://pear.php.net/go-pear.phar
bin/php go-pear.phar 按照導向選擇安裝位置,這里保持默認即可 ,這樣之后就有了pecl命令了,在php的bin下面
bin/pecl install mongodb
vim etc/php.ini 寫入extension=mongodb.so
要重啟一下php-fpm 就可以了
這個是測試php與mongod是否連通的 (一個連通,一個插入數據)
<?php
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
var_dump($manager);
?>
<?php
$bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert(['_id' => 1, 'x' => 1]);
$bulk->insert(['_id' => 2, 'x' => 2]);
$bulk->update(['x' => 2], ['$set' => ['x' => 1]], ['multi' => false, 'upsert' => false]);
$bulk->update(['x' => 3], ['$set' => ['x' => 3]], ['multi' => false, 'upsert' => true]);
$bulk->update(['_id' => 3], ['$set' => ['x' => 3]], ['multi' => false, 'upsert' => true]);
$bulk->insert(['_id' => 4, 'x' => 2]);
$bulk->delete(['x' => 1], ['limit' => 1]);
$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 100);
$result = $manager->executeBulkWrite('db.collection', $bulk, $writeConcern);
printf("Inserted %d document(s)\n", $result->getInsertedCount());
printf("Matched %d document(s)\n", $result->getMatchedCount());
printf("Updated %d document(s)\n", $result->getModifiedCount());
printf("Upserted %d document(s)\n", $result->getUpsertedCount());
printf("Deleted %d document(s)\n", $result->getDeletedCount());
foreach ($result->getUpsertedIds() as $index => $id) {
printf('upsertedId[%d]: ', $index);
var_dump($id);
}
/* If the WriteConcern could not be fulfilled */
if ($writeConcernError = $result->getWriteConcernError()) {
printf("%s (%d): %s\n", $writeConcernError->getMessage(), $writeConcernError->getCode(), var_export($writeConcernError->getInfo(), true));
}
/* If a write could not happen at all */
foreach ($result->getWriteErrors() as $writeError) {
printf("Operation#%d: %s (%d)\n", $writeError->getIndex(), $writeError->getMessage(), $writeError->getCode());
}
?>
[root@test001 ~]# cat /lib/systemd/system/php-fpm.service
[Install]
WantedBy=multi-user.target
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[root@test002 /]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@test002 /]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
vi /usr/lib/systemd/system/nginx.service
[Unit]
Desciption=nginx
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/usr/local/nginx/sbin/nginx -s reload
[Install]
WantedBy=multi-user.target
//開機啟動
systemctl enable nginx
接下來是mongod的開機自啟動,這個是安裝了11個包的那個穩定版的
[root@test001 web]# cat /lib/systemd/system/mongod.service
# Automatically generated by systemd-sysv-generator
[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/rc.d/init.d/mongod
Description=SYSV: Mongo is a scalable, document-oriented database.
Before=runlevel3.target runlevel5.target shutdown.target
After=network-online.target network.service
Conflicts=shutdown.target
[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=no
PIDFile=/var/run/mongodb/mongod.pid
ExecStart=/etc/rc.d/init.d/mongod start
ExecStop=/etc/rc.d/init.d/mongod stop
ExecReload=/etc/rc.d/init.d/mongod reload
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。