Centos 7 Webサービス構築の完全なプロセス
一、設置前の準備
リソース添付:https://download.csdn.net/download/u011159821/13119645
ダウンロード後の配置:/usr/local/srcディレクトリの下
環境依存:
二、インストールNginx 1.19
Nginxを編集します.conf、次の内容をコピーします.
サービスコマンド
三、PHP 7.4を取り付ける
PHPの設定:
コンパイルインストール:
一般的な設定:
php.ini基礎修正
サービスコマンド
四、MySQL 5.7のインストール
以下が現れ、これでMySqlのインストールが完了しました.
変更/etc/my.cnf
パスワードの初期化:
コマンドラインがデータベースに入り、初期化パスワードを変更
リモート・アクセスの有効化
サービスコマンド
Firewalldにオープンポートを追加mysqlポートを追加
再読み込み
注意:FirewallD is not runningを求めるメッセージが表示された場合、サービスは開始されません.
五、Redis 6.0のインストール
仮想空間の作成Redisサービスの実行
PHPにRedis拡張を加える
六、MongoDB 4.4のインストール
起動前の構成
サービスコマンド
六、SSHポートの修正
リソース添付:https://download.csdn.net/download/u011159821/13119645
ダウンロード後の配置:/usr/local/srcディレクトリの下
環境依存:
groupadd www;
useradd -g www -s /sbin/nologin -M www;
yum -y install gcc gcc-c++ openssl openssl-devel libxml2 libxml2-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 sqlite-devel screen autoconf;
mkdir -p /opt/nginx/1.19;
mkdir -p /opt/php/7.4;
mkdir -p /data/mysql/data;
mkdir -p /opt/redis/6.0;
mkdir -p /opt/mongodb/4.4;
二、インストールNginx 1.19
cd /usr/local/src;
tar -zxvf nginx-1.19.4.tar.gz;
cd nginx-1.19.4;
./configure --prefix=/opt/nginx/1.19 --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream --with-http_v2_module;
make -j;
make install;
ln -s /opt/nginx/1.19/sbin/nginx /usr/local/bin/nginx;
Nginxを編集します.conf、次の内容をコピーします.
user www www;
worker_processes auto;
error_log logs/error.log crit;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 51200;
events {
use epoll;
worker_connections 51200;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" "$request_body" '
'"$http_user_agent" $http_x_forwarded_for';
#access_log logs/access.log main;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;
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_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
#server {
#listen 80;
#server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root html;
# index index.html index.htm;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root html;
#}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
#}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
include vhost/*.conf;
# vhost
}
サービスコマンド
nginx #
nginx -s reload #
nginx -s stop #
三、PHP 7.4を取り付ける
cd /usr/local/src;
tar -xvf php-7.4.12.tar.gz;
cd php-7.4.12;
PHPの設定:
./configure \
--prefix=/opt/php/7.4 \
--with-config-file-path=/opt/php/7.4/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-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
コンパイルインストール:
make && make install;
一般的な設定:
# fpm php-fpm.conf.default
mv /opt/php/7.4/etc/php-fpm.conf.default /opt/php/7.4/etc/php-fpm.conf;
# php.ini
cp php.ini-production /opt/php/7.4/etc/php.ini;
# php-fpm init.d
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm;
# www.conf
cp /opt/php/7.4/etc/php-fpm.d/www.conf.default /opt/php/7.4/etc/php-fpm.d/www.conf;
# www.conf
vim /opt/php/7.4/etc/php-fpm.d/www.conf;
// 23、24 ,nginx www
#
chmod +x /etc/init.d/php-fpm;
#
chkconfig --add php-fpm;
#
chkconfig php-fpm on;
#
ln -s /opt/php/7.4/bin/php /usr/local/bin/php;
ln -s /opt/php/7.4/bin/phpize /usr/local/bin/phpize;
ln -s /opt/php/7.4/bin/php-config /usr/local/bin/php-config;
php.ini基礎修正
vim /opt/php/7.4/etc/php.ini
# expose_php = On, :
expose_php = Off
# ;extension_dir = "./", :
extension_dir = "/opt/php/7.4/lib/php/extensions/no-debug-non-zts-20190902"
# disable_functions = :
disable_functions = passthru,system,chroot,chgrp,chown,shell_exec,popen,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,popepassthru,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
# ;date.timezone = :
date.timezone = PRC
サービスコマンド
service php-fpm start # PHP
service php-fpm reload # PHP
service php-fpm stop # PHP
四、MySQL 5.7のインストール
cd /usr/local/src;
yum -y install mysql57-community-release-el7-10.noarch.rpm;
yum -y install mysql-community-server;
以下が現れ、これでMySqlのインストールが完了しました.
変更/etc/my.cnf
[client]
#password = your_password
port = 4363
socket = /tmp/mysql.sock
[mysqld]
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#skip-grant-tables
#wait_timeout=500
#interactive_timeout=500
port = 4363
socket = /tmp/mysql.sock
datadir = /data/mysql/data
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 100G
table_open_cache = 1024
sort_buffer_size = 4M
net_buffer_length = 4K
read_buffer_size = 4M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 64M
thread_cache_size = 128
query_cache_size = 128M
tmp_table_size = 128M
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
pid-file=/data/mysql/mysqld.pid
explicit_defaults_for_timestamp = true
#skip-name-resolve
max_connections = 500
max_connect_errors = 500
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
slow-query-log-file=/data/mysql/logs/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on
early-plugin-load = ""
character_set_server=utf8
init_connect='SET NAMES utf8'
innodb_data_home_dir = /data/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /data/mysql/data
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 512M
innodb_log_buffer_size = 128M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/data/mysql/logs/mysqld.error.log
[mysqld_safe]
log-error=/data/mysql/logs/mysqld.error.log
pid-file=/data/mysql/mysqld.pid
[mysqldump]
quick
max_allowed_packet = 500M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 4M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
パスワードの初期化:
grep "password" /var/log/mysqld.log
コマンドラインがデータベースに入り、初期化パスワードを変更
mysql -uroot -p
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'qoL5P*49KIlJ';
リモート・アクセスの有効化
mysql>use mysql;
mysql>select 'host' from user where user='root';
mysql>update user set host = '%' where user ='root';
mysql>flush privileges;
mysql>select 'host' from user where user='root';
mysql>exit;
サービスコマンド
# , /data/mysql :mysql:mysql
# chown -R mysql:mysql /data/mysql;
systemctl start mysqld.service # Mysql
systemctl restart mysqld # Mysql
systemctl stop mysqld # Mysql
Firewalldにオープンポートを追加mysqlポートを追加
firewall-cmd --zone=public --add-port=4363/tcp --permanent
再読み込み
firewall-cmd --reload
注意:FirewallD is not runningを求めるメッセージが表示された場合、サービスは開始されません.
# Firewall
systemctl start firewalld.service
五、Redis 6.0のインストール
# :
yum -y install gcc tcl;
yum -y install centos-release-scl;
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils;
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile;
# Shell
cd /usr/local/src;
tar xzf redis-6.0.9.tar.gz;
mv ./redis-6.0.9 /opt/redis/6.0;
cd /opt/redis/6.0;
make;
# redis.conf
# port 6379, :
port 6397
# # requirepass foobared, :
# Redis
requirepass AmYQn2Hv6AytY4Ux
#
ln -s /opt/redis/6.0/src/redis-cli /usr/local/bin/redis-cli;
仮想空間の作成Redisサービスの実行
# Screen
screen -R RedisServe;
[RedisServe]:src/redis-server /opt/redis/6.0/redis.conf;
# CTRL + A + D Screen
# Screen
screen -r RedisServe;
PHPにRedis拡張を加える
cd /usr/local/src/;
tar zxvf redis-5.3.2.tgz;
cd redis-5.3.2/;
phpize # /opt/php/7.4/bin/phpize;
./configure --with-php-config=/opt/php/7.4/bin/php-config;
make;
make install;
# php.ini
vim /opt/php/7.4/etc/php.ini;
extension=redis.so # 949 ,;extension=xsl
# PHP
service php-fpm reload;
六、MongoDB 4.4のインストール
cd /usr/local/src;
tar -zxvf mongodb-linux-x86_64-rhel70-4.4.1.tgz;
mv /usr/local/src/mongodb-linux-x86_64-rhel70-4.4.1/* /opt/mongodb/4.4/
export PATH=/opt/mongodb/4.4/bin:$PATH;
#
systemctl enable mongod.service
起動前の構成
mkdir -p /data/mongo/data/db;
cd /data/mongo;
mkdir logs;
touch mongodb.log;
mkdir etc;
touch mongodb.conf;
# mongodb.conf
# , mongod --help
dbpath=/data/mongo/data/db #
logpath=/data/mongo/logs/mongodb.log #
logappend=true #
port=27017 #
fork=true #
auth=true #
bind_ip=0.0.0.0 #
#
mongod --config /data/mongo/etc/mongodb.conf;
# mongo
# root@dev-PC:~# mongo
db.createUser({user:"root",pwd:"K8gEBx05@F$9#jUe",roles:["root"]})
サービスコマンド
# mongodb
mongod --config /data/mongo/etc/mongodb.conf;
# mongodb
ps -ef | grep mongodb;
kill -9 [ MongoDB ID]
六、SSHポートの修正
vi /etc/ssh/sshd_config
# Port
#Port 22
Port 2063 #
# ,
# ssh
systemctl restart sshd.service
# , ,